networks:
  database:
    external: true
  frontend:
  backend:
  traefik:
    external: true
volumes:
  opdata:

x-op-restart-policy: &restart_policy
  restart: unless-stopped
x-op-image: &image
  image: openproject/openproject:${OPENPROJECT_TAG:-15-slim}
x-op-app: &app
  <<: [*image, *restart_policy]
  environment:
    OPENPROJECT_HTTPS: "${OPENPROJECT_HTTPS:-true}"
    OPENPROJECT_HOST__NAME: "${OPENPROJECT_HOST__NAME:-localhost:8080}"
    OPENPROJECT_HSTS: "${OPENPROJECT_HSTS:-true}"
    RAILS_CACHE_STORE: "memcache"
    OPENPROJECT_CACHE__MEMCACHE__SERVER: "cache:11211"
    OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
    DATABASE_URL: "postgres://${OPENPROJECT_DB_USER:-openproject}:${OPENPROJECT_DB_PASSWORD:-openproject}@postgres/openproject?pool=20&encoding=unicode&reconnect=true"
    RAILS_MIN_THREADS: ${OPENPROJECT_RAILS_MIN_THREADS:-4}
    RAILS_MAX_THREADS: ${OPENPROJECT_RAILS_MAX_THREADS:-16}
    # set to true to enable the email receiving feature. See ./docker/cron for more options
    IMAP_ENABLED: "${OPENPROJECT_IMAP_ENABLED:-false}"
  volumes:
    - "${OPENPROJECT_OPDATA:-opdata}:/var/openproject/assets"

services:
  cache:
    image: memcached
    networks:
      - backend
      - database
    restart: unless-stopped

  proxy:
    build:
      context: ./proxy
      args:
        APP_HOST: web
    image: openproject/proxy
    depends_on:
      - web
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik
      - traefik.http.routers.openproject.entrypoints=web,websecure
      - traefik.http.routers.openproject.middlewares=https-redirect
      - traefik.http.routers.openproject.tls=true
      - traefik.http.routers.openproject.tls.certresolver=le
      - traefik.http.routers.openproject.rule=Host(`${OPENPROJECT_DOMAIN}`)
      - traefik.http.services.openproject.loadbalancer.server.port=80
    networks:
      - traefik
      - frontend
    restart: unless-stopped

  web:
    <<: *app
    command: "./docker/prod/web"
    networks:
      - database
      - frontend
      - backend
    depends_on:
      - cache
      - seeder
    labels:
      - autoheal=true
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}/health_checks/default"]
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s

  autoheal:
    image: willfarrell/autoheal:1.2.0
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      AUTOHEAL_CONTAINER_LABEL: autoheal
      AUTOHEAL_START_PERIOD: 600
      AUTOHEAL_INTERVAL: 30

  worker:
    <<: *app
    command: "./docker/prod/worker"
    networks:
      - backend
      - database
    depends_on:
      - cache
      - seeder

  cron:
    <<: *app
    command: "./docker/prod/cron"
    networks:
      - backend
      - database
    depends_on:
      - cache
      - seeder

  seeder:
    <<: *app
    command: "./docker/prod/seeder"
    restart: on-failure
    networks:
      - backend
      - database

