version: "3.9"

services:
  xweb:
    build: .
    container_name: xweb
    environment:
      LOG_CSV: /app/data/logs.csv
      BASIC_AUTH_USER: admin
      BASIC_AUTH_PASS: supersecret123
      FLASK_ENV: production
    volumes:
      - ./data:/app/data:rw
    expose:
      - "8080"
    restart: unless-stopped

  nginx:
    image: nginx:latest
    container_name: nginx
    depends_on:
      - xweb
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./certbot/conf:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
    ports:
      - "80:80"
      - "443:443"
    restart: unless-stopped

  certbot:
    image: certbot/certbot
    container_name: certbot
    volumes:
      - ./certbot/conf:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
    entrypoint: >
      sh -c "trap exit TERM;
      while :; do
        certbot renew --webroot -w /var/www/certbot;
        sleep 12h & wait $${!};
      done"
