Skip to content
This repository was archived by the owner on Feb 5, 2018. It is now read-only.

Commit 48a646f

Browse files
committed
Initial version
0 parents  commit 48a646f

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM phusion/baseimage:0.9.19
2+
MAINTAINER Arne Jørgensen
3+
4+
RUN set -x && \
5+
apt-get update && \
6+
DEBIAN_FRONTEND=noninteractive apt-get install -y -q golang-go git php-cli php-curl ruby && \
7+
GOPATH=/usr/local go get -u github.com/xenolf/lego && \
8+
curl -sS https://platform.sh/cli/installer | php && \
9+
curl -sS -o /opt/yamledit.rb https://raw.githubusercontent.com/dbrandenburg/yamledit/master/yamledit.rb && \
10+
DEBIAN_FRONTEND=noninteractive apt-get purge -y -q golang-go && \
11+
apt-get clean -y -q && \
12+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
13+
14+
ENV PATH=/root/.platformsh/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
15+
16+
COPY etc/ /etc/
17+
COPY usr/ /usr/
18+
VOLUME [ "/data" ]

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Let's Encrypt with DNS challenge on platform.sh
2+
3+
[Platform.sh](https://platform.sh) currently doesn't support using
4+
Let's Encrypt certificates (at least not with domain verification and
5+
automatic renewal).
6+
7+
This image uses [lego](https://github.com/xenolf/lego) to obtain a
8+
certificate via Let's Encrypts DNS challenge and uploads the
9+
certificate to platform.sh using their commmand line client.
10+
11+
Experimental. YMMV.
12+
13+
Necessary configuration via environment variables, .i.e.:
14+
15+
* `[email protected]` (used for registering with Let's Encrypt)
16+
* `DOMAINS="example.com www.example.com"` (space separated list --
17+
must already be added to the project at Platform.sh)
18+
* `DNS_PROVIDER=dnsimple` (your DNS provider, see below for supported
19+
providers and additional needed configuration)
20+
* `PLATFORMSH_API_TOKEN=mytoken` (an APIv1 token)
21+
* `PLATFORMSH_PROJECT_ID=myprojectid`
22+
23+
24+
You also need to provide environment variables required by the DNS provider challenge chosen:
25+
26+
* cloudflare: `CLOUDFLARE_EMAIL`, `CLOUDFLARE_API_KEY`
27+
* digitalocean: `DO_AUTH_TOKEN`
28+
* dnsimple: `DNSIMPLE_EMAIL`, `DNSIMPLE_API_KEY`
29+
* dnsmadeeasy: `DNSMADEEASY_API_KEY`, `DNSMADEEASY_API_SECRET`
30+
* gandi: `GANDI_API_KEY`
31+
* gcloud: `GCE_PROJECT`
32+
* namecheap: `NAMECHEAP_API_USER`, `NAMECHEAP_API_KEY`
33+
* rfc2136: `RFC2136_TSIG_KEY`, `RFC2136_TSIG_SECRET`, `RFC2136_TSIG_ALGORITHM`, `RFC2136_NAMESERVER`
34+
* route53: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`
35+
* dyn: `DYN_CUSTOMER_NAME`, `DYN_USER_NAME`, `DYN_PASSWORD`
36+
* vultr: `VULTR_API_KEY`
37+
* ovh: `OVH_ENDPOINT`, `OVH_APPLICATION_KEY`, `OVH_APPLICATION_SECRET`, `OVH_CONSUMER_KEY`
38+
* pdns: `PDNS_API_KEY`, `PDNS_API_URL`
39+
40+
Optional configuration via environment variables:
41+
42+
```
43+
SERVER=https://acme-staging.api.letsencrypt.org/directory
44+
```

etc/cron.daily/100-lego-platform

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec /usr/local/bin/lego-platform.sh
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
TOKEN_FILE=$(mktemp -p /opt)
4+
echo "${PLATFORMSH_API_TOKEN}" > "${TOKEN_FILE}"
5+
/usr/bin/ruby /opt/yamledit.rb -f /root/.platformsh/config.yaml -n -k api,token_file -v "${TOKEN_FILE}" --force

etc/my_init.d/200-lego-platform

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
exec /usr/local/bin/lego-platform.sh

usr/local/bin/lego-platform.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
set +x
4+
5+
. /etc/container_environment.sh
6+
7+
IFS=' ' read -r -a domains <<< "${DOMAINS}"
8+
LEGOPATH=/data
9+
export HOME=/root
10+
SERVER=${SERVER:-https://acme-v01.api.letsencrypt.org/directory}
11+
12+
verify_preconditions () {
13+
[ ! -z "${SERVER}" ] && [ ! -z "${EMAIL}" ] && [ ! -z "${DNS_PROVIDER}" ] && verify_domains_in_platformsh
14+
}
15+
16+
verify_domains_in_platformsh () {
17+
local status=0
18+
19+
for i in "${!domains[@]}"
20+
do
21+
platform domain:get --yes --project="${PLATFORMSH_PROJECT_ID}" "${domains[i]}"
22+
local err=$?
23+
status=$((${err}|${status}))
24+
done
25+
26+
return ${status}
27+
}
28+
29+
create_or_renew_domains () {
30+
for i in "${!domains[@]}"
31+
do
32+
if $(domain_exists "${domains[i]}")
33+
then
34+
renew_domain "${domains[i]}"
35+
else
36+
create_domain "${domains[i]}"
37+
fi
38+
done
39+
}
40+
41+
domain_exists () {
42+
local domain=$1
43+
[ -e "${LEGOPATH}/certificates/${domain}.crt" ]
44+
}
45+
46+
create_domain () {
47+
local domain=$1
48+
lego --domains=${domain} --server=${SERVER} --email=${EMAIL} --accept-tos --path=${LEGOPATH} --dns=${DNS_PROVIDER} run
49+
}
50+
51+
renew_domain () {
52+
local domain=$1
53+
lego --domains=${domain} --server=${SERVER} --email=${EMAIL} --accept-tos --path=${LEGOPATH} --dns=${DNS_PROVIDER} renew --days=60
54+
}
55+
56+
upload_certificates () {
57+
for i in "${!domains[@]}"
58+
do
59+
upload_certificate "${domains[i]}"
60+
done
61+
}
62+
63+
upload_certificate () {
64+
local domain=$1
65+
local cert=${LEGOPATH}/certificates/${domain}.crt
66+
local key=${LEGOPATH}/certificates/${domain}.key
67+
local chain=${LEGOPATH}/certificates/${domain}.crt
68+
platform domain:update --yes --cert=${cert} --key=${key} --chain=${chain} --project="${PLATFORMSH_PROJECT_ID}" "${domain}"
69+
}
70+
71+
verify_preconditions && create_or_renew_domains && upload_certificates

0 commit comments

Comments
 (0)