version: '3.3'

services:
  db:
    build: mysql
    restart: always
    environment:
      - MYSQL_DATABASE=c_db_movies
      - MYSQL_USER=c_db_ro_user
      - MYSQL_PASSWORD=c_db_password_changed_on_remote
      - MYSQL_ROOT_PASSWORD=c_db_root_password_changed_on_remote
    networks:
      - no-internet
    volumes:
      - './dbdata:/var/lib/mysql'
    #   uncomment to deploy new sql migration scripts without rebuilding the container
    #   all files should have 0644 permissions and folders 755 (umask 022)
    # - './mysql/initdb.d/:/docker-entrypoint-initdb.d/'

  redis:
    build: redis_server
    restart: always
    networks:
      - no-internet
    environment:
      - REDIS_PASSWORD=redis_password_changed_on_remote

  spring:
    build: viewer
    restart: always
    command: sh -c '/wait && java -jar /viewer.jar'
    environment:
      - DB_USERNAME=c_db_ro_user
      - DB_HOST=db
      - DB_NAME=c_db_movies
      - DB_USER=c_db_ro_user
      - DB_PASSWORD=c_db_password_changed_on_remote
      - REDIS_HOST=redis
      - REDIS_PASSWORD=redis_password_changed_on_remote
      - WAIT_HOSTS=db:3306
      - WAIT_BEFORE=4
      - WAIT_TIMEOUT=300
      - WAIT_HOST_CONNECT_TIMEOUT=20
    #   The Apparmor profile requires to be loaded manually on a VM by running
    #     apparmor_parser -r -W profiles/docker-custom
    #   Once loaded, uncomment the following lines:
    # security_opt:
    #  - apparmor=docker-custom
    depends_on:
      - db
      - redis
    networks:
      - no-internet
    #   uncomment to deploy new viewer.jar versions without rebuilding the container
    #   ./viewer/viewer.jar should have 0644 permissions
    # volumes:
    # - './viewer/viewer.jar:/viewer.jar:ro'

  proxy:
    image: nginx:alpine
    restart: always
    volumes:
      - './proxy/nginx.conf:/etc/nginx/nginx.conf:ro'
    depends_on:
      - spring
    ports:
      - '8080:80'
    networks:
      - internet
      - no-internet

networks:
  internet:
    driver: bridge
  no-internet:
    driver: bridge
    internal: true
