version: '3.8'

services:
  certbot:
    image: certbot/certbot
    container_name: home-service-certbot-daemon
    restart: unless-stopped
    volumes:
      - ./ssl-certs:/etc/letsencrypt
      - ./certbot-webroot:/var/www/certbot
      - /var/run/docker.sock:/var/run/docker.sock
    # 12시간마다 갱신 체크 + 갱신 성공 시 Nginx 자동 리로드 (--post-hook)
    entrypoint: >
      /bin/sh -c ' apk add --no-cache docker-cli && trap exit TERM; while :; do
        certbot renew --webroot -w /var/www/certbot --post-hook "docker exec home-service-proxy-ssl nginx -s reload";
        sleep 12h & wait $${!};
      done;'
