version: '2.3'

# This value intentionally matches the project name on Lagoon.
# It is used to name the CLI_IMAGE to use as a build arg locally.
x-lagoon-project: &lagoon-project
  acs

x-lagoon-local-dev-url: &lagoon-local-dev-url
  http://acs.docker.amazee.io

# See GOVCMS_IMAGE_VERSION in "Variables" at https://github.com/govCMS/govCMS8/wiki
x-govcms-image-version: &govcms-image-version
  ${GOVCMS_IMAGE_VERSION:-10.x-latest}

x-volumes: &default-volumes
  volumes:
    - ./themes:/app/web/themes/custom:${VOLUME_FLAGS:-delegated}
    - ./files:/app/web/sites/default/files:delegated
    - ./tests/behat/features:/app/tests/behat/features:${VOLUME_FLAGS:-delegated}
    - ./tests/behat/screenshots:/app/tests/behat/screenshots:${VOLUME_FLAGS:-delegated}
    - ./tests/phpunit/tests:/app/tests/phpunit/tests:${VOLUME_FLAGS:-delegated}
    - ./config:/app/config

x-volumes-paas: &paas-volumes
  volumes:
    - .:/app:delegated

x-environment: &default-environment
  STAGE_FILE_PROXY_URL: ${STAGE_FILE_PROXY_URL:-}
  LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-}
  LAGOON_PROJECT: *lagoon-project
  LAGOON_ROUTE: &default-url ${LOCALDEV_URL:-http://acs.docker.amazee.io}
  GOVCMS_IMAGE_VERSION: ${GOVCMS_IMAGE_VERSION:-10.x-latest}
  DEV_MODE: "${DEV_MODE:-false}"
  XDEBUG_ENABLE: ${XDEBUG_ENABLE:-}
  DOCKERHOST: ${DOCKERHOST:-host.docker.internal}
  X_FRAME_OPTIONS: ${X_FRAME_OPTIONS:-SameOrigin}
  DRUPAL_SHIELD_USER: ${DRUPAL_SHIELD_USER:-}
  DRUPAL_SHIELD_PASS: ${DRUPAL_SHIELD_PASS:-}
  GOVCMS_DEPLOY_WORKFLOW_CONFIG: ${GOVCMS_DEPLOY_WORKFLOW_CONFIG:-import}
  GOVCMS_PREPARE_XML_SCRIPT: /app/vendor/bin/govcms-prepare-xml
  CLAMAV_HOST: av
  CLAMAV_MODE: daemon

services:

  cli:
    build:
      context: .
      dockerfile: .docker/Dockerfile.cli
      args:
        LAGOON_SAFE_PROJECT: *lagoon-project
        GOVCMS_IMAGE_VERSION: *govcms-image-version
        GOVCMS_GITHUB_TOKEN: ${GOVCMS_GITHUB_TOKEN:-}
    image: *lagoon-project
    labels:
      lagoon.type: cli-persistent
      lagoon.persistent.name: nginx
      lagoon.persistent: /app/web/sites/default/files/
    << : *paas-volumes
    environment:
      << : *default-environment
    # Mount volumes from Pygmy to inject host SSH key into container.
    # https://pygmy.readthedocs.io/en/master/ssh_agent/
    volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI.
      - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI.
    networks:
      - amazeeio-network
      - default

  test:
    build:
      context: .
      dockerfile: .docker/Dockerfile.test
      args:
        CLI_IMAGE: *lagoon-project
        GOVCMS_IMAGE_VERSION: *govcms-image-version
        SITE_AUDIT_VERSION: ${SITE_AUDIT_VERSION:-7.x-3.x}
    labels:
      lagoon.type: none
    << : *paas-volumes
    depends_on:
      - cli
    environment:
      << : *default-environment
    networks:
      - amazeeio-network
      - default

  nginx:
    build:
      context: .
      dockerfile: .docker/Dockerfile.nginx-drupal
      args:
        CLI_IMAGE: *lagoon-project
        GOVCMS_IMAGE_VERSION: *govcms-image-version
    labels:
      lagoon.type: nginx-php-persistent
      lagoon.persistent: /app/web/sites/default/files/
    << : *paas-volumes
    depends_on:
      - cli
    environment:
      << : *default-environment
      LAGOON_LOCALDEV_URL: *default-url
    networks:
      - amazeeio-network
      - default

  php:
    build:
      context: .
      dockerfile: .docker/Dockerfile.php
      args:
        CLI_IMAGE: *lagoon-project
        GOVCMS_IMAGE_VERSION: *govcms-image-version
    labels:
      lagoon.type: nginx-php-persistent
      lagoon.name: nginx
      lagoon.persistent: /app/web/sites/default/files/
    << : *paas-volumes
    depends_on:
      - cli
    environment:
      << : *default-environment
    networks:
      - amazeeio-network
      - default

  mariadb:
    image: ${MARIADB_DATA_IMAGE:-govcms/mariadb-drupal:10.x-latest}
    labels:
      lagoon.type: mariadb
      lagoon.image: govcms/mariadb-drupal:10.x-latest
    ports:
      - "3306" # Find port on host with `docker-compose port mariadb 3306`
    environment:
      << : *default-environment

  av:
    image: govcms/av:latest
    labels:
      lagoon.type: none

  # Uncomment to enable solr.
  # solr:
  #   build:
  #     context: .
  #     dockerfile: .docker/Dockerfile.solr
  #     args:
  #       GOVCMS_IMAGE_VERSION: *govcms-image-version
  #   labels:
  #     lagoon.type: solr
  #   ports:
  #     - "8983" # Find port on host with `docker-compose port solr 8983`
  #   depends_on:
  #     - cli
  #   environment:
  #     << : *default-environment

  chrome:
    image: selenium/standalone-chrome:4.5.2-20221021
    shm_size: '1gb'
    depends_on:
      - test
    labels:
      lagoon.type: none
    << : *paas-volumes

networks:
  amazeeio-network:
    external: true
