@@ -0,0 +1 @@ +FROM nginx:alpine \ No newline at end of file @@ -57,7 +57,7 @@ deploy_production: - docker:dind environment: name: production - url: https://api.air.fail + url: https://backend.air.fail only: - main when: on_success @@ -68,5 +68,4 @@ deploy_production: - echo "$PRODUCTION_CLUSTER_KEY" > $DOCKER_CERT_PATH/key.pem - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" $CI_REGISTRY --password-stdin script: - - docker compose pull - - docker compose --project-name air-backend up -d + - docker stack deploy --compose-file stack.yml --resolve-image always --detach backend \ No newline at end of file @@ -0,0 +1,122 @@ +services: + app: + restart: unless-stopped + image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + build: + context: . + dockerfile: Dockerfile + volumes: + - static:/code/static + command: + - /bin/sh + - -c + - | + python manage.py collectstatic --no-input + python manage.py compilemessages + python -m uvicorn --host 0.0.0.0 --workers 8 --timeout-keep-alive 300 --ws wsproto --loop uvloop --http httptools --lifespan off --log-level info backend.asgi:application + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + labels: + - traefik.enable=true + - traefik.http.routers.backend.rule=Host(`backend.air.fail`) + - traefik.http.routers.backend.entrypoints=https + - traefik.http.routers.backend.tls=true + - traefik.http.routers.backend.tls.certresolver=defaultresolver + - traefik.http.services.backend.loadbalancer.server.port=8000 + env_file: + - $ENV + depends_on: + - cache-mdb + - celery-mdb + + celery: + restart: unless-stopped + image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + build: + context: . + dockerfile: Dockerfile + command: celery -A backend worker -l INFO --concurrency 8 + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + env_file: + - $ENV + environment: + - C_FORCE_ROOT=true + depends_on: + - celery-mdb + + celery_beat: + restart: unless-stopped + image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + build: + context: . + dockerfile: Dockerfile + command: celery -A backend beat -l INFO + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + env_file: + - $ENV + depends_on: + - celery-mdb + + static-server: + restart: unless-stopped + image: $CI_REGISTRY_IMAGE/static-server:$CI_COMMIT_SHA + build: + context: nginx + dockerfile: Dockerfile + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + volumes: + - static:/var/www/static + env_file: + - $ENV + + cache-mdb: + image: redis:alpine + restart: unless-stopped + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + + celery-mdb: + image: redis:alpine + restart: unless-stopped + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + + channels-mdb: + image: redis:alpine + restart: unless-stopped + deploy: + replicas: 1 + placement: + constraints: + - node.role == worker + +networks: + infrastructure: + external: true + +volumes: + static: + name: "backend-static" + locales: + name: "backend-locales" \ No newline at end of file