Skip to content

Instantly share code, notes, and snippets.

@ggtools
Created February 13, 2017 06:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggtools/a6a963be12e91c690e804bbdd5d4c053 to your computer and use it in GitHub Desktop.
Save ggtools/a6a963be12e91c690e804bbdd5d4c053 to your computer and use it in GitHub Desktop.
Docker Secrets & Letsencrypt automation
#!/usr/bin/env bash
LE_ARC_DIR="etc/archive"
SECRETS=$(docker secret ls | tail -n +2 | awk '{print $2}')
find $LE_ARC_DIR -name 'fullchain*.pem' -o -name 'privkey*.pem' | sed "s,$LE_ARC_DIR/,," | while read file
do
base_file=$(basename $file .pem | sed -r 's/[0-9]+$//')
version=$(basename $file .pem | sed -r 's/^.*?([0-9]+)$/\1/')
secret_name="le_$(dirname $file)_$base_file.$version"
if ! echo $SECRETS | grep -q $secret_name
then
echo "Creating secret $secret_name for $file"
docker secret create --label letsencrypt $secret_name $LE_ARC_DIR/$file
else
echo "Secret $secret_name already exists"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment