-
Notifications
You must be signed in to change notification settings - Fork 25
Remove example, make Nginx config extensible, simplify configurations #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c4a4ed6
602e0b5
24ed42d
80300a2
a70f486
f7a8a63
3789a55
4eb70c0
06491cb
15fc76d
ac6aeea
faf5c39
855c6bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
SERVICE_NAME=${SERVICE_NAME:-nginx} | ||
CONSUL=${CONSUL:-consul} | ||
CERT_DIR="/var/www/ssl" | ||
|
||
# Determine whether ACME SSL certificates have been acquired | ||
SSL_READY="false" | ||
if [ -f ${CERT_DIR}/fullchain.pem -a -f ${CERT_DIR}/privkey.pem ]; then | ||
export SSL_READY="true" | ||
fi | ||
|
||
# Generate a conf.d config file for every corresponding cond.d Consul template | ||
for f in $(ls -1 /etc/nginx/templates/conf.d/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if you missed it in the consul-template docs but we can render multiple files from a single invocation, which should reduce the number of API calls to Consul. Their example is as follows:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the 2nd block to use this approach, as there's a static list of files there. For the first block, the files would primarily be user supplied, so we need to loop over the list. |
||
do | ||
consul-template \ | ||
-once \ | ||
-dedup \ | ||
-consul ${CONSUL}:8500 \ | ||
-template "/etc/nginx/templates/conf.d/${f}:/etc/nginx/conf.d/${f}" | ||
done | ||
|
||
# Render Nginx configuration template using values from Consul | ||
consul-template \ | ||
-once \ | ||
-dedup \ | ||
-consul ${CONSUL}:8500 \ | ||
-template "/etc/nginx/templates/health.conf:/etc/nginx/health.conf" \ | ||
-template "/etc/nginx/templates/ssl.conf:/etc/nginx/ssl.conf" \ | ||
-template "/etc/nginx/templates/nginx.conf:/etc/nginx/nginx.conf" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
LE_STAGING_CACERT=/etc/acme/ca/lets-encrypt-staging.crt | ||
ACME_ENV=${ACME_ENV:-staging} | ||
|
||
SCHEME=$1 | ||
|
||
if [[ $SCHEME == "https" ]]; then | ||
grep -q $ACME_DOMAIN /etc/hosts || printf "\n\n127.0.0.1 ${ACME_DOMAIN}\n" >> /etc/hosts | ||
if [[ "$ACME_ENV" == "staging" ]]; then | ||
curl --cacert $LE_STAGING_CACERT -fsSo /dev/null "https://${ACME_DOMAIN}/nginx-health" | ||
else | ||
curl -fsSo /dev/null "https://${ACME_DOMAIN}/nginx-health" | ||
fi | ||
else | ||
curl -fsSo /dev/null "http://localhost/nginx-health" | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
generate-config | ||
nginx -s reload |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIFATCCAumgAwIBAgIRAKc9ZKBASymy5TLOEp57N98wDQYJKoZIhvcNAQELBQAw | ||
GjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMB4XDTE2MDMyMzIyNTM0NloXDTM2 | ||
MDMyMzIyNTM0NlowGjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMIICIjANBgkq | ||
hkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA+pYHvQw5iU3v2b3iNuYNKYgsWD6KU7aJ | ||
diddtZQxSWYzUI3U0I1UsRPTxnhTifs/M9NW4ZlV13ZfB7APwC8oqKOIiwo7IwlP | ||
xg0VKgyz+kT8RJfYr66PPIYP0fpTeu42LpMJ+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KMbsf6QdBcTjhvfZyMIpBRkTe3zuHd2feKzY9lEkbRvRQ | ||
zbh4Ps5YBnG6CKJPTbe2hfi3nhnw/MyEmF3zb0hzvLWNrR9XW3ibb2oL3424XOwc | ||
VjrTSCLzO9Rv6s5wi03qoWvKAQQAElqTYRHhynJ3w6wuvKYF5zcZF3MDnrVGLbh1 | ||
Q9ePRFBCiXOQ6wPLoUhrrbZ8LpFUFYDXHMtYM7P9sc9IAWoONXREJaO08zgFtMp4 | ||
8iyIYUyQAbsvx8oD2M8kRvrIRSrRJSl6L957b4AFiLIQ/GgV2curs0jje7Edx34c | ||
idWw1VrejtwclobqNMVtG3EiPUIpJGpbMcJgbiLSmKkrvQtGng== | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
{ | ||
"consul": "{{ if .CONSUL_AGENT }}localhost{{ else }}{{ if .CONSUL }}{{ .CONSUL }}{{ else }}consul{{ end }}{{ end }}:8500", | ||
"preStart": "/usr/local/bin/reload.sh preStart", | ||
"logging": {"level": "DEBUG"}, | ||
"preStart": "generate-config", | ||
"services": [ | ||
{ | ||
"name": "nginx", | ||
"port": 80, | ||
"health": "/usr/bin/curl --fail --silent --show-error --output /dev/null http://localhost/nginx-health", | ||
"health": "health-check http", | ||
"poll": 10, | ||
"ttl": 25, | ||
"interfaces": ["eth0"] | ||
}, | ||
{ | ||
"name": "nginx-public", | ||
"port": 80, | ||
"health": "/usr/bin/curl --fail --silent --show-error --output /dev/null http://localhost/nginx-health", | ||
"health": "health-check http", | ||
"poll": 10, | ||
"ttl": 25, | ||
"interfaces": ["eth1", "eth0"] | ||
}{{ if .ACME_DOMAIN }}, | ||
{ | ||
"name": "nginx-ssl", | ||
"port": 443, | ||
"health": "acme init && health-check https", | ||
"poll": 10, | ||
"ttl": 25, | ||
"interfaces": ["eth0"] | ||
}, | ||
{ | ||
"name": "nginx-public-ssl", | ||
"port": 443, | ||
"health": "/usr/local/bin/acme init && /usr/bin/curl --insecure --fail --silent --show-error --output /dev/null --header \"HOST: {{ .ACME_DOMAIN }}\" https://localhost/nginx-health", | ||
"health": "health-check https", | ||
"poll": 10, | ||
"ttl": 25, | ||
"interfaces": ["eth1", "eth0"] | ||
}{{ end }} | ||
], | ||
"backends": [ | ||
{ | ||
"name": "{{ .BACKEND }}", | ||
"poll": 7, | ||
"onChange": "/usr/local/bin/reload.sh" | ||
} | ||
], | ||
"coprocesses": [{{ if .CONSUL_AGENT }} | ||
{ | ||
"command": ["/usr/local/bin/consul", "agent", | ||
"command": ["consul", "agent", | ||
"-data-dir=/var/lib/consul", | ||
"-config-dir=/etc/consul", | ||
"-rejoin", | ||
|
@@ -49,9 +49,7 @@ | |
{{ if and .CONSUL_AGENT .ACME_DOMAIN }},{{ end }} | ||
{{ if .ACME_DOMAIN }} | ||
{ | ||
"command": ["/usr/local/bin/consul-template", | ||
"-config", "/etc/acme/watch.hcl", | ||
"-consul", "{{ if .CONSUL_AGENT }}localhost{{ else }}{{ if .CONSUL }}{{ .CONSUL }}{{ else }}consul{{ end }}{{ end }}:8500"], | ||
"command": ["acme", "watch"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We certainly can. I just did it this way so that all the moving parts related to certificate acquisition was contained within the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that's totally reasonable. Let's keep it as you've got it here. |
||
"restarts": "unlimited" | ||
}{{ end }}], | ||
"telemetry": { | ||
|
@@ -62,35 +60,22 @@ | |
"help": "Number of accepted connnections that were not handled", | ||
"type": "gauge", | ||
"poll": 5, | ||
"check": ["/usr/local/bin/sensor.sh", "unhandled"] | ||
"check": ["sensor", "unhandled"] | ||
}, | ||
{ | ||
"name": "nginx_connections_load", | ||
"help": "Ratio of active connections (less waiting) to the maximum worker connections", | ||
"type": "gauge", | ||
"poll": 5, | ||
"check": ["/usr/local/bin/sensor.sh", "connections_load"] | ||
"check": ["sensor", "connections_load"] | ||
} | ||
] | ||
}, | ||
"tasks": [{{ if .ACME_DOMAIN }} | ||
{ | ||
"name": "acme-checkin", | ||
"command": [ "/usr/local/bin/acme", "checkin" ], | ||
"frequency": "5m", | ||
"command": [ "acme", "checkin" ], | ||
"frequency": "1h", | ||
"timeout": "10s" | ||
}, | ||
{ | ||
"name": "acme-renew-certs", | ||
"command": [ "/usr/local/bin/acme", "renew-certs" ], | ||
"frequency": "12h", | ||
"timeout": "10m" | ||
}, | ||
{ | ||
"name": "clean-unused-certs", | ||
"command": ["/usr/local/bin/acme", "clean-certs" ], | ||
"frequency": "24h", | ||
"timeout": "10m" | ||
}{{ end }} | ||
] | ||
}{{ end }}] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we're doing an update we might consider tossing in ContainerPilot 2.4.4 which reduces some log spam.