Skip to content

Commit

Permalink
Containerize backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Mar 9, 2023
1 parent 939e5d5 commit 1258498
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 2 deletions.
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM python:3.10 as base

FROM base as builder

RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
python3-dev

WORKDIR /install

COPY pyproject.toml pdm.lock ./

RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir pdm==2.4.8 \
&& pdm config python.use_venv false
RUN pdm install --prod --no-editable

FROM base
WORKDIR /usr/src/app

ENV PATH="/usr/src/python/bin:$PATH" \
PYTHONPATH="/usr/src/python/lib"

COPY --from=builder \
/install/__pypackages__/3.10 \
/usr/src/python

COPY backend backend/
COPY migrations migrations/
COPY wsgi.py ./

CMD ["gunicorn", "-c", "python:backend.gunicorn", "wsgi:app"]
8 changes: 8 additions & 0 deletions backend/gunicorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

bind = "0.0.0.0:5000"
worker_class = "gevent"
workers = (os.cpu_count() or 1) * 2 + 1
threads = (os.cpu_count() or 1) * 2 + 1
preload = True
timeout = 180
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.4"

x-backend-config: &backend
image: localizer-backend:latest
volumes:
- .:/app
depends_on:
- db
env_file: ${ENV_FILE:-localizer.env}

volumes:
db_data:

services:
backend:
<<: *backend
container_name: localizer-backend
restart: always
ports:
- "5600:5000"

migration:
<<: *backend
container_name: localizer-migration
restart: on-failure
command: flask db upgrade

db:
image: mdillon/postgis:11
container_name: db
restart: always
env_file: ${ENV_FILE:-localizer.env}
ports:
- "5434:5432"
volumes:
- db_data:/var/lib/postgresql/data

Loading

0 comments on commit 1258498

Please sign in to comment.