name: canvas-lms

x-environment: &BASE-ENV
  CANVAS_DATABASE_HOST: canvas-postgres
  CANVAS_REDIS_HOST: canvas-redis
  ENCRYPTION_KEY: facdd3a131ddd8988b14f6e4e01039c93cfa0160
  POSTGRES_PASSWORD: sekret
  RAILS_ENV: development
  CANVAS_DEV_DOMAIN: canvas-web.$INST_DOMAIN
  CANVAS_PROD_DOMAIN: canvas-web.$INST_DOMAIN
  RCE_HOST: canvas-rce-api-web.$INST_DOMAIN
  INCLUDE_INTERNAL_API_DOCS: 'true'

x-base-service: &BASE-SERVICE
  build:
    context: .
  volumes:
    - .:/usr/src/app
    # needed to prevent local .bundle/plugin/index file from being copied into the container
    - /usr/src/app/.bundle/plugin
    - brandable_css_brands:/usr/src/app/app/stylesheets/brandable_css_brands
    - bundler:/home/docker/.bundle/
    - canvas-docker-gems:/home/docker/.gem/
    - js-utils_es:/usr/src/app/packages/js-utils/es
    - js-utils_lib:/usr/src/app/packages/js-utils/lib
    - js-utils_node_modules:/usr/src/app/packages/js-utils/node_modules
    - locales:/usr/src/app/config/locales/generated
    - log:/usr/src/app/log
    - node_modules:/usr/src/app/node_modules
    - pacts:/usr/src/app/pacts
    - public_dist:/usr/src/app/public/dist
    - reports:/usr/src/app/reports
    - styleguide:/usr/src/app/app/views/info
    - tmp:/usr/src/app/tmp
    - translations:/usr/src/app/public/javascripts/translations
    - yardoc:/usr/src/app/.yardoc
    - yarn-cache:/home/docker/.cache/yarn
  env_file: .env
  environment:
    <<: *BASE-ENV
  labels:
    - traefik.enable=true

services:
  web:
    container_name: canvas-web
    <<: *BASE-SERVICE
    environment:
      <<: *BASE-ENV
      HTTPS_METHOD: noredirect
      # TODO: remove and replace instances with CANVAS_DEV_DOMAIN
      VIRTUAL_HOST: .canvas-web.$INST_DOMAIN
      # AR_QUERY_TRACE: 'true'
      # AR_QUERY_TRACE_TYPE: 'all' # 'all', 'write', or 'read'
      # AR_QUERY_TRACE_LINES: 10
      # DISABLE_N_PLUS_ONE_DETECTION: 'false'
    depends_on:
      - postgres
      - redis
    ports:
      - 80
      - 12345-12354:12345-12354
    networks:
      default:
        aliases:
          - canvas-web
          - canvas-web.$INST_DOMAIN

  web-dev-logs:
    container_name: canvas-web-dev-logs
    <<: *BASE-SERVICE
    command: tail -f log/development.log
    volumes:
      - log:/usr/src/app/log:ro
    labels:
      - traefik.enable=false

  jobs:
    container_name: canvas-jobs
    <<: *BASE-SERVICE
    command: bundle exec script/delayed_job run
    networks:
      default:
        aliases:
          - canvas-jobs

  webpack:
    container_name: canvas-webpack
    <<: *BASE-SERVICE
    command: yarn run webpack
    networks:
      default:
        aliases:
          - canvas-webpack

  postgres:
    container_name: canvas-postgres
    build: ./docker-compose/postgres
    env_file: .env
    environment:
      POSTGRES_PASSWORD: sekret
    labels:
      - traefik.enable=true
    volumes:
      - pg_data:/var/lib/postgresql/data
    networks:
      default:
        aliases:
          - canvas-postgres

  redis:
    container_name: canvas-redis
    image: redis:alpine
    env_file: .env
    labels:
      - traefik.enable=true
    networks:
      default:
        aliases:
          - canvas-redis

  githook-installer:
    container_name: canvas-githook-installer
    build:
      context: .
      dockerfile: Dockerfile.githook
    env_file: .env
    volumes:
      - ./.git:/tmp/.git
      - ./hooks:/tmp/hooks
      - ./script:/tmp/script
    networks:
      default:
        aliases:
          - canvas-githook-installer

networks:
  default:
    external: true
    name: "inst_shared"

volumes:
  brandable_css_brands: {}
  bundler: {}
  canvas-docker-gems: {}
  i18nliner_node_modules: {}
  js-utils_es: {}
  js-utils_lib: {}
  js-utils_node_modules: {}
  k5uploader_es: {}
  k5uploader_lib: {}
  k5uploader_node_modules: {}
  locales: {}
  log: {}
  node_modules: {}
  pg_data: {}
  pacts: {}
  public_dist: {}
  reports: {}
  styleguide: {}
  tmp: {}
  translations: {}
  yardoc: {}
  yarn-cache: {}
