diff --git a/Dockerfile b/Dockerfile index c39d88d..d25ea61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,8 @@ COPY requirements.txt /code/ RUN pip install -r requirements.txt +RUN groupadd -g 777 appuser && \ + useradd -r -u 777 -g appuser appuser +USER appuser + COPY . /code/ diff --git a/Dockerfile-prod b/Dockerfile-prod new file mode 100644 index 0000000..8bfb9b5 --- /dev/null +++ b/Dockerfile-prod @@ -0,0 +1,19 @@ +FROM python:3.8-slim + +ENV PYTHONUNBUFFERED 1 + +RUN mkdir /code +WORKDIR /code +COPY requirements.txt /code/ + +RUN apt-get update && \ + apt-get install gcc -y && \ + apt-get clean +RUN pip install uwsgi && \ + pip install -r requirements.txt + +RUN groupadd -g 777 appuser && \ + useradd -r -u 777 -g appuser appuser +USER appuser + +COPY . /code/ diff --git a/README.md b/README.md index b011595..7300d5d 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,16 @@ You can then visit [localhost:5000](http://localhost:5000) to verify that it's r $ curl http://localhost:5000 ``` +## Deployment + +Configuration files are located at `env.local` and `uwsgi.ini`. + +A production ready uWSGI daemon (uwsgi socket exposed on port 5000) can be started with: + +```bash +docker-compose -f docker-compose.prod.yml up -d --build +``` + ## Routes ### `GET /v1/collections` diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..85c8e7b --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,11 @@ +version: '3' + +services: + web: + command: uwsgi --ini uwsgi.ini + build: + context: . + dockerfile: Dockerfile-prod + ports: + - "5000:5000" + restart: on-failure diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 0000000..eac1d78 --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,5 @@ +[uwsgi] +module = main:app +socket = 0.0.0.0:5000 +master = true +processes = 4