feat: dockerize for prod

Signed-off-by: Ameya Shenoy <shenoy.ameya@gmail.com>
This commit is contained in:
Ameya Shenoy 2023-03-23 15:53:01 +05:30
parent ae57e86d23
commit ebc2f4f8c5
Signed by: codingcoffee
GPG key ID: EEC8EA855D61CEEC
3 changed files with 87 additions and 0 deletions

37
backend/Dockerfile Normal file
View file

@ -0,0 +1,37 @@
FROM python:3.10.9-slim-bullseye
LABEL maintainer "Ameya Shenoy <shenoy.ameya@gmail.com>"
ENV PYTHONUNBUFFERED=1
ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1
ENV GUNICORN_VERSION=20.1.0
ARG APP_USER=app
WORKDIR /code
COPY requirements.txt /
RUN set -ex \
&& pip install --no-cache-dir -r /requirements.txt \
&& pip install --no-cache-dir gunicorn==$GUNICORN_VERSION \
&& apk del .build-deps \
&& addgroup -S ${APP_USER} \
&& adduser -S ${APP_USER} -G ${APP_USER} \
&& mkdir -p /code/static \
&& mkdir -p /code/media \
&& mkdir -p /code/static_cdn \
&& mkdir -p /code/media_cdn \
&& chown -R ${APP_USER}:${APP_USER} /code/
COPY . /code
WORKDIR /code
RUN set -ex \
&& python manage.py collectstatic --no-input
EXPOSE 8000
USER ${APP_USER}:${APP_USER}
ENTRYPOINT gunicorn --workers 2 --bind 0.0.0.0 backend.wsgi

39
docker-compose.prod.yml Normal file
View file

@ -0,0 +1,39 @@
---
version: '3.7'
services:
web:
image: foldbank-web-prod
build:
context: ./web
dockerfile: Dockerfile
restart: unless-stopped
backend:
image: foldbank-backend-prod
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- prod.env
depends_on:
- redis
- postgres-db
redis:
image: redis:7.0.0-alpine3.16
restart: unless-stopped
postgres-db:
image: postgres:14.3-alpine3.16
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data/pgdata
env_file:
- prod.env
volumes:
postgres-data:

11
web/Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM node:16.19.1-alpine3.17
COPY web /code
WORKDIR /code
RUN set -ex \
&& npm i \
&& npm run build
ENTRYPOINT npm start