Browse Source

Initial version

master
Chris Smith 8 years ago
commit
d10c31733a
4 changed files with 126 additions and 0 deletions
  1. 18
    0
      Dockerfile
  2. 83
    0
      README.md
  3. 10
    0
      config.sh
  4. 15
    0
      run.sh

+ 18
- 0
Dockerfile View File

@@ -0,0 +1,18 @@
1
+FROM python:2.7
2
+MAINTAINER Chris Smith <chris87@gmail.com> 
3
+
4
+RUN pip install \
5
+      dns-lexicon==1.1.4
6
+
7
+RUN apt-get update \
8
+ && apt-get install -y inotify-tools
9
+
10
+ADD https://raw.githubusercontent.com/lukas2511/letsencrypt.sh/v0.1.0/letsencrypt.sh /letsencrypt.sh
11
+ADD https://raw.githubusercontent.com/AnalogJ/lexicon/v1.1.4/examples/letsencrypt.default.sh /lexicon.sh
12
+COPY run.sh config.sh /
13
+RUN chmod +x /run.sh /letsencrypt.sh /lexicon.sh
14
+
15
+VOLUME ["/letsencrypt/"]
16
+
17
+ENTRYPOINT ["/bin/bash"]
18
+CMD ["/run.sh"]

+ 83
- 0
README.md View File

@@ -0,0 +1,83 @@
1
+# Let's Encrypt Lexicon Service
2
+
3
+This container uses the awesome [Lexicon](https://github.com/AnalogJ/lexicon)
4
+library with [letsencrypt.sh](https://github.com/lukas2511/letsencrypt.sh) to
5
+automatically obtain SSL certs from [Let's Encrypt](https://letsencrypt.org/).
6
+
7
+Multiple domains, as well as SANs, are supported. Certificates will be
8
+renewed automatically, and obtained automatically as soon as new domains
9
+are added.
10
+
11
+## Usage
12
+
13
+### Defining domains
14
+
15
+The container defines one volume at `/letsencrypt`, and expects there to be
16
+a list of domains in `/letsencrypt/domains.txt`. Certificates are output to
17
+`/letsencrypt/certs/{domain}`.
18
+
19
+domains.txt should contain one line per certificate. If you want alternate
20
+names on the cert, these should be listed after the primary domain. e.g.
21
+
22
+```
23
+example.com www.example.com
24
+admin.example.com
25
+```
26
+
27
+This will request two certificates: one for example.com with a SAN of
28
+www.example.com, and a separate one for admin.example.com.
29
+
30
+The container uses inotify to monitor the domains.txt file for changes,
31
+so you can update it while the container is running and changes will be
32
+automatically applied.
33
+
34
+### DNS providers
35
+
36
+To verify that you own the domain, a TXT record needs to be automatically
37
+created for it. The Lexicon library handles this, and comes with support
38
+for a variety of providers including CloudFlare, EasyDNS, DigitalOcean and
39
+Vultr.
40
+
41
+Lexicon takes its configuration from environment variables. For full
42
+instructions, see its
43
+[README](https://github.com/AnalogJ/lexicon/blob/master/README.md).
44
+
45
+To configure Lexicon to update DNS hosted by CloudFlare, for example, you
46
+would pass in:
47
+
48
+```
49
+docker run ... \
50
+  -e "PROVIDER=cloudflare" \
51
+  -e "LEXICON_CLOUDFLARE_USERNAME=email@address.com" \
52
+  -e "LEXICON_CLOUDFLARE_TOKEN=api-key-here"
53
+```
54
+
55
+### Other configuration
56
+
57
+For testing purposes, you can set the `STAGING` environment variable to
58
+a non-empty value. This will use the Let's Encrypt staging server, which
59
+has much more relaxed limits.
60
+
61
+You should pass in a contact e-mail address by setting the `EMAIL` env var.
62
+This is passed on to Let's Encrypt, and may be used for important service
63
+announcements.
64
+
65
+### Running
66
+
67
+Here's a full worked example:
68
+
69
+```bash
70
+# The directory we'll use to store the domain list and certificates.
71
+# You could use a docker volume instead.
72
+mkdir /tmp/letsencrypt
73
+echo "domain.com www.domain.com" > /tmp/letsencrypt/domains.txt
74
+
75
+docker run -d --restart=always \
76
+  -e "EMAIL=admin@domain.com" \
77
+  -e "STAGING=true" \
78
+  -e "PROVIDER=cloudflare" \
79
+  -e "LEXICON_CLOUDFLARE_USERNAME=email@address.com" \
80
+  -e "LEXICON_CLOUDFLARE_TOKEN=api-key-here" \
81
+  -v /tmp/letsencrypt:/letsencrypt \
82
+  csmith/letsencrypt-lexicon:latest
83
+```

+ 10
- 0
config.sh View File

@@ -0,0 +1,10 @@
1
+#!/usr/bin/env bash
2
+
3
+BASEDIR=/letsencrypt
4
+CONTACT_EMAIL="$EMAIL"
5
+
6
+if [[ -z "${STAGING}" ]]; then
7
+  CA="https://acme-staging.api.letsencrypt.org/directory"
8
+else
9
+  CA="https://acme-v01.api.letsencrypt.org/directory"
10
+fi

+ 15
- 0
run.sh View File

@@ -0,0 +1,15 @@
1
+#!/usr/bin/env bash
2
+
3
+interrupt() {
4
+  echo
5
+  echo "Caught ^C, exiting."
6
+  exit 1
7
+}
8
+
9
+trap interrupt SIGINT
10
+
11
+while true; do
12
+  /letsencrypt.sh --cron --hook /lexicon.sh --challenge dns-01 
13
+  inotifywait --timeout 1440 /letsencrypt/domains.txt
14
+  sleep 60
15
+done

Loading…
Cancel
Save