Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (20 sloc) 1.18 KB
#!/bin/bash -e
mkdir -p /var/www/letsencrypt
{{ $optIn := contains $.Env "LETSENCRYPT_OPT_IN" }}
{{ $optInContainers := whereLabelExists $ "letsencrypt.cert" }}
{{ $optOutContainers := whereLabelDoesNotExist $ "letsencrypt.nocert" }}
{{ $sslContainers := when $optIn $optInContainers $optOutContainers }}
{{ range $host, $containers := groupByMulti $sslContainers "Env.VIRTUAL_HOST" "," }}
{{ range $container := $containers }}
#### begin {{ $host }} ####
{{ if contains $container.Env "LETSENCRYPT_EMAIL" }}
/certbot/certbot-auto certonly -n -t --email {{ $container.Env.LETSENCRYPT_EMAIL }} --agree-tos --keep-until-expiring --webroot -w /var/www/letsencrypt -d {{ $host }}
{{ else }}
/certbot/certbot-auto certonly -n -t --email info@{{ $host }} --agree-tos --keep-until-expiring --webroot -w /var/www/letsencrypt -d {{ $host }}
{{ end }}
ln -sf /etc/letsencrypt/live/{{ $host }}/fullchain.pem /etc/nginx/certs/{{ $host }}.crt
ln -sf /etc/letsencrypt/live/{{ $host }}/privkey.pem /etc/nginx/certs/{{ $host }}.key
#### end {{ $host }} ####
{{ end }}
{{ end }}
docker-gen -only-exposed -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf