# Usage:
# docker compose --env-file env/<mode> run <args> news_fetch && docker-compose --env-file env/production down

version: "3.9"

services:

  geckodriver:
    image: selenium/standalone-firefox:103.0
    volumes:
      - ${XSOCK-/dev/null}:${XSOCK-/tmp/sock}
      - ${XAUTHORITY-/dev/null}:/home/auto_news/.Xauthority
    environment:
      - DISPLAY=$DISPLAY
      - START_VNC=false
      - START_XVFB=false
    user: 1001:1001
    expose: # exposed to other docker-compose services only
    - "4444"


  vpn:
    image: wazum/openconnect-proxy:latest
    env_file:
      - ${CONTAINER_DATA}/config/vpn.config
    cap_add:
    - NET_ADMIN
    volumes:
      - /dev/net/tun:/dev/net/tun
    # alternative to cap_add & volumes: specify privileged: true


  nas_sync:
    depends_on:
      - vpn # used to establish a connection to the SMB server
    network_mode: "service:vpn"
    build: nas_sync
    image: nas_sync:latest
    cap_add: # capabilities needed for mounting the SMB share
      - SYS_ADMIN
      - DAC_READ_SEARCH
    volumes:
      - ${CONTAINER_DATA}/files:/sync/local_files
      - ${CONTAINER_DATA}/config/nas_sync.config:/sync/nas_sync.config
      - ${CONTAINER_DATA}/config/nas_login.config:/sync/nas_login.config
    command: 
      - nas22.ethz.ch/gess_coss_1/helbing_support/Files RM/Archiving/TEST # first command is the target mount path
      - lsyncd
      - /sync/nas_sync.config


  news_fetch:
    build: news_fetch
    image: news_fetch:latest

    depends_on: # when using docker compose run news_fetch, the dependencies are started as well
      - nas_sync
      - geckodriver

    volumes:
      - ${CONTAINER_DATA}:/app/containerdata # always set
      - ${CODE:-/dev/null}:/code # not set in prod, defaults to /dev/null
    environment:
      - DEBUG=${DEBUG}
      - HEADLESS=${HEADLESS}
      - REDUCEDFETCH=${REDUCEDFETCH}
    entrypoint: ${ENTRYPOINT:-python3 runner.py} # by default launch workers as defined in the Dockerfile
    stdin_open: ${INTERACTIVE:-false} # docker run -i
    tty: ${INTERACTIVE:-false}        # docker run -t


  news_check:
    build: news_check
    image: news_check:latest

    volumes:
      - ${CONTAINER_DATA}:/app/containerdata # always set
      - ${CODE:-/dev/null}:/code # not set in prod, defaults to /dev/null

    ports:
      - 8080:80 # 80 inside container