version: "3.4"

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

x-metamigo-vars:
  &common-metamigo-variables
  DATABASE_HOST: "metamigo-postgresql"
  DATABASE_NAME: "metamigo"
  DATABASE_ROOT_OWNER: "root"
  DATABASE_ROOT_PASSWORD: ${METAMIGO_DATABASE_ROOT_PASSWORD}
  DATABASE_OWNER: "metamigo"
  DATABASE_PASSWORD: ${METAMIGO_DATABASE_PASSWORD}
  DATABASE_VISITOR: "app_visitor"
  DATABASE_AUTHENTICATOR: "app_graphile_auth"
  DATABASE_AUTHENTICATOR_PASSWORD: ${METAMIGO_DATABASE_AUTHENTICATOR_PASSWORD}
  DATABASE_URL: "postgresql://metamigo:${METAMIGO_DATABASE_PASSWORD}@metamigo-postgresql/metamigo"
  WORKER_DATABASE_URL: "postgresql://metamigo:${METAMIGO_DATABASE_PASSWORD}@metamigo-postgresql/metamigo"
  SHADOW_DATABASE_URL: "postgresql://metamigo:${METAMIGO_DATABASE_PASSWORD}@metamigo-postgresql/metamigo_shadow"
  ROOT_DATABASE_URL: "postgresql://metamigo:${METAMIGO_DATABASE_PASSWORD}@metamigo-postgresql/template1"
  APP_ROOT_DATABASE_URL: "postgresql://root:${METAMIGO_DATABASE_ROOT_PASSWORD}@metamigo-postgresql/metamigo"
  DATABASE_AUTH_URL: "postgresql://app_graphile_auth:${METAMIGO_DATABASE_AUTHENTICATOR_PASSWORD}@metamigo-postgresql/metamigo"
  CORS_ALLOWED_ORIGINS: "https://metamigo-api,${METAMIGO_DOMAIN},http://localhost:3000,http://127.0.0.1:3000"
  FRONTEND_URL: ${METAMIGO_DOMAIN}
  API_URL: "http://metamigo-api:3001"
  NEXTAUTH_URL: ${METAMIGO_DOMAIN}
  NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
  NEXTAUTH_AUDIENCE: ${NEXTAUTH_AUDIENCE}
  NEXTAUTH_SIGNING_KEY_B64: ${NEXTAUTH_SIGNING_KEY_B64}
  NEXTAUTH_ENCRYPTION_KEY_B64: ${NEXTAUTH_ENCRYPTION_KEY_B64}
  GITLAB_EMAIL_ADDRESS: ${GITLAB_EMAIL_ADDRESS}
  GITLAB_ID: ${GITLAB_ID}
  GITLAB_SECRET: ${GITLAB_SECRET}
  SIGNALD_ENABLED: "true"
  SIGNALD_SOCKET: /signald/signald.sock

services:
  metamigo-api:
    # build:
    #   context: .
    #   dockerfile: ./apps/metamigo-cli/Dockerfile
    # image: registry.gitlab.com/digiresilience/link/link-stack/metamigo:${LINK_STACK_VERSION}
    image: registry.gitlab.com/digiresilience/link/metamigo:develop
    container_name: metamigo-api
    restart: ${RESTART}
    command: [ "api" ]
    ports:
      - 127.0.0.1:8003:3001
    environment: *common-metamigo-variables
    volumes:
      - ./signald-state:/signald
    depends_on:
      - metamigo-postgresql
      - signald

  metamigo-frontend:
    # build:
    #   context: .
    #   dockerfile: ./apps/metamigo-frontend/Dockerfile
    # image: registry.gitlab.com/digiresilience/link/link-stack/metamigo-frontend:${LINK_STACK_VERSION}
    command: [ "frontend" ]
    image: registry.gitlab.com/digiresilience/link/metamigo:develop
    container_name: metamigo-frontend
    restart: ${RESTART}
    expose:
      - "3000"
    ports:
      - 127.0.0.1:8002:3000
    depends_on:
      - metamigo-api
    environment:
      <<: *common-metamigo-variables
      VIRTUAL_HOST: ${METAMIGO_VIRTUAL_HOST}
      VIRTUAL_PORT: 3000

  metamigo-worker:
    # build:
    #   context: .
    #   dockerfile: ./apps/metamigo-cli/Dockerfile
    # image: registry.gitlab.com/digiresilience/link/link-stack/metamigo:${LINK_STACK_VERSION}
    image: registry.gitlab.com/digiresilience/link/metamigo:develop
    container_name: metamigo-worker
    restart: ${RESTART}
    command: [ "worker" ]
    environment: *common-metamigo-variables
    depends_on:
      - metamigo-api

  signald:
    container_name: signald
    build: ./docker/signald
    image: registry.gitlab.com/digiresilience/link/link-stack/signald:${LINK_STACK_VERSION}
    restart: ${RESTART}
    user: ${CURRENT_UID}
    volumes:
      - ./signald-state:/signald
    environment:
      <<: *common-global-variables

