Skip to content

Commit

Permalink
Amend code for non-ssl version
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielTsiang committed Sep 5, 2023
1 parent 4d62a5d commit cfefcd3
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 119 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Test application

on:
push:
branches: [ "main" ]
branches: [ "non-ssl" ]
pull_request:
branches: [ "main" ]
branches: [ "non-ssl" ]

permissions:
contents: read
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Traffic Sign Classifier

[![Traffic Sign Classifier](https://img.shields.io/website-up-down-green-red/https/danieltsiang.github.io.svg)](https://traffic-sign-classifier-dt.onrender.com/)
[![Test app status](https://github.com/DanielTsiang/traffic-sign-classifier/actions/workflows/test-app.yml/badge.svg?branch=main)](https://github.com/DanielTsiang/traffic-sign-classifier/actions?query=branch%3Amain)
[![Test app status](https://github.com/DanielTsiang/traffic-sign-classifier/actions/workflows/test-app.yml/badge.svg?branch=non-ssl)](https://github.com/DanielTsiang/traffic-sign-classifier/actions?query=branch%3Anon-ssl)
[![GitHub branches](https://badgen.net/github/branches/DanielTsiang/traffic-sign-classifier?&kill_cache=1)](https://github.com/DanielTsiang/traffic-sign-classifier/branches)
[![Security](https://snyk.io/test/github/DanielTsiang/traffic-sign-classifier/badge.svg?targetFile=services/flask/requirements.txt)](https://snyk.io/test/github/DanielTsiang/traffic-sign-classifier?targetFile=services/flask/requirements.txt)
[![Security](https://snyk.io/test/github/DanielTsiang/traffic-sign-classifier/non-ssl/badge.svg?targetFile=services/flask/requirements.txt)](https://snyk.io/test/github/DanielTsiang/traffic-sign-classifier/non-ssl?targetFile=services/flask/requirements.txt)
[![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Ftraffic-sign-classifier-dt.onrender.com%2F&label=Hits&countColor=%2337d67a&style=flat)](https://visitorbadge.io/status?path=https%3A%2F%2Ftraffic-sign-classifier-dt.onrender.com%2F)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Buymeacoffee](https://img.shields.io/badge/Donate-Buy%20Me%20A%20Coffee-orange.svg?style=flat&logo=buymeacoffee)](https://www.buymeacoffee.com/dantsiang8)
Expand All @@ -24,7 +24,7 @@ https://user-images.githubusercontent.com/74436899/151076061-8875ae51-8c43-4dea-

## Specification
* Design and build a single-page web app to serve a Machine Learning model I trained.
* Serve the Python Flask app with Gunicorn and use NGINX as the reverse proxy. Customise NGINX config to force SSL.
* Serve the Python Flask app with Gunicorn and use NGINX as the reverse proxy.
* Serve the TensorFlow model using TensorFlow Serving for optimal performance and managing model versioning.
* Flask, NGINX and TensorFlow Serving Docker containers are orchestrated using Docker Compose.
* Users can upload their own images or select a random image for the model to classify.
Expand Down Expand Up @@ -63,11 +63,8 @@ https://user-images.githubusercontent.com/74436899/151076061-8875ae51-8c43-4dea-
## Running locally
1. Ensure you have Docker installed.
2. To start the app, in the root folder where `docker-compose.yml` is contained, run `docker-compose up` in the terminal.
3. Visit `localhost:1337` in your web browser. Bypass the invalid SSL certificate warning.
E.g. in Chrome, click on the screen with the page open and type `thisisunsafe` to bypass the warning.
4. If you are unable to bypass the warning, checkout the `non-ssl` branch instead to run the Docker
containers without SSL enforced. In this branch, visit `localhost` instead.
5. To shut down the app, run `docker-compose down` in the terminal or hit `CTRL+C`.
3. Visit `localhost` in your web browser.
4. To shut down the app, run `docker-compose down` in the terminal or hit `CTRL+C`.

### Testing
To run the integration tests, in the root folder, run the following in the terminal:
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
build:
context: ./services/tensorflow-serving
dockerfile: Dockerfile.tf
command:
- "--model_config_file=/models/model.config"
container_name: tensorflow-serving
ports:
- "8501:8501"
Expand All @@ -16,7 +18,7 @@ services:
dockerfile: Dockerfile.nginx
container_name: nginx
ports:
- "1337:443"
- "80:80"
depends_on:
- flask

Expand Down
2 changes: 0 additions & 2 deletions services/nginx/Dockerfile.nginx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ FROM nginx:1.23.3-alpine
RUN rm /etc/nginx/conf.d/default.conf

COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY cert.pem /certificate/cert.pem
COPY key.pem /certificate/key.pem
32 changes: 0 additions & 32 deletions services/nginx/cert.pem

This file was deleted.

52 changes: 0 additions & 52 deletions services/nginx/key.pem

This file was deleted.

17 changes: 4 additions & 13 deletions services/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@ upstream classify {
}

server {
listen 443 ssl;
ssl_certificate /certificate/cert.pem;
ssl_certificate_key /certificate/key.pem;
error_page 497 https://$host:1337$request_uri;
listen 80;
server_name localhost;

location / {
proxy_pass http://classify; # upstream name defined above
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:1337;
proxy_set_header Host "localhost";
proxy_redirect off;
}
}

server {
listen 80;
server_name classify;
location / {
return 301 https://$host:1337$request_uri;
}
}
6 changes: 0 additions & 6 deletions services/tensorflow-serving/Dockerfile.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ ENV PORT 8501

COPY ./model/ /models/traffic-sign-classifier/
COPY ./model.config /models/model.config

# Fix because base tf_serving_entrypoint.sh does not take $PORT env variable while $PORT is set by Heroku
# CMD is required to run on Heroku
COPY ./tf_serving_entrypoint.sh /usr/bin/tf_serving_entrypoint.sh
RUN chmod +x /usr/bin/tf_serving_entrypoint.sh
CMD ["/usr/bin/tf_serving_entrypoint.sh"]
3 changes: 0 additions & 3 deletions services/tensorflow-serving/tf_serving_entrypoint.sh

This file was deleted.

0 comments on commit cfefcd3

Please sign in to comment.