version: "2"
services:
  db:
    image: mariadb:10.2
    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/*
  web:
    ports:
      - "127.0.0.1:5001:4000"
    build: ..
    logging:
      driver: "json-file"
      options:
        max-size: "1024m"
    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}
      - RECAPTCHA_SECRET_KEY=${RECAPTCHA_SECRET_KEY}
      - RECAPTCHA_SITE_KEY=${RECAPTCHA_SITE_KEY}
      - SERVER_ADDRESS=${SERVER_ADDRESS}
      - USERNAME=${USERNAME}
      - EMAIL_PASSWORD=${EMAIL_PASSWORD}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASS=${SMTP_PASS}
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT}
      - SMTP_AUTH=${SMTP_AUTH}
      - SMTP_STLS=${SMTP_STLS}
      - OAUTH_GOOGLE_APP_KEY=${OAUTH_GOOGLE_APP_KEY}
      - OAUTH_GOOGLE_APP_SECRET=${OAUTH_GOOGLE_APP_SECRET}
      - OAUTH_GITHUB_APP_KEY=${OAUTH_GITHUB_APP_KEY}
      - OAUTH_GITHUB_APP_SECRET=${OAUTH_GITHUB_APP_SECRET}
      - OAUTH_TWITTER_APP_KEY=${OAUTH_TWITTER_APP_KEY}
      - OAUTH_TWITTER_APP_SECRET=${OAUTH_TWITTER_APP_SECRET}
      - OAUTH_FACEBOOK_APP_KEY=${OAUTH_FACEBOOK_APP_KEY}
      - OAUTH_FACEBOOK_APP_SECRET=${OAUTH_FACEBOOK_APP_SECRET}
      - REDIS_URL=redis://redis:6379/0
      - TWITTER_CONSUMER_KEY=${TWITTER_CONSUMER_KEY}
      - TWITTER_CONSUMER_SECRET=${TWITTER_CONSUMER_SECRET}
      - TWITTER_ACCESS_TOKEN=${TWITTER_ACCESS_TOKEN}
      - TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
      - WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
      - TWEET_SEARCH=${TWEET_SEARCH}
      - GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
      - GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
      - GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
      - GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
      - FOG_PROVIDER=${FOG_PROVIDER}
    volumes:
      - ..:/app
      - /etc/passwd:/etc/passwd:ro
      - /etc/group:/etc/group:ro
    links:
      - redis
      - db
    restart: on-failure:5
  redis:
    image: redis:latest
    command: redis-server
  sidekiq:
    build: ..
    command: bundle exec sidekiq -L log/sidekiq.log
    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}
  mailman:
    build: ..
    command: script/mailman_server
    environment:
      - RAILS_ENV=${RAILS_ENV}
      - SECRET_KEY_BASE=${SECRET_KEY_BASE}
      - SERVER_ADDRESS=${SERVER_ADDRESS}
      - USERNAME=${USERNAME}
      - EMAIL_PASSWORD=${EMAIL_PASSWORD}
      - DB_USER=${DB_USER}
      - DB_NAME=${DB_NAME}
      - DB_PASS=${DB_PASS}
      - DB_HOST=${DB_HOST}
      - DB_SOCKET=${DB_SOCKET}
    volumes:
      - ..:/app
