version: "2"
services:
  db:
    image: mariadb:10.2
    network_mode: "service:web"
    environment:
      - MYSQL_DATABASE=plots
      - MYSQL_USER=plots
      - MYSQL_PASSWORD=plots
      - MYSQL_RANDOM_ROOT_PASSWORD=true
    volumes:
      - ../config/my.cnf:/etc/mysql/my.cnf
      # for configuration 
      - ../../mysql:/var/lib/mysql
      # for persistence
      - ../../dump:/docker-entrypoint-initdb.d
      # for importing a dump
      # if you want to re-import simply put away ../../mysql/*
  redis:
    image: redis:latest
    command: redis-server
  web:
    build: ..
    cap_add:
      - SYS_PTRACE
    environment:
      - COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}
      - DB_USER=${DB_USER}
      - DB_NAME=${DB_NAME}
      - DB_PASS=${DB_PASS}
      - DB_HOST=${DB_HOST}
      - RAILS_MAX_THREADS=${RAILS_MAX_THREADS}
      - RAILS_ENV=${RAILS_ENV}
      - SECRET_KEY_BASE=${SECRET_KEY_BASE}
      - REDIS_URL=redis://redis:6379/0
      - DANGER_GITHUB_API_TOKEN=${DANGER_GITHUB_API_TOKEN}
      - TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}
      - TRAVIS_REPO_SLUG=${TRAVIS_REPO_SLUG}
      - CI=${CI}
      - TRAVIS=${TRAVIS}
      - CONTINUOUS_INTEGRATION=${CONTINUOUS_INTEGRATION}
      # used to tell if we are in a Travis environment:
      - HAS_JOSH_K_SEAL_OF_APPROVAL=${HAS_JOSH_K_SEAL_OF_APPROVAL}
      - GITHUB_ACTION=${GITHUB_ACTION}
      - GITHUB_TOKEN=${GITHUB_TOKEN}
      - GITHUB_REPOSITORY=${GITHUB_REPOSITORY}
      - GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH}
      - GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME}
      - QT_QPA_PLATFORM=${QT_QPA_PLATFORM}
      - TASK=${TASK}
    links:
      - redis
    volumes:
      - ..:/app
    restart: unless-stopped
  sidekiq:
    build: ..
    command: bundle exec sidekiq
    depends_on:
      - db
      - redis
    links:
      - db
      - redis
    volumes:
      - .:/app
    environment:
      - RAILS_ENV=${RAILS_ENV}
      - REDIS_URL=redis://redis:6379/0
      - SECRET_KEY_BASE=${SECRET_KEY_BASE}
      - DB_USER=${DB_USER}
      - DB_NAME=${DB_NAME}
      - DB_PASS=${DB_PASS}
      - DB_HOST=${DB_HOST}
      - DB_SOCKET=${DB_SOCKET}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASS=${SMTP_PASS}
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT}
      - SMTP_AUTH=${SMTP_AUTH}
      - SMTP_STLS=${SMTP_STLS}
