Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit ac9f8bb

Browse files
author
@_sopitz
committed
Merge branch 'release/1.1.0'
2 parents dcec464 + e6413e1 commit ac9f8bb

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ That's about it already. If you want to run it without `docker-compose` it would
1616
### Configuration
1717
You can configure the email address that should be used for certificate generation with letsencrypt with the environment variable `LETSENCRYPT_EMAIL`. If you do not set it, the email address will defaul to `info@VIRTUAL_HOST`.
1818

19+
If you don't want SSL support for a certain container you can now add a label to prevent certificate generation: `letsencrypt.nocert`. The value you assign is not checked right now. Only the existence of the label is enough to exclude for certificate generation. That's how it would look like with a run command: `docker run -tid --label letsencrypt.nocert=true -e VIRTUAL_HOST=<your_domain> ubuntu`
20+
1921
If there's anything else you want to configure. Please also have a look at [jwilder/nginx-proxy](https://github.com/jwilder/nginx-proxy/). There you'll find more beautiful documentation on how to do more magic with this reverse proxy.
2022

2123
### How does it work?
2224
We use [Let's Encrypt](https://letsencrypt.org/) to generate the SSL certificates. Those certificates are free and expire every 3 months.
2325
We use [docker-gen](https://github.com/jwilder/docker-gen) to watch for starting containers and generate a shell-script that will run [Let's Encrypt](https://letsencrypt.org/). This will give you a SSL certificate in a matter of a couple of seconds. (So please don't worry when the certificate won't show up right after you start the container for the first time!). We use the `--keep-until-expiring` flag so you hopefully don't run into [beta restrictions](https://community.letsencrypt.org/t/public-beta-rate-limits/4772). That means the certificate will be renewed if it expires in 10 or less days automatically on container (re)start.
2426
Additional we have `cron` installed in the container to check regularly that your SSL certificates don't expire as you might not (re)start your containers every 3 months. That check will be performed at 10am. If you want to change that, just change it in the `cronfile`.
27+
28+
### Docker Tags
29+
`latest` is always taken from develop branch. Please do NOT consider it production ready. Use the versioned tags instead for production please!

ssl.tmpl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#!/bin/bash -e
22
mkdir -p /var/www/letsencrypt
33

4-
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
4+
{{ $optIn := contains $.Env "LETSENCRYPT_OPT_IN" }}
5+
{{ $optInContainers := whereLabelExists $ "letsencrypt.cert" }}
6+
{{ $optOutContainers := whereLabelDoesNotExist $ "letsencrypt.nocert" }}
7+
{{ $sslContainers := when $optIn $optInContainers $optOutContainers }}
58

6-
{{ if $.Env.LETSENCRYPT_EMAIL }}
7-
/letsencrypt/letsencrypt-auto certonly --email {{ $.Env.LETSENCRYPT_EMAIL }} --agree-tos --keep-until-expiring --webroot -w /var/www/letsencrypt -d {{ $host }}
8-
{{ else }}
9-
/letsencrypt/letsencrypt-auto certonly --email info@{{ $host }} --agree-tos --keep-until-expiring --webroot -w /var/www/letsencrypt -d {{ $host }}
10-
{{ end }}
11-
12-
ln -sf /etc/letsencrypt/live/{{ $host }}/fullchain.pem /etc/nginx/certs/{{ $host }}.crt
13-
ln -sf /etc/letsencrypt/live/{{ $host }}/privkey.pem /etc/nginx/certs/{{ $host }}.key
9+
{{ $containersForGeneration := groupByMulti $sslContainers "Env.VIRTUAL_HOST" "," }}
1410

15-
{{ end }}
11+
{{ range $containers := $containersForGeneration }}
12+
{{ range $container := $containers }}
13+
{{ if contains $container.Env "LETSENCRYPT_EMAIL" }}
14+
/letsencrypt/letsencrypt-auto certonly --email {{ $container.Env.LETSENCRYPT_EMAIL }} --agree-tos --keep-until-expiring --webroot -w /var/www/letsencrypt -d {{ $container.Env.VIRTUAL_HOST }}
15+
{{ else }}
16+
/letsencrypt/letsencrypt-auto certonly --email info@{{ $container.Env.VIRTUAL_HOST }} --agree-tos --keep-until-expiring --webroot -w /var/www/letsencrypt -d {{ $container.Env.VIRTUAL_HOST }}
17+
{{ end }}
18+
19+
ln -sf /etc/letsencrypt/live/{{ $container.Env.VIRTUAL_HOST }}/fullchain.pem /etc/nginx/certs/{{ $container.Env.VIRTUAL_HOST }}.crt
20+
ln -sf /etc/letsencrypt/live/{{ $container.Env.VIRTUAL_HOST }}/privkey.pem /etc/nginx/certs/{{ $container.Env.VIRTUAL_HOST }}.key
1621

22+
{{ end }}
23+
{{ end }}
1724
docker-gen -only-exposed -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf

0 commit comments

Comments
 (0)