x-global-vars: &common-global-variables
  TZ: Etc/UTC

x-zammad-vars: &common-zammad-variables
  MEMCACHE_SERVERS: "zammad-memcached:11211"
  REDIS_URL: "redis://zammad-redis:6379"
  POSTGRESQL_HOST: "postgresql"
  POSTGRESQL_PORT: "5432"
  POSTGRESQL_USER: "zammad"
  POSTGRESQL_PASS: ${ZAMMAD_DATABASE_PASSWORD}
  POSTGRESQL_DB: "zammad_production"
  ELASTICSEARCH_HOST: ${OPENSEARCH_HOST}
  ELASTICSEARCH_USER: ${OPENSEARCH_USER}
  ELASTICSEARCH_PASS: ${OPENSEARCH_ADMIN_PASSWORD}
  ELASTICSEARCH_SSL_VERIFY: "false" # this doesn't set es_ssl_verify as expected, but ideally it would
  ELASTICSEARCH_SCHEMA: "https"

services:
  zammad-init:
    platform: linux/x86_64
    container_name: zammad-init
    command: ["zammad-init"]
    depends_on:
      - postgresql
    environment:
      <<: [*common-zammad-variables, *common-global-variables]
      POSTGRESQL_USER: zammad
      POSTGRESQL_PASS: ${ZAMMAD_DATABASE_PASSWORD}
    build:
      context: ../zammad
      args:
        EMBEDDED: "true"
    image: registry.gitlab.com/digiresilience/link/link-stack/zammad:${LINK_STACK_VERSION}
    restart: on-failure
    user: 0:0
    volumes:
      - zammad-config-nginx:/etc/nginx/sites-enabled
      - zammad-var:/opt/zammad/var

  zammad-memcached:
    container_name: zammad-memcached
    command: memcached -m 256M
    build: ../memcached
    image: registry.gitlab.com/digiresilience/link/link-stack/memcached:${LINK_STACK_VERSION}
    restart: ${RESTART}
    environment:
      <<: *common-global-variables

  zammad-nginx:
    platform: linux/x86_64
    container_name: zammad-nginx
    command: ["zammad-nginx"]
    expose:
      - "8080"
    ports:
      - 8001:8080
    depends_on:
      - zammad-railsserver
    build:
      context: ../zammad
      args:
        EMBEDDED: "true"
    image: registry.gitlab.com/digiresilience/link/link-stack/zammad:${LINK_STACK_VERSION}
    restart: ${RESTART}
    environment:
      <<: [*common-zammad-variables, *common-global-variables]
      NGINX_SERVER_SCHEME: https
      VIRTUAL_HOST: ${ZAMMAD_VIRTUAL_HOST}
      VIRTUAL_PORT: 8080
    volumes:
      - zammad-config-nginx:/etc/nginx/sites-enabled:ro
      - zammad-var:/opt/zammad/var:ro

  zammad-railsserver:
    platform: linux/x86_64
    container_name: zammad-railsserver
    command: ["zammad-railsserver"]
    depends_on:
      - zammad-memcached
      - zammad-redis
      - postgresql
    environment:
      <<: [*common-global-variables, *common-zammad-variables]
      RAILS_RELATIVE_URL_ROOT: /zammad
    build:
      context: ../zammad
      args:
        EMBEDDED: "true"
    image: registry.gitlab.com/digiresilience/link/link-stack/zammad:${LINK_STACK_VERSION}
    restart: ${RESTART}
    volumes:
      - zammad-var:/opt/zammad/var
      - zammad-storage:/opt/zammad/storage

  zammad-redis:
    container_name: zammad-redis
    build: ../redis
    image: registry.gitlab.com/digiresilience/link/link-stack/redis:${LINK_STACK_VERSION}
    restart: ${RESTART}
    environment:
      <<: *common-global-variables
    volumes:
      - redis-data:/data

  zammad-scheduler:
    platform: linux/x86_64
    container_name: zammad-scheduler
    command: ["zammad-scheduler"]
    depends_on:
      - zammad-memcached
      - zammad-railsserver
      - zammad-redis
    environment:
      <<: [*common-global-variables, *common-zammad-variables]
    build:
      context: ../zammad
      args:
        EMBEDDED: "true"
    image: registry.gitlab.com/digiresilience/link/link-stack/zammad:${LINK_STACK_VERSION}
    restart: ${RESTART}
    volumes:
      - zammad-var:/opt/zammad/var
      - zammad-storage:/opt/zammad/storage

  zammad-websocket:
    platform: linux/x86_64
    container_name: zammad-websocket
    command: ["zammad-websocket"]
    depends_on:
      - zammad-memcached
      - zammad-railsserver
      - zammad-redis
    environment:
      <<: [*common-global-variables, *common-zammad-variables]
    build:
      context: ../zammad
      args:
        EMBEDDED: "true"
    image: registry.gitlab.com/digiresilience/link/link-stack/zammad:${LINK_STACK_VERSION}
    restart: ${RESTART}
    volumes:
      - zammad-var:/opt/zammad/var
      - zammad-storage:/opt/zammad/storage

volumes:
  redis-data:
    driver: local
  zammad-config-nginx:
    driver: local
  zammad-var:
    driver: local
  zammad-storage:
    driver: local
