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_PASS}
  ELASTICSEARCH_SSL_VERIFY: false # this doesn't set es_ssl_verify as expected, but ideally it would
  ELASTICSEARCH_SCHEMA: "https"

x-bridge-vars: &common-bridge-variables
  DATABASE_HOST: "postgresql"
  DATABASE_NAME: "bridge"
  DATABASE_ROOT_OWNER: "root"
  DATABASE_ROOT_PASSWORD: ${BRIDGE_DATABASE_ROOT_PASSWORD}
  DATABASE_OWNER: "bridge"
  DATABASE_PASSWORD: ${BRIDGE_DATABASE_PASSWORD}
  DATABASE_URL: "postgresql://bridge:${BRIDGE_DATABASE_PASSWORD}@bridge-postgresql/bridge"
  WORKER_DATABASE_URL: "postgresql://bridge:${BRIDGE_DATABASE_PASSWORD}@bridge-postgresql/bridge"
  SHADOW_DATABASE_URL: "postgresql://bridge:${BRIDGE_DATABASE_PASSWORD}@bridge-postgresql/bridge_shadow"
  ROOT_DATABASE_URL: "postgresql://bridge:${BRIDGE_DATABASE_PASSWORD}@bridge-postgresql/template1"
  DATABASE_AUTH_URL: "postgresql://app_graphile_auth:${BRIDGE_DATABASE_AUTHENTICATOR_PASSWORD}@bridge-postgresql/bridge"
  FRONTEND_URL: ${BRIDGE_DOMAIN}
  API_URL: "http://bridge-api:3001"
  NEXTAUTH_URL: ${BRIDGE_DOMAIN}
  NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}

services:
  postgresql:
    container_name: postgresql
    environment:
      <<:
        [
          *common-global-variables,
          *common-zammad-variables,
          *common-bridge-variables,
        ]
      POSTGRES_USER: zammad
      POSTGRES_PASSWORD: ${ZAMMAD_DATABASE_PASSWORD}
    build: ../postgresql
    image: registry.gitlab.com/digiresilience/link/link-stack/postgresql:${LINK_STACK_VERSION}
    restart: ${RESTART}
    ports:
      - 5432:5432
    volumes:
      - postgresql-data:/var/lib/postgresql/data

#    volumes:
#     - bridge-data:/var/lib/postgresql/data
#     - ./scripts/bootstrap-bridge.sh:/docker-entrypoint-initdb.d/bootstrap-bridge.sh
#environment:
# <<: *common-bridge-variables
# POSTGRES_PASSWORD: ${BRIDGE_DATABASE_ROOT_PASSWORD}
#  POSTGRES_USER: "root"
# POSTGRES_DB: "bridge"

volumes:
  postgresql-data:
    driver: local
