Skip to content

Commit d8c54bc

Browse files
committed
Refactor code and add missing command for production environment Dockerfile
1 parent e07c160 commit d8c54bc

26 files changed

+51
-66
lines changed

.env

Lines changed: 0 additions & 6 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ wheels/
2626
MANIFEST
2727

2828
# PyInstaller
29-
# Usually these files are written by a python script from a template
29+
# Usually these files are written by a src script from a template
3030
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3131
*.manifest
3232
*.spec

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Make sure that you have a model in the main directory.
2020
You can launch the example using the following line in order to create a quick
2121
classification model.
2222
```bash
23-
$ python ./python/example/build_linear_binary.py
23+
$ python ./example/build_linear_binary.py
2424
```
25-
or one of the scripts in the `python/example` folder
25+
or one of the scripts in the `./example` folder
2626

2727
### Configuration
2828

@@ -72,8 +72,8 @@ $ docker-compose -f docker-compose-production.yml up
7272

7373
Create the environment
7474
```bash
75-
$ conda create -n flask_ml_template python=3
76-
$ conda activate flask_ml_template
75+
$ conda create -n flask_ml python=3
76+
$ conda activate flask_ml
7777
```
7878
Install requirements
7979
```bash
@@ -87,8 +87,9 @@ $ python service.py
8787

8888
## Usage of the API
8989

90-
This example considers that the API was launched with the default parameters
91-
(`localhost` at port `5000`) and its calling the example model.
90+
This example considers that the API was launched locally without docker and
91+
with the default parameters (`localhost` at port `5000`) and its calling
92+
the example model.
9293

9394
For `/predict` endpoint the JSON string in the payload of hte request can take
9495
two forms:

docker-compose-production.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
version: '3'
22
services:
33
flask-ml:
4-
container_name: flask-ml-${VERSION}
4+
container_name: flask-ml
55
build:
66
context: .
77
dockerfile: ./docker/Dockerfile-production
8-
image: flask-ml:${VERSION}
8+
image: flask-ml
99
env_file:
10-
- ./docker/variables-production.env
10+
- ./docker/production.env
1111
restart: always
1212
ports:
13-
- "${PORT_EXTERNAL}:${PORT}"
13+
- "3333:5000"

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
version: '3'
22
services:
33
flask-ml:
4-
container_name: flask-ml-${VERSION}
4+
container_name: flask-ml
55
build:
66
context: .
77
dockerfile: ./docker/Dockerfile
8-
image: flask-ml:${VERSION}
8+
image: flask-ml
99
env_file:
10-
- ./docker/variables.env
10+
- ./docker/.env
1111
restart: always
1212
ports:
13-
- "${PORT_EXTERNAL}:${PORT}"
13+
- "33333:5000"

docker/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DEBUG=1
2+
MODEL_NAME=model.joblib
3+
MODEL_TYPE=SKLEARN_MODEL

docker/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM python:3
22

3-
ENV ENVIRONMENT local
4-
53
WORKDIR /usr/src/app
64

75
# Copy and install service requirements

docker/Dockerfile-production

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM tiangolo/uwsgi-nginx-flask:python3.6
22

3-
ENV ENVIRONMENT production
4-
53
WORKDIR /app/
64

75
# Copy and install service requirements
@@ -14,3 +12,5 @@ RUN pip install -r ./requirements.txt
1412

1513
# Copy code and model
1614
COPY . .
15+
16+
CMD gunicorn -b 0.0.0.0:5000 service --timeout 300

docker/production.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DEBUG=0
2+
MODEL_NAME=model.joblib
3+
MODEL_TYPE=SKLEARN_MODEL

docker/variables-production.env

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)