services:

  # Nginx server configuration
  web1:
    image: nginx:1.17
    #container_name: webserver
    container_name: reco-$RECO_TYPE-web1
    restart: unless-stopped
    depends_on:
      - db
      - php1
    links:
      - db
      - php1
    volumes:
      - ./web:/var/www/html/recomedcloud
      - ./devops/nginx1:/etc/nginx/conf.d/
    ports:
      - "3333:80"
    environment:
      - NGINX_HOST=reco-medcloud.com
      - NGINX_PORT=80

  # Php-fpm configuration
  php1:
    build:
      context: .
      dockerfile: ./Dockerfile
    image: php:8.3-fpm
    container_name: reco-$RECO_TYPE-php1
    restart: unless-stopped
    links:
      - db
    volumes:
      - ./web:/var/www/html/recomedcloud
      - ./uploads:/var/www/html/recomedcloud/uploads
      - ./devops/php-test.ini:/usr/local/etc/php/php.ini
      - ./logs:/home/logs
      - /tmp/backups:/home/backups
    environment:
      - RECO_MED_SEND_GRID_KEY=$RECO_MED_SEND_GRID_KEY
      - RECO_LOGO_SEND_GRID_KEY=$RECO_LOGO_SEND_GRID_KEY
      - RECO_MED_SES_ACCESS_KEY=$RECO_MED_SES_ACCESS_KEY
      - RECO_MED_SES_SECRET_KEY=$RECO_MED_SES_SECRET_KEY
      - RECO_LOGO_SES_ACCESS_KEY=$RECO_LOGO_SES_ACCESS_KEY
      - RECO_LOGO_SES_SECRET_KEY=$RECO_LOGO_SES_SECRET_KEY
      - RECO_MED_SMTP_HOST=$RECO_MED_SMTP_HOST
      - RECO_MED_SMTP_PORT=$RECO_MED_SMTP_PORT
      - RECO_MED_SMTP_SSL=$RECO_MED_SMTP_SSL
      - RECO_MED_SMTP_TLS=$RECO_MED_SMTP_TLS
      - RECO_MED_SMTP_USER=$RECO_MED_SMTP_USER
      - RECO_MED_SMTP_PASSWORD=$RECO_MED_SMTP_PASSWORD
      - RECO_LOGO_SMTP_HOST=$RECO_LOGO_SMTP_HOST
      - RECO_LOGO_SMTP_PORT=$RECO_LOGO_SMTP_PORT
      - RECO_LOGO_SMTP_SSL=$RECO_LOGO_SMTP_SSL
      - RECO_LOGO_SMTP_TLS=$RECO_LOGO_SMTP_TLS
      - RECO_LOGO_SMTP_USER=$RECO_LOGO_SMTP_USER
      - RECO_LOGO_SMTP_PASSWORD=$RECO_LOGO_SMTP_PASSWORD
      - SENTRY_DSN_MED=$SENTRY_DSN_MED
      - SENTRY_DSN_LOGO=$SENTRY_DSN_LOGO
      - MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
      - MYSQL_HOST=$MYSQL_HOST
      - MYSQL_USER=$MYSQL_USER
      - MYSQL_PASSWORD=$MYSQL_PASSWORD
      - MYSQL_DATABASE=$MYSQL_DATABASE
      - ENVIRONMENT=$ENVIRONMENT
      - BASE_URL=$BASE_URL
      - DOPPLER_CONFIG=$DOPPLER_CONFIG
      - DOPPLER_ENVIRONMENT=DOPPLER_ENVIRONMENT
      - DOPPLER_PROJECT=$DOPPLER_PROJECT
      - RECO_TYPE=$RECO_TYPE
      - SKIP_RECAPTCHA=$SKIP_RECAPTCHA
      - SKIP_COOKIE_BANNER=$SKIP_COOKIE_BANNER
      - AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
      - AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
      - AWS_REGION=$AWS_REGION
      - S3_BUCKET_NAME=$S3_BUCKET_NAME
      - GOOGLE_MAPS_KEY=$GOOGLE_MAPS_KEY
      - GOOGLE_SECRET=$GOOGLE_SECRET
      - DB_SESSIONS=$DB_SESSIONS

  # Mysql configuration
  db:
    image: mysql:8.4.2
    #image: mariadb
    #container_name: db
    container_name: reco-$RECO_TYPE-db
    restart: unless-stopped
    command: [ "--lower_case_table_names=1", "--innodb_page_size=64k", "--innodb_log_buffer_size=32M", "--innodb_buffer_pool_size=512M", "--sql_mode=NO_ENGINE_SUBSTITUTION" ]
    environment:
      #   - MYSQL_DATABASE=dedrhimy_recohelp
      #   - MYSQL_ALLOW_EMPTY_PASSWORD=true
      - MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
      - MYSQL_USER=$MYSQL_USER
      - MYSQL_PASSWORD=$MYSQL_PASSWORD
      - MYSQL_HOST=$MYSQL_HOST
      - MYSQL_DATABASE=$MYSQL_DATABASE
    #   - MYSQL_USER=tycho
    #   - MYSQL_PASSWORD=tycho
    ports:
      - "${LOCAL_IP}:3334:3306"
    volumes:
      - ./dbdata:/var/lib/mysql

  cron:
    image: ubuntu:20.04
    container_name: reco-${RECO_TYPE}-cron
    volumes:
      - ./devops/crontab:/etc/cron.d/reco-cron
    environment:
      - TZ=UTC
    command: >
      bash -c " apt-get update && apt-get install -y cron wget tzdata && chmod 0644 /etc/cron.d/reco-cron && crontab /etc/cron.d/reco-cron && touch /var/log/cron.log && (cron -f &) && tail -f /var/log/cron.log "
    restart: unless-stopped

  smtp-forwarder:
    build:
      context: .
      dockerfile: Dockerfile.smtp
    ports:
      - "${LOCAL_IP}:2525:25"
    container_name: reco-$RECO_TYPE-smtp
    environment:
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASSWORD=${SMTP_PASSWORD}
      - SMTP_ENCRYPTION=${SMTP_ENCRYPTION}
      - DAILY_RATE_LIMIT=${DAILY_RATE_LIMIT}
      - HOURLY_RATE_LIMIT=${HOURLY_RATE_LIMIT}
      - MONTHLY_RATE_LIMIT=${MONTHLY_RATE_LIMIT}
      - WARN_RATE=${WARN_RATE}
      - SENTRY_DSN=${SENTRY_DSN_MED}
      - BIND_ADDRESS=0.0.0.0
    restart: unless-stopped
