version: "3"
services:
  db:
    image: docker.io/library/mysql:8.4
    platform: linux/amd64
    networks:
      - backend
    expose:
      - 3306
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      MYSQL_USER: tower
      MYSQL_PASSWORD: tower
      MYSQL_DATABASE: tower
    healthcheck:
      test: ["CMD", "mysqladmin" , "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10
    restart: always
    volumes:
      #  To use the pipeline optimization service, uncomment the lines below to mount the initialization script
      #  - type: bind
      #    source: ./init.sql
      #    target: /docker-entrypoint-initdb.d/init.sql

      # Store the MySQL data in a directory on the host
      - $HOME/.tower/db/mysql:/var/lib/mysql

  redis:
    # This Redis definition is provided for convenience and pulls from Docker
    # Hub's public registry. For production use we recommend:
    #   - Vendoring this image to your own registry, or authenticating to Docker
    #     Hub to avoid pull rate limits.
    #   - Replacing this in-cluster instance with a managed service (e.g.
    #     ElastiCache, Azure Cache for Redis, Memorystore) or an official Redis
    #     installation source for durability and operational support.
    image: docker.io/library/redis:7.4
    platform: linux/amd64
    networks:
      - backend
    expose:
      - 6379
    command: --appendonly yes
    restart: always
    # Store the Redis data in a directory on the host
    volumes:
      - $HOME/.tower/db/redis:/data

  migrate:
    image: cr.seqera.io/enterprise/platform/migrate-db:v26.2.3
    platform: linux/amd64
    command: -c "/migrate-db.sh"
    networks:
      - backend
    volumes:
      - $PWD/tower.yml:/tower.yml
    env_file:
      # Seqera environment variables — see https://docs.seqera.io/platform-enterprise/enterprise/configuration/overview for details
      - tower.env
    restart: no

    depends_on:
      db:
        condition: service_healthy

  cron:
    image: cr.seqera.io/enterprise/platform/backend:v26.2.3
    platform: linux/amd64
    command: -c '/tower.sh'
    networks:
      - backend
    volumes:
      # A Studios RSA key is required for the Studios functionality. Uncomment the line below to mount the key.
      #- $PWD/data-studios-rsa.pem:/data-studios-rsa.pem
      - $PWD/tower.yml:/tower.yml
    env_file:
      - tower.env
    environment:
      # Micronaut environments are required. Do not edit these values
      - MICRONAUT_ENVIRONMENTS=prod,redis,cron
    restart: always
    depends_on:
      migrate:
        condition: service_completed_successfully


  backend:
    image: cr.seqera.io/enterprise/platform/backend:v26.2.3
    platform: linux/amd64
    command: -c '/wait-for-it.sh db:3306 -t 60; /tower.sh'
    networks:
      - frontend
      - backend
    expose:
      - 8080
    volumes:
      - $PWD/tower.yml:/tower.yml
      # A Studios RSA key is required for the Studios functionality. Uncomment the line below to mount the key.
      #- $PWD/data-studios-rsa.pem:/data-studios-rsa.pem
    env_file:
      # Seqera environment variables — see https://docs.seqera.io/platform-enterprise/enterprise/configuration/overview for details
      - tower.env
    environment:
      # Micronaut environments are required. Do not edit these values
      - MICRONAUT_ENVIRONMENTS=prod,redis,ha
    restart: always
    depends_on:
      - db
      - redis
      - cron

  frontend:
    image: cr.seqera.io/enterprise/platform/frontend:v26.2.3
    platform: linux/amd64
    networks:
      - frontend
    ports:
      # From 26.2 the frontend image is unprivileged and listens on 8000.
      # Set the container side to match NGINX_LISTEN_PORT if you override it.
      - 8000:8000
    restart: always
    depends_on:
      - backend

# Uncomment the following section to enable Studios functionality. See [Studios configuration](../../../studios/overview) for more information.
#  connect-proxy:
#    image: cr.seqera.io/enterprise/studios/proxy:0.14.0
#    platform: linux/amd64
#    env_file:
#      - data-studios.env
#    networks:
#      - frontend
#      - backend
#    ports:
#      - 9090:9090
#    restart: always
#    depends_on:
#      - redis
#   volumes:
#     - $HOME/.tower/connect:/data
#
#  connect-server:
#    image: cr.seqera.io/enterprise/studios/server:0.14.0
#    platform: linux/amd64
#    env_file:
#      - data-studios.env
#    networks:
#      - backend
#    ports:
#      - 7070:7070
#    restart: always

  # Uncomment the following section to enable the pipeline optimization service. Add TOWER_ENABLE_GROUNDSWELL
  # or GROUNDSWELL_SERVER_URL to tower.env environment variables
  # groundswell:
  #   image: cr.seqera.io/enterprise/platform/pipeline-optimization:0.3.3
  #   command: bash -c 'bin/wait-for-it.sh db:3306 -t 60; bin/migrate-db.sh; bin/serve.sh'
  #   networks:
  #     - backend
  #   ports:
  #     - 8090:8090
  #   env_file:
  #     - groundswell.env
  #   restart: always
  #   depends_on:
  #     - db

networks:
  frontend: {}
  backend: {}
