services:
  royalties-mysql:
    image: mysql:8.0.36
    platform: linux/amd64
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=royalty_accounting
      - MYSQL_USER=royalties
      - MYSQL_PASSWORD=1234
    ports:
      - "6050:3306"
    tmpfs:
      - /var/lib/mysql:rw,noexec,nodev,nosuid,size=512m
    command:
      # "Binary logs" are enabled by default in MySQL 8.0 which comes at a performance cost.
      # We can disable it for slightly better performance since we don't need it to run our tests.
      - --disable-log-bin
      # Speeds up connections auth
      - --skip-name-resolve
      # Reduce durability
      - --innodb_doublewrite=0
      - --innodb_flush_log_at_trx_commit=2
      - --sync_binlog=0
      # Consistency with the production database
      - --sql_mode=NO_ENGINE_SUBSTITUTION

  royalties-liquibase-runner:
    image: 437795906767.dkr.ecr.us-east-1.amazonaws.com/royalties-liquibase-runner:latest
    depends_on:
      - royalties-mysql
    volumes:
      - sqlite:/var/lib/sqlite
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_NAME=royalty_accounting
      - MYSQL_DEPLOY_USER=root
      - MYSQL_DEPLOY_PASSWORD=root
      - MYSQL_SERVICE_USER=royalties
      - GITHUB_USER=theorchard
      - GITHUB_REPO=database
      - GITHUB_BRANCH=master
      - GITHUB_REPO_DIR=royalty_accounting
      # The following are test-only and overridden during env builds.
      - SQLITE_ENABLE=true

  royalties-ows-royalties:
    image: 086679231553.dkr.ecr.us-east-1.amazonaws.com/ows-royalties:latest
    volumes:
      - .split:/var/app/.split
    depends_on:
      - royalties-liquibase-runner
      - royalties-ows-abacus-account
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_USER=royalties
      - MYSQL_DB_PASS=1234
      - MYSQL_DB_NAME=royalty_accounting
      - S3_SALES_BUCKET_NAME=qa-royalties-sales-files
      - S3_ABACUS_ADJUSTMENTS_BUCKET=qa-abacus-adjustments
      - S3_ABACUS_QUARANTINE_BUCKET=qa-abacus-quarantine
      - AWS_DEFAULT_REGION=us-east-1
      - AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
      - SPLIT_FILE_PATH=/var/app/.split
      - OWSREQUEST_SERVICE_MAP={"ows-abacus-account":"http://royalties-ows-abacus-account:8080"}

  royalties-ows-abacus-account:
    image: 086679231553.dkr.ecr.us-east-1.amazonaws.com/ows-abacus-account:latest
    volumes:
      - ./.split:/var/app/.split.file:ro
    depends_on:
      - royalties-liquibase-runner
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_USER=royalties
      - MYSQL_DB_PASS=1234
      - MYSQL_DB_NAME=royalty_accounting
      - SPLIT_FILE_PATH=/var/app/.split.file

  royalties-local:
    build:
      context: .
      dockerfile: Dockerfile
      target: deploy
    depends_on:
      - royalties-liquibase-runner
      - royalties-ows-abacus-account
    volumes:
      - ./.split:/var/app/.split.file:ro
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_USER=royalties
      - MYSQL_DB_PASS=1234
      - MYSQL_DB_NAME=royalty_accounting
      - S3_SALES_BUCKET_NAME=qa-royalties-sales-files
      - S3_ABACUS_ADJUSTMENTS_BUCKET=qa-abacus-adjustments
      - S3_ABACUS_QUARANTINE_BUCKET=qa-abacus-quarantine
      - SPLIT_FILE_PATH=/var/app/.split.file
      - AWS_DEFAULT_REGION=us-east-1
      - AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
      - OWSREQUEST_SERVICE_MAP={"ows-abacus-account":"http://royalties-ows-abacus-account:8080"}
    ports:
      - "6052:8080"

  unit-lint:
    depends_on:
      - royalties-liquibase-runner
    build:
      context: .
      target: unit-lint
    volumes:
      - .:/var/app
      - sqlite:/var/lib/sqlite
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_USER=royalties
      - MYSQL_DB_PASS=1234
      - MYSQL_DB_NAME=royalty_accounting
      - MYSQL_TEST_DB_NAME=royalty_accounting_test
      - S3_SALES_BUCKET_NAME=qa-royalties-sales-files
      - S3_ABACUS_ADJUSTMENTS_BUCKET=qa-abacus-adjustments
      - TEST_ENVIRONMENT

  test-integration:
    depends_on:
      - royalties-ows-royalties
    build:
      context: .
      target: test-integration
    volumes:
      - .:/var/app
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_USER=royalties
      - MYSQL_DB_PASS=1234
      - MYSQL_DB_NAME=royalty_accounting
      - S3_SALES_BUCKET_NAME=qa-royalties-sales-files
      - S3_ABACUS_ADJUSTMENTS_BUCKET=qa-abacus-adjustments
      - S3_ABACUS_QUARANTINE_BUCKET=qa-abacus-quarantine
      - AWS_BUCKET_OWNER=$AWS_BUCKET_OWNER
      - ROYALTIES_API_BASE_URL=http://royalties-ows-royalties:8080
      - AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
      - DD_ENV=${DD_ENV:-qa}
      - DD_SERVICE=ows-royalties-integration-tests
      - DD_VERSION=${DD_VERSION:-local}
      - DD_SITE=${DD_SITE:-sonymusic-pde.datadoghq.com}
      - DD_AGENT_HOST=host-gateway
      - DD_GIT_REPOSITORY_URL
      - DD_GIT_COMMIT_SHA
      - DD_GIT_BRANCH
      - DD_GIT_COMMIT_AUTHOR_NAME
      - DD_GIT_COMMIT_AUTHOR_EMAIL
      - DD_GIT_COMMIT_MESSAGE
      - JOB_NAME=${JOB_NAME:-}
      - BUILD_NUMBER=${BUILD_NUMBER:-}
      - BUILD_ID=${BUILD_ID:-}
      - JENKINS_URL=${JENKINS_URL:-}
      - BUILD_URL=${BUILD_URL:-}
    extra_hosts:
      - "host-gateway:host-gateway"

  test-integration-local:
    depends_on:
      - royalties-local
    build:
      context: .
      target: test-integration
    volumes:
      - .:/var/app
    environment:
      - MYSQL_DB_HOST=royalties-mysql
      - MYSQL_DB_PORT=3306
      - MYSQL_DB_USER=royalties
      - MYSQL_DB_PASS=1234
      - MYSQL_DB_NAME=royalty_accounting
      - S3_SALES_BUCKET_NAME=qa-royalties-sales-files
      - S3_ABACUS_ADJUSTMENTS_BUCKET=qa-abacus-adjustments
      - S3_ABACUS_QUARANTINE_BUCKET=qa-abacus-quarantine
      - AWS_BUCKET_OWNER=$AWS_BUCKET_OWNER
      - ROYALTIES_API_BASE_URL=http://royalties-local:8080
      - AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
      - AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
      - DD_ENV=${DD_ENV:-qa}
      - DD_SERVICE=ows-royalties-integration-tests
      - DD_VERSION=${DD_VERSION:-local}
      - DD_SITE=${DD_SITE:-sonymusic-pde.datadoghq.com}
      - DD_AGENT_HOST=host-gateway
      - DD_GIT_REPOSITORY_URL
      - DD_GIT_COMMIT_SHA
      - DD_GIT_BRANCH
      - DD_GIT_COMMIT_AUTHOR_NAME
      - DD_GIT_COMMIT_AUTHOR_EMAIL
      - DD_GIT_COMMIT_MESSAGE
      - JOB_NAME=${JOB_NAME:-}
      - BUILD_NUMBER=${BUILD_NUMBER:-}
      - BUILD_ID=${BUILD_ID:-}
      - JENKINS_URL=${JENKINS_URL:-}
      - BUILD_URL=${BUILD_URL:-}
    extra_hosts:
      - "host-gateway:host-gateway"

volumes:
  sqlite:
