Skip to content

Commit 8d9bde5

Browse files
committed
Use gunicorn in docker for deployment
1 parent d8c54bc commit 8d9bde5

File tree

10 files changed

+25
-55
lines changed

10 files changed

+25
-55
lines changed

README.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ or one of the scripts in the `./example` folder
4444

4545
### On Docker
4646

47-
#### Development
48-
49-
Build the image (this has to be done every time the code or the model change)
47+
Build the image (this has to be done every time the code or the model changes)
5048
```bash
5149
$ docker-compose build
5250
```
@@ -55,19 +53,6 @@ Create and run the container
5553
$ docker-compose up
5654
```
5755

58-
#### Production
59-
60-
Using uWSGI and nginx for production.
61-
62-
Build the image (this has to be done every time the code or the model change)
63-
```bash
64-
$ docker-compose -f docker-compose-production.yml build
65-
```
66-
Create and run the container
67-
```bash
68-
$ docker-compose -f docker-compose-production.yml up
69-
```
70-
7156
### On local Python environment
7257

7358
Create the environment
@@ -137,6 +122,8 @@ Endpoint: `/service-info`
137122
138123
```bash
139124
$ curl -X GET http://localhost:5000/service-info
125+
```
126+
```json
140127
{
141128
"debug": true,
142129
"running-since": 1563355369.6482198,
@@ -152,6 +139,8 @@ Endpoint: `/info`
152139
153140
```bash
154141
$ curl -X GET http://localhost:5000/info
142+
```
143+
```json
155144
{
156145
"metadata": {
157146
"features": [
@@ -191,6 +180,8 @@ Endpoint: `/predict`
191180
192181
```bash
193182
$ curl -d '[{"feature1": 1, "feature2": 1, "feature3": 2}, {"feature1": 1, "feature2": 1, "feature3": 2}]' -H "Content-Type: application/json" -X POST http://localhost:5000/predict
183+
```
184+
```json
194185
{
195186
"prediction": [0, 0]
196187
}
@@ -202,6 +193,8 @@ Endpoint: `/predict?proba=1`
202193
203194
```bash
204195
$ curl -d '{"feature1": 1, "feature2": 1, "feature3": 2}' -H "Content-Type: application/json" -X POST "http://localhost:5000/predict?proba=1"
196+
```
197+
```json
205198
{
206199
"prediction": [{
207200
"0": 0.8,
@@ -216,6 +209,8 @@ $ curl -d '{"feature1": 1, "feature2": 1, "feature3": 2}' -H "Content-Type: appl
216209
Endpoint: `/features`
217210
```bash
218211
$ curl -X GET "http://localhost:5000/features"
212+
```
213+
```json
219214
[
220215
{
221216
"default": -1,
@@ -243,7 +238,9 @@ $ curl -X GET "http://localhost:5000/features"
243238
Endpoint: `/predict?proba=1&explain=1`
244239
245240
```bash
246-
$curl -d '{"feature1": 1, "feature2": 1, "feature3": 2}' -H "Content-Type: application/json" -X POST "http://localhost:5000/predict?proba=1&explain=1"
241+
$ curl -d '{"feature1": 1, "feature2": 1, "feature3": 2}' -H "Content-Type: application/json" -X POST "http://localhost:5000/predict?proba=1&explain=1"
242+
```
243+
```json
247244
{
248245
"explanation": {
249246
"feature1": 0.10000000149011613,

docker-compose-production.yml

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

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ services:
1010
- ./docker/.env
1111
restart: always
1212
ports:
13-
- "33333:5000"
13+
- "5000:5000"

docker/.env

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

docker/Dockerfile

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

3-
WORKDIR /usr/src/app
3+
WORKDIR /app
4+
5+
RUN pip install --upgrade pip
46

57
# Copy and install service requirements
68
COPY requirements-service.txt .
@@ -13,5 +15,7 @@ RUN pip install -r ./requirements.txt
1315
# Copy code and model
1416
COPY . .
1517

16-
ENTRYPOINT ["python"]
17-
CMD [ "./service.py" ]
18+
EXPOSE 5000
19+
20+
CMD gunicorn -b 0.0.0.0:5000 service --timeout 300 --workers=2 --threads=4 --worker-class=gthread
21+

docker/Dockerfile-production

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

docker/production.env

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

requirements-service.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Web Service
22
flask
3+
gunicorn
34

45
# Model persistance and data handling
56
numpy

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pandas
22
numpy
33
scikit-learn
44
scipy
5+
lightgbm

service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Version of this APP template
1616
__version__ = '2.1.0'
1717
# Read env variables
18-
DEBUG = os.environ.get('DEBUG', True)
18+
DEBUG = os.environ.get('DEBUG', False)
1919
MODEL_NAME = os.environ.get('MODEL_NAME', 'model.joblib')
2020
ENVIRONMENT = os.environ.get('ENVIRONMENT', 'local')
2121
MODEL_TYPE = os.environ.get('MODEL_TYPE', 'SKLEARN_MODEL')

0 commit comments

Comments
 (0)