services:
  fyp-django-prod:
    container_name: fyp-django-prod
    image: "${FYP_DJANGO_IMAGE}"
    env_file:
      - ../../.env
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.fyp-web.rule=Host(`${DJANGO_DOMAIN_NAME}`)"
      - "traefik.http.routers.fyp-web.entrypoints=${DJANGO_ENTRYPOINT}"
      - "traefik.http.routers.fyp-web.tls.certresolver=${CERTRESOLVER}"
      - "traefik.http.routers.fyp-web.tls=true"
      - "traefik.http.services.fyp-web.loadbalancer.server.port=8000"
      - "traefik.docker.network=proxy"
      - "com.centurylinklabs.watchtower.enable=true"
      - "com.centurylinklabs.watchtower.scope=fyp"
    volumes:
      - ../../static:/app/static
      - ../../media:/app/media
    depends_on:
      fyp-postgres-prod:
        condition: service_healthy
    networks:
      - fyp-network
      - proxy

  fyp-postgres-prod:
    container_name: fyp-postgres-prod
    image: pgvector/pgvector:pg15
    hostname: fyp-postgres-prod
    restart: unless-stopped
    env_file:
      - ../../.env
    environment:
      POSTGRES_HOST_AUTH_METHOD: trust
    volumes:
      - fyp_postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h 127.0.0.1 -p 5432 -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - fyp-network
  
  fyp-redis-prod:
    container_name: fyp-redis-prod
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - fyp_redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - fyp-network
  
  fyp-celery-prod:
    container_name: fyp-celery-prod
    image: "${FYP_CELERY_IMAGE}"
    env_file:
      - ../../.env
    volumes:
      - ../../:/app
      - ../../static:/app/static
      - ../../media:/app/media
    depends_on:
      fyp-redis-prod:
        condition: service_healthy
      fyp-postgres-prod:
        condition: service_healthy
    networks:
      - fyp-network
  
  fyp-watchtower-prod:
    container_name: fyp-watchtower-prod
    image: containrrr/watchtower
    command:
      - "--scope=fyp"
      - "--label-enable"
      - "--interval"
      - "30"
      - "--rolling-restart"
    environment:
      - WATCHTOWER_CLEANUP=true
      - REPO_USER=${GITLAB_USER}
      - REPO_PASS=${GITLAB_PASS}
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
  
  fyp-runner-prod:
    container_name: fyp-runner-prod
    image: gitlab/gitlab-runner:${GITLAB_RUNNER_IMAGE_TAG}
    restart: unless-stopped
    environment:
      - CI_SERVER_URL=${GITLAB_SERVER_URL}
      - REGISTRATION_TOKEN=${GITLAB_RUNNER_REGISTRATION_TOKEN}
      - RUNNER_EXECUTOR=docker
      - RUNNER_RUN_UNTAGGED=true
      - RUNNER_TAG_LIST=
      - DOCKER_TLS_CERTDIR=
      - DOCKER_IMAGE=${GITLAB_RUNNER_DOCKER_IMAGE}
    volumes:
      - gitlab-runner-config:/etc/gitlab-runner
      - gitlab-machine-config:/root/.docker/machine
      - /var/run/docker.sock:/var/run/docker.sock
    command:
      - run
      - "--working-directory=/home/gitlab-runner"

volumes:
  fyp_postgres_data:
  fyp_redis_data:
  gitlab-runner-config:
  gitlab-machine-config:

networks:
  fyp-network:
    driver: bridge
  proxy:
    external: true
