Dockerfile split into prod and dev

This commit is contained in:
ayxan
2023-01-31 21:03:07 +04:00
parent 54d02bd56e
commit ee6b5e51c1
6 changed files with 39 additions and 7 deletions

6
Docker/Dev/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY src /code/src/

View File

@@ -0,0 +1,18 @@
version: "3.9"
services:
django:
restart: always
environment:
- DJANGO_SETTINGS_MODULE=config.settings.development
build:
context: ../../
dockerfile: Docker/Dev/Dockerfile
command: >
bash -c "python3 src/manage.py makemigrations
&& python3 src/manage.py migrate
&& python src/manage.py runserver 0.0.0.0:8000"
ports:
- "8000:8000"
volumes:
- ../../src:/code/src

7
Docker/Prod/Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY src /code/src/
COPY config /code/config/

View File

@@ -0,0 +1,45 @@
version: "3.9"
services:
db:
image: postgres
volumes:
- dbdata:/var/lib/postgresql/data
env_file:
- config/db/databasepostgresql_env
rabbitmq:
image: rabbitmq
django:
restart: always
environment:
- DJANGO_SETTINGS_MODULE=config.settings.production
build:
context: ../../
dockerfile: Docker/Prod/Dockerfile
command: >
bash -c "python3 src/manage.py makemigrations
&& python3 src/manage.py migrate
&& gunicorn --chdir src --bind 0.0.0.0:8000 config.wsgi"
ports:
- "8000:8000"
depends_on:
- db
- rabbitmq
volumes:
- static_volume:/django_static
nginx:
image: nginx
ports:
- "80:80"
volumes:
- ./config/nginx/server-cloudflare.conf:/etc/nginx/conf.d/default.conf:ro
- static_volume:/django_static
depends_on:
- django
volumes:
dbdata:
static_volume:

View File

@@ -0,0 +1,56 @@
version: "3.9"
services:
db:
image: postgres
volumes:
- dbdata:/var/lib/postgresql/data
env_file:
- config/db/databasepostgresql_env
rabbitmq:
image: rabbitmq
django:
restart: always
environment:
- DJANGO_SETTINGS_MODULE=config.settings.production
build:
context: ../../
dockerfile: Docker/Prod/Dockerfile
command: >
bash -c "python3 src/manage.py makemigrations
&& python3 src/manage.py migrate
&& gunicorn --chdir src --bind 0.0.0.0:8000 config.wsgi"
ports:
- "8000:8000"
depends_on:
- db
- rabbitmq
volumes:
- static_volume:/django_static
nginx:
image: nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./config/nginx/server.conf:/etc/nginx/conf.d/default.conf:ro
- ./config/certbot/conf:/etc/letsencrypt
- ./config/certbot/www:/var/www/certbot
- static_volume:/django_static
depends_on:
- django
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
image: certbot/certbot
volumes:
- ./config/certbot/conf:/etc/letsencrypt
- ./config/certbot/www:/var/www/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
volumes:
dbdata:
static_volume: