From b29c598259dd0e2526abaa7f6fdc3ac21b19f2d4 Mon Sep 17 00:00:00 2001 From: Vincent Vallaeys Date: Thu, 16 May 2024 15:46:19 +0200 Subject: [PATCH] chore: changed production docker (#432) (#433) * chore: changed production docker * chore: modified tests as well * chore: celery --- backend/{Dockerfile => Dockerfile.dev} | 0 backend/Dockerfile.prod | 22 ++++++++++++++++++++++ development.yml | 6 +++--- production.yml | 9 +++++---- test.yml | 6 +++--- 5 files changed, 33 insertions(+), 10 deletions(-) rename backend/{Dockerfile => Dockerfile.dev} (100%) create mode 100644 backend/Dockerfile.prod diff --git a/backend/Dockerfile b/backend/Dockerfile.dev similarity index 100% rename from backend/Dockerfile rename to backend/Dockerfile.dev diff --git a/backend/Dockerfile.prod b/backend/Dockerfile.prod new file mode 100644 index 00000000..9e0245ee --- /dev/null +++ b/backend/Dockerfile.prod @@ -0,0 +1,22 @@ +FROM python:3.11.4-alpine3.18 as requirements + +RUN pip install poetry-plugin-export + +WORKDIR /code + +COPY pyproject.toml poetry.lock ./ + +RUN poetry export --without-hashes --format=requirements.txt > requirements.txt + + +FROM python:3.11.4-alpine3.18 + +RUN apk add --no-cache gettext libintl + +WORKDIR /code + +COPY --from=requirements /code/requirements.txt . + +RUN pip install -r requirements.txt --no-cache-dir + +COPY . . diff --git a/development.yml b/development.yml index 1d0bb3e4..67ca5ea3 100644 --- a/development.yml +++ b/development.yml @@ -35,7 +35,7 @@ services: nginx: <<: *common-keys-selab container_name: nginx - image: nginx:latest + image: nginx:alpine-slim ports: - 80:80 - 443:443 @@ -52,7 +52,7 @@ services: container_name: backend build: context: $BACKEND_DIR - dockerfile: Dockerfile + dockerfile: Dockerfile.dev command: sh -c "./setup.sh; python manage.py runsslserver 0.0.0.0:8000" volumes: - ${BACKEND_DIR}:/code @@ -63,7 +63,7 @@ services: container_name: celery build: context: $BACKEND_DIR - dockerfile: Dockerfile + dockerfile: Dockerfile.dev command: sh -c "./setup.sh && celery -A ypovoli worker -l DEBUG" volumes: - ${BACKEND_DIR}:/code diff --git a/production.yml b/production.yml index 7c40cc42..e80fa8ae 100644 --- a/production.yml +++ b/production.yml @@ -34,7 +34,7 @@ x-common-keys-selab: &common-keys-selab services: nginx: <<: *common-keys-selab - image: nginx:latest + image: nginx:alpine-slim container_name: nginx_prod ports: - 80:80 @@ -62,7 +62,7 @@ services: container_name: backend_prod build: context: $BACKEND_DIR - dockerfile: Dockerfile + dockerfile: Dockerfile.prod command: sh -c "./setup.sh && gunicorn --config gunicorn_config.py ypovoli.wsgi:application" depends_on: - postgres @@ -80,10 +80,11 @@ services: container_name: celery_prod build: context: $BACKEND_DIR - dockerfile: Dockerfile + dockerfile: Dockerfile.prod command: celery -A ypovoli worker -l ERROR volumes: - - ${BACKEND_DIR}:/code + - /var/run/docker.sock:/var/run/docker.sock + - /var/lib/docker/overlay2:/var/lib/docker/overlay2 depends_on: - backend - redis diff --git a/test.yml b/test.yml index 05051584..24ec2d9b 100644 --- a/test.yml +++ b/test.yml @@ -34,7 +34,7 @@ x-common-keys-selab_test: &common-keys-selab_test services: nginx: <<: *common-keys-selab_test - image: nginx:latest + image: nginx:alpine-slim container_name: nginx volumes: - ${DATA_DIR}/nginx/nginx.test.conf:/etc/nginx/nginx.conf:ro @@ -48,7 +48,7 @@ services: container_name: backend build: context: $BACKEND_DIR - dockerfile: Dockerfile + dockerfile: Dockerfile.dev command: sh -c "./setup.sh && python manage.py runsslserver 0.0.0.0:8000" volumes: - $BACKEND_DIR:/code @@ -60,7 +60,7 @@ services: container_name: celery build: context: $BACKEND_DIR - dockerfile: Dockerfile + dockerfile: Dockerfile.dev command: sh -c "./setup.sh && celery -A ypovoli worker -l DEBUG" volumes: - $BACKEND_DIR:/code