forked from open-forest/sendy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HAProxy to docker-compose to handle SSL termination. Additional…
… fixed to support SENDY_PROTOCOL environment variable.
- Loading branch information
1 parent
d1b3812
commit b5b69cf
Showing
10 changed files
with
241 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Application Load Balancer Dockerfile (Development Use Only) | ||
# | ||
# Build: | ||
# $ docker build -t lb_sendy -f haproxy/Dockerfile . | ||
# | ||
# Run: | ||
# $ docker run --rm -d -p 80:80 -p 443:443 lb_sendy | ||
|
||
FROM haproxy:2.1-alpine | ||
EXPOSE 80 443 | ||
|
||
COPY haproxy/haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg | ||
COPY haproxy/generateSSLCertificate.sh /usr/local/bin | ||
|
||
COPY haproxy/docker-entrypoint.sh / | ||
ENTRYPOINT ["/docker-entrypoint.sh"] | ||
CMD ["haproxy", "-f", "/usr/local/etc/haproxy/haproxy.cfg"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# if necessary, generate and install certificate. | ||
if [ ! -f "/etc/cert/server.pem" ]; then | ||
echo "Generating certificate for domain: $SENDY_FQDN" | ||
echo "Installing OpenSSL" | ||
apk --update-cache add openssl && \ | ||
rm -rf /var/cache/apk/* | ||
/usr/local/bin/generateSSLCertificate.sh $SENDY_FQDN | ||
else | ||
echo "Certificate exists for domain: $SENDY_FQDN" | ||
fi | ||
|
||
# first arg is `-f` or `--some-option` | ||
if [ "${1#-}" != "$1" ]; then | ||
set -- haproxy "$@" | ||
fi | ||
|
||
if [ "$1" = 'haproxy' ]; then | ||
shift # "haproxy" | ||
# if the user wants "haproxy", let's add a couple useful flags | ||
# -W -- "master-worker mode" (similar to the old "haproxy-systemd-wrapper"; allows for reload via "SIGUSR2") | ||
# -db -- disables background mode | ||
set -- haproxy -W -db "$@" | ||
fi | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
|
||
# Lifted from https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/ | ||
# Author: Brad Touesnard | ||
|
||
if [ "$#" -ne 1 ] | ||
then | ||
echo "Usage: Must supply a domain" | ||
exit 1 | ||
fi | ||
|
||
DOMAIN=$1 | ||
|
||
echo "Generating Development RootCA and SSL Certificate for: $DOMAIN" | ||
|
||
# create output directory | ||
mkdir /etc/cert | ||
|
||
# create temporary work directory | ||
mkdir /tmp/deleteme | ||
cd /tmp/deleteme | ||
|
||
# Create RootCA key and cert | ||
openssl genrsa -out rootCA.key 2048 | ||
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1825 \ | ||
-subj "/C=US/ST=CA/L=/O=/OU=/CN=rootCA-$DOMAIN" -out ./rootCA.crt | ||
|
||
|
||
|
||
# Create domain certificate signing request | ||
openssl genrsa -out server.key 2048 | ||
openssl req -new -key server.key -subj "/C=US/ST=CA/L=/O=/OU=/CN=$DOMAIN" -out server.csr | ||
|
||
cat > $DOMAIN.ext << EOF | ||
authorityKeyIdentifier=keyid,issuer | ||
basicConstraints=CA:FALSE | ||
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = $DOMAIN | ||
EOF | ||
|
||
openssl x509 -req -in server.csr -CA ./rootCA.crt -CAkey ./rootCA.key -CAcreateserial -days 825 -sha256 \ | ||
-extfile $DOMAIN.ext -out ./server.crt | ||
|
||
cat ./server.key ./server.crt > /etc/cert/server.pem | ||
cat ./rootCA.key ./rootCA.crt > /etc/cert/rootCA.pem | ||
|
||
cd / | ||
|
||
# remove temporary work directory | ||
rm -rf /tmp/deleteme | ||
|
||
echo "Development RootCA and SSL Certificate are located in /etc/cert/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
global | ||
maxconn 100 | ||
# Log to stdout at info level | ||
log stdout daemon info | ||
|
||
# SSL Params | ||
tune.ssl.default-dh-param 2048 | ||
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets | ||
|
||
|
||
defaults | ||
# Use Log settings from global section | ||
log global | ||
# HAProxy in HTTP mode | ||
mode http | ||
# Log standard http fields | ||
option httplog | ||
# Don't log null responses | ||
option dontlognull | ||
# Timeouts | ||
timeout connect 5s | ||
timeout client 30s | ||
timeout server 30s | ||
|
||
|
||
frontend nonSecureFrontend | ||
bind :80 | ||
# Redirect http to https | ||
redirect scheme https code 301 | ||
|
||
|
||
frontend secureFrontend | ||
# primary cert is /etc/cert/server.pem | ||
bind :443 ssl crt /etc/cert/server.pem | ||
|
||
# Add X-Forwarded-For and X-Forwarded-Port headers | ||
option forwardfor | ||
|
||
# All others use webBackend | ||
use_backend webBackend | ||
|
||
|
||
backend webBackend | ||
# Health checks using HTTP GET / and expects 200 OK response | ||
option httpchk GET / | ||
http-check expect status 200 | ||
# Health check interval 60sec, if server is down, check every 5secs, | ||
# Server is marked down after 12 failed attempts (eg 1min), | ||
# Server is healthly after 1 success response. | ||
server webApp1 sendy:80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SENDY_PROTOCOL=https | ||
# Update FQDN to match your Sendy licensed domain. | ||
SENDY_FQDN=campaigns.example.com | ||
MYSQL_HOST=db_sendy | ||
MYSQL_DATABASE=sendy | ||
MYSQL_USER=sendy | ||
MYSQL_PASSWORD_FILE=/run/secrets/db_password | ||
# MYSQL_PASSWORD=db_password | ||
|
||
# XDEBUG | ||
# REQUIRES BUILDING image with XDEBUG installed. | ||
# See Dockerfile header for details. | ||
|
||
# Uncomment to set XDEBUG enviorment configuration. Ensure `remote_port` does not have conflicts. | ||
#XDEBUG_CONFIG=remote_host=host.docker.internal remote_port=9000 remote_enable=1 remote_autostart=1 |