version: "3.4"

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: "zammad-postgresql"
  POSTGRESQL_PORT: "5432"
  POSTGRESQL_USER: "zammad"
  POSTGRESQL_PASS: ${ZAMMAD_DATABASE_PASSWORD}
  POSTGRESQL_DB: "zammad_production"

services:
  zammad-elasticsearch:
    container_name: zammad-elasticsearch
    environment:
      discovery.type: single-node
      ES_JAVA_OPTS: -Xms750m -Xmx750m
      xpack.security.enabled: false
      <<: *common-global-variables
    build: ./docker/elasticsearch
    image: registry.gitlab.com/digiresilience/link/link-stack/elasticsearch:${LINK_STACK_VERSION}
    restart: ${RESTART}
    volumes:
      - elasticsearch-data:/usr/share/elasticsearch/data

  zammad-init:
    platform: linux/x86_64
    container_name: zammad-init
    command: [ "zammad-init" ]
    depends_on:
      - zammad-postgresql
    environment:
      <<: [ *common-zammad-variables, *common-global-variables ]
      POSTGRESQL_USER: zammad
      POSTGRESQL_PASS: ${ZAMMAD_DATABASE_PASSWORD}
    build: ./docker/zammad
    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: ./docker/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:
      - 127.0.0.1:8001:8080
    depends_on:
      - zammad-railsserver
    build: ./docker/zammad
    image: registry.gitlab.com/digiresilience/link/link-stack/zammad:${LINK_STACK_VERSION}
    restart: ${RESTART}
    environment:
      <<: *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-postgresql:
    container_name: zammad-postgresql
    environment:
      <<: [ *common-global-variables, *common-zammad-variables ]
      POSTGRES_USER: zammad
      POSTGRES_PASSWORD: ${ZAMMAD_DATABASE_PASSWORD}
    build: ./docker/postgresql
    image: registry.gitlab.com/digiresilience/link/link-stack/postgresql:${LINK_STACK_VERSION}
    restart: ${RESTART}
    ports:
      - 127.0.0.1:5432:5432
    volumes:
      - postgresql-data:/var/lib/postgresql/data

  zammad-railsserver:
    platform: linux/x86_64
    container_name: zammad-railsserver
    command: [ "zammad-railsserver" ]
    depends_on:
      - zammad-memcached
      - zammad-postgresql
      - zammad-redis
    environment:
      <<: [ *common-global-variables, *common-zammad-variables ]
    build: ./docker/zammad
    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: ./docker/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: ./docker/zammad
    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: ./docker/zammad
    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:
  elasticsearch-data:
    driver: local
  postgresql-data:
    driver: local
  redis-data:
    driver: local
  zammad-config-nginx:
    driver: local
  zammad-var:
    driver: local
  zammad-storage:
    driver: local
