Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@mugifly 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
You can’t perform that action at this time.