Skip to content

Instantly share code, notes, and snippets.

@mugifly
Last active May 15, 2016 12:33
Show Gist options
  • Save mugifly/1d96e23a9bae768e23a1d9f3992f85a1 to your computer and use it in GitHub Desktop.
Save mugifly/1d96e23a9bae768e23a1d9f3992f85a1 to your computer and use it in GitHub Desktop.
Setup Script for the Let's Encrypt Certificate to Dokku apps
#!/bin/bash
# Setting Script for Let's Encrypt Certificate for Dokku apps
# Path of Let's Encrypt command
PATH_LE="/root/letsencrypt/"
# Base domain of dokku apps
DOKKU_BASE_DOMAIN="example.com"
# App names
DOKKU_APP_NAMES="foo bar"
# ----
set -e
# Make a single certificate file for apps
echo "Making a certificate file for apps..."
le_opts=""
for app_name in $(echo $DOKKU_APP_NAMES); do
le_opts="${le_opts} -d ${app_name}.${DOKKU_BASE_DOMAIN}"
done
"${PATH_LE}/letsencrypt-auto" certonly -a standalone --non-interactive --keep-until-expiring --expand -d $DOKKU_BASE_DOMAIN $le_opts
echo ""
# Make a tar archive for the dokku certs command
echo "Making a tar archive for the dokku certs command"
cp "/etc/letsencrypt/live/${DOKKU_BASE_DOMAIN}/fullchain.pem" /tmp/server.crt
cp "/etc/letsencrypt/live/${DOKKU_BASE_DOMAIN}/privkey.pem" /tmp/server.key
tar cvf cert-key.tar /tmp/server.crt /tmp/server.key
echo ""
# Iterate the each app
for app_name in $(echo $DOKKU_APP_NAMES); do
echo "----- ${app_name} -----"
# Check whether the app is available
dokku config "${app_name}" > /dev/null && :
if [ "$?" -ne 0 ] ; then
echo -e "Skip - ${app_name} is not found\n"
continue
fi
# Apply the certificate
echo "Applying the certificate for this app..."
dokku certs:add "${app_name}" < cert-key.tar
echo ""
done
echo "Done."
exit 0
@mugifly
Copy link
Author

mugifly commented May 15, 2016

We also propose to another way. It is to use the Let's Encrypt Plugin of dokku (https://github.com/dokku/dokku-letsencrypt).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment