From 362013d0dff89c3805ced1650283bb5b783ac6e4 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Wed, 15 Nov 2023 12:01:35 +0100 Subject: [PATCH] On met en place la version prod --- Makefile | 3 + deployment/scripts/backend/start.sh | 0 deployment/scripts/celery/start-beat.sh | 0 deployment/scripts/celery/start-worker.sh | 0 deployment/scripts/wait-db.sh | 7 +++ .../scripts/{backend => }/wait-for-it.sh | 0 docker-compose.prod.yml | 63 ++++--------------- docker-compose.yml | 2 +- 8 files changed, 22 insertions(+), 53 deletions(-) mode change 100644 => 100755 deployment/scripts/backend/start.sh mode change 100644 => 100755 deployment/scripts/celery/start-beat.sh mode change 100644 => 100755 deployment/scripts/celery/start-worker.sh create mode 100644 deployment/scripts/wait-db.sh rename deployment/scripts/{backend => }/wait-for-it.sh (100%) mode change 100644 => 100755 diff --git a/Makefile b/Makefile index a8e0359..ccd0957 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,9 @@ build-dev-log: build-prod: DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.prod.yml up --build -d +build-prod-log: + DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 docker-compose -f docker-compose.prod.yml up --build + stop-dev: @docker-compose -f docker-compose.yml down diff --git a/deployment/scripts/backend/start.sh b/deployment/scripts/backend/start.sh old mode 100644 new mode 100755 diff --git a/deployment/scripts/celery/start-beat.sh b/deployment/scripts/celery/start-beat.sh old mode 100644 new mode 100755 diff --git a/deployment/scripts/celery/start-worker.sh b/deployment/scripts/celery/start-worker.sh old mode 100644 new mode 100755 diff --git a/deployment/scripts/wait-db.sh b/deployment/scripts/wait-db.sh new file mode 100644 index 0000000..f75caba --- /dev/null +++ b/deployment/scripts/wait-db.sh @@ -0,0 +1,7 @@ + +wait_for_it=$(dirname "$0")/wait-for-it.sh + +chmod +x $wait_for_it +chmod +x $1 + +$wait_for_it -h $POSTGRES_HOST -p $POSTGRES_PORT -- $1 \ No newline at end of file diff --git a/deployment/scripts/backend/wait-for-it.sh b/deployment/scripts/wait-for-it.sh old mode 100644 new mode 100755 similarity index 100% rename from deployment/scripts/backend/wait-for-it.sh rename to deployment/scripts/wait-for-it.sh diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index d6b1e1d..05d7d9b 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,4 +1,4 @@ -version: '3.9' +version: '3.7' services: backend: @@ -15,18 +15,12 @@ services: - ./deployment/scripts:/app/deployment/scripts/ - static_files:/usr/src/app/static - media_files:/usr/src/app/media - labels: - - "traefik.enable=true" - - "traefik.http.routers.${APP_NAME}-backend.rule=Host(`${APP_DOMAIN}`)" - - "traefik.http.routers.${APP_NAME}-backend.entrypoints=web" - - "traefik.http.services.${APP_NAME}-backend.loadbalancer.server.port=${APP_PORT:-8000}" - env_file: .env + env_file: .env.prod expose: - "${APP_PORT:-8000}" depends_on: - db: - condition: service_healthy - command: [ "/bin/sh", "/app/deployment/scripts/backend/start.sh" ] + - db + command: [ "/bin/sh", "/app/deployment/scripts/wait-db.sh", "/app/deployment/scripts/backend/start.sh" ] db: image: postgres:15.2-alpine @@ -34,7 +28,7 @@ services: hostname: "${POSTGRES_HOST:-db}" volumes: - postgres_data_dir:/var/lib/postgresql/data/ - env_file: .env + env_file: .env.prod expose: - "${POSTGRES_PORT:-5432}" shm_size: 1g @@ -61,17 +55,17 @@ services: - ./deployment/scripts:/app/deployment/scripts/ - static_files:/usr/src/app/static - media_files:/usr/src/app/media - env_file: .env + env_file: .env.prod depends_on: - db - redis - backend - command: [ "/bin/sh", "/app/deployment/scripts/celery/start-worker.sh" ] + command: [ "/bin/sh", "/app/deployment/scripts/wait-db.sh", "/app/deployment/scripts/celery/start-worker.sh" ] celery-beat: <<: *celery-worker container_name: "${APP_NAME}-celery-beat" - command: [ "/bin/sh", "/app/deployment/scripts/celery/start-beat.sh" ] + command: [ "/bin/sh", "/app/deployment/scripts/wait-db.sh", "/app/deployment/scripts/celery/start-beat.sh" ] nginx: image: nginx:latest @@ -80,46 +74,11 @@ services: - ./deployment/scripts/nginx/nginx.conf:/etc/nginx/nginx.conf:ro - static_files:/usr/src/app/static - media_files:/usr/src/app/media - labels: - - "traefik.enable=true" - - "traefik.http.routers.${APP_NAME}-nginx.rule=Host(`${APP_DOMAIN}`)" - - "traefik.http.routers.${APP_NAME}-nginx.entrypoints=websecure" - - "traefik.http.services.${APP_NAME}-nginx.loadbalancer.server.port=80" - - "traefik.http.routers.${APP_NAME}-nginx.tls=true" - - "traefik.http.routers.${APP_NAME}-nginx.tls.certresolver=myresolver" - expose: - - "80" - - "443" + env_file: .env.prod + ports: + - 6380:80 depends_on: - backend - - traefik - - traefik: - image: traefik:v2.5 - container_name: "${APP_NAME}-traefik" - command: - - "--providers.docker=true" - - "--providers.docker.exposedbydefault=false" - - "--providers.docker.watch=true" - - "--entrypoints.web.address=:80" - - "--entrypoints.websecure.address=:443" - - "--entrypoints.web.http.redirections.entryPoint.to=websecure" - - "--entrypoints.web.http.redirections.entryPoint.scheme=https" - - "--entrypoints.web.http.redirections.entrypoint.permanent=true" - - "--api.dashboard=true" - - "--certificatesresolvers.myresolver.acme.httpchallenge=true" - - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web" - - "--certificatesresolvers.myresolver.acme.email=${LETSENCRYPT_EMAIL}" - - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json" - - "--log.level=DEBUG" - - "--accesslog=true" - - "--tracing=true" - ports: - - "80:80" - - "443:443" - volumes: - - "/var/run/docker.sock:/var/run/docker.sock" - - "./letsencrypt:/letsencrypt" volumes: static_files: diff --git a/docker-compose.yml b/docker-compose.yml index 2270e5c..4170c29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.9' +version: '3.7' services: backend: