name: linux-counter
services:
  app:
    build: .
    environment:
      APP_MESSAGE: ${APP_MESSAGE:?Copy .env.example to .env and set APP_MESSAGE}
    ports:
      - "127.0.0.1:8080:8000"
    volumes:
      - app_data:/data
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"]
      interval: 5s
      timeout: 3s
      retries: 5
      start_period: 10s
    restart: unless-stopped
  caddy:
    image: caddy:2-alpine
    profiles: [https]
    environment:
      DOMAIN: ${DOMAIN:-localhost}
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      app:
        condition: service_healthy
    restart: unless-stopped
volumes:
  app_data:
  caddy_data:
  caddy_config:
