version: '3.8'

services:
  elemes:
    build: .
    volumes:
      - ../content:/app/content
      - ../tokens_siswa.csv:/app/tokens.csv
      - ../assets:/app/assets
    env_file:
      - ../.env

    # production
    command: gunicorn --config gunicorn.conf.py "app:create_app()"

    # debug
    # command: python app.py

  elemes-frontend:
    build: ./frontend
    # ports:
    #  - 3000:3000
    environment:
      - ORIGIN=http://localhost:3000
      - API_BACKEND=http://elemes:5000
      - PUBLIC_APP_BAR_TITLE=${APP_BAR_TITLE}
      - PUBLIC_COPYRIGHT_TEXT=${COPYRIGHT_TEXT}
      - PUBLIC_PAGE_TITLE_SUFFIX=${PAGE_TITLE_SUFFIX}
      - PUBLIC_CURSOR_OFFSET_Y=${CURSOR_OFFSET_Y:-50}
    depends_on:
      - elemes

  velxio:
    # image: ghcr.io/a2nr/velxio-elemes:latest
    build:
      context: ./velxio
      dockerfile: Dockerfile.standalone
      args:
        VITE_BASE_PATH: /velxio/
        VITE_API_BASE: /velxio/api
    environment:
      - SECRET_KEY=embed-only-no-auth-needed
      - DATABASE_URL=sqlite+aiosqlite:////app/data/velxio.db
      - DATA_DIR=/app/data
    volumes:
      - velxio-data:/app/data
      - velxio-arduino-libs:/root/.arduino15

  elemes-ts:
    image: docker.io/tailscale/tailscale:latest
    hostname: ${ELEMES_HOST}
    environment:
      - TS_AUTHKEY=${TS_AUTHKEY}
      - TS_SERVE_CONFIG=/config/sinau-c-tail.json
      - TS_STATE_DIR=/var/lib/tailscale
      - TS_USERSPACE=true
    volumes:
      - ../state:/var/lib/tailscale
      - ./config:/config
      - /dev/net/tun:/dev/net/tun
    cap_add:
      - net_admin
      - sys_module
    restart: unless-stopped
    depends_on:
      - elemes-frontend
    env_file:
      - ../.env

volumes:
  velxio-data:
  velxio-arduino-libs:

networks:
  main_network:
    drive: bridge
    network_mode: service:elemes-ts
