services:
  web:
    image: sheep-service/web
    build: ./web
    restart: always
    expose:
      - "4002"
    volumes:
      - "${CARDS_PATH:-./data}:/app/data/cards"
      - "${MAP_PATH:-./data}:/app/data/map"
    environment:
      - CARDS_PATH=/app/data/cards/
      - MAP_PATH=/app/data/map/
    networks:
      - network

  api:
    image: sheep-service/api
    build: ./api
    restart: always
    expose:
      - "4003"
    volumes:
      - "${DB_PATH:-./data}:/app/data"
      - "${CARDS_PATH:-./data}:/app/data/cards"
    environment:
      - DATABASE_PATH=/app/data/
      - CARDS_PATH=/app/data/cards/
      - PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
      - VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY}
      - VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY}
      - DOMAIN=${DOMAIN}
    shm_size: '1gb'
    networks:
      - network

  ws:
    image: sheep-service/ws
    build: ./ws
    restart: always
    expose:
      - "4004"
    volumes:
      - "${DB_PATH:-./data}:/app/data"
    environment:
      - DATABASE_PATH=/app/data/
    networks:
      - network

  nginx:
    image: nginx:latest
    restart: always
    ports:
      - "${HTTP_PORT}:80"
      - "${HTTPS_PORT}:443"
    volumes:
      - ./nginx/default.conf.template:/etc/nginx/templates/default.conf.template:ro
      - ./nginx/certs:/etc/letsencrypt/live
      - ./nginx/html:/usr/share/nginx/html
      - ./nginx/log:/var/log/nginx
    environment:
      - DOMAIN=${DOMAIN}
    command: /bin/sh -c "envsubst '\$DOMAIN' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
    networks:
      - network

volumes:
  data:

networks:
  network:
    driver: bridge