Skip to content

Commit

Permalink
Improve caddy setup
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteinLTU committed Jul 1, 2024
1 parent 21b7cef commit e7f4352
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions Caddyfile.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
EXTRA
}

DASH_IP.roboscapeonlineservers.netsblox.org {
EXTRA
reverse_proxy :15000
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-caddy
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM caddy:2-alpine

RUN apk add --no-cache curl
RUN apk add --no-cache curl nss-tools openssl

COPY update_caddyfile.sh .
COPY Caddyfile.template .
Expand Down
13 changes: 11 additions & 2 deletions update_caddyfile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
echo "Updating Caddyfile"

# Get the current IP address in the DASH_IP format
DASH_IP="`curl -s http://checkip.amazonaws.com | tr . -`"

Expand All @@ -13,8 +15,15 @@ if [[ -n "$CERT" && -n "$KEY" ]]; then
echo "$CERT" | base64 -d > cert.pem
echo "$KEY" | base64 -d > key.pem

# Replace the placeholder with TLS configuration
sed -i -e "s/EXTRA/tls cert.pem key.pem/" Caddyfile
# Verify the certificate is still valid
EXPIRY_DATE=`openssl x509 -enddate -noout -in cert.pem | cut -d= -f2 | sed 's/ GMT//g'`
if [[ `date -d "$EXPIRY_DATE" +%s` -lt `date +%s` ]]; then
echo "Certificate has expired"
sed -i -e "s/EXTRA//" Caddyfile
else
# Replace the placeholder with TLS configuration
sed -i -e "s/EXTRA/tls cert.pem key.pem/" Caddyfile
fi
else
# Replace the placeholder with no TLS configuration
sed -i -e "s/EXTRA//" Caddyfile
Expand Down

0 comments on commit e7f4352

Please sign in to comment.