Skip to content

Commit

Permalink
Merge pull request #275 from BilliAlpha/fix/issue-235
Browse files Browse the repository at this point in the history
Return both host and container config dir
  • Loading branch information
josegonzalez authored Aug 8, 2022
2 parents 2327278 + 71af85f commit 6a82b84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ letsencrypt_configure_and_get_dir() {
# store config settings
echo "--http.port :$acme_port $config" >"$config_dir/config"

# re-implement entire path to respect mapped DOKKU_ROOT when running in a container
echo "$DOKKU_HOST_ROOT/$app/letsencrypt/certs/$config_hash"
# send both host and container path
# to respect mapped DOKKU_ROOT when running in a container
echo "$DOKKU_HOST_ROOT/$app/letsencrypt/certs/$config_hash:$config_dir"
}

letsencrypt_get_email() {
Expand Down
10 changes: 6 additions & 4 deletions subcommands/enable
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ letsencrypt_acme() {
dokku_log_info1 "Getting letsencrypt certificate for ${app}..."

# read arguments from appropriate config file into the config array
config_dir="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")"
read -r -a config <"$config_dir/config"
config_dirs="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")"
host_config_dir="$(echo "$config_dirs" | cut -d: -f1)"
container_config_dir="$(echo "$config_dirs" | cut -d: -f2)"
read -r -a config <"$container_config_dir/config"

# run letsencrypt as a docker container using "certonly" mode
# port 80 of the standalone webserver will be forwarded by the proxy
Expand All @@ -95,7 +97,7 @@ letsencrypt_acme() {
docker run --rm \
--user $DOKKU_UID:$DOKKU_GID \
-p "$acme_port:$acme_port" \
-v "$config_dir:/certs" \
-v "$host_config_dir:/certs" \
"${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION}" \
"${config[@]}" run | sed "s/^/ /"

Expand All @@ -113,7 +115,7 @@ letsencrypt_acme() {

# got certificate
dokku_log_info1 "Certificate retrieved successfully."
letsencrypt_link "$app" "$config_dir"
letsencrypt_link "$app" "$container_config_dir"
nginx_build_config "$app"
}

Expand Down
18 changes: 10 additions & 8 deletions subcommands/revoke
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ letsencrypt_acme_revoke() {
local acme_port=$(get_available_port)

# read arguments from appropriate config file into the config array
local config_dir="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")"
read -r -a config <"$config_dir/config"
config_dirs="$(letsencrypt_configure_and_get_dir "$app" "$acme_port")"
host_config_dir="$(echo "$config_dirs" | cut -d: -f1)"
container_config_dir="$(echo "$config_dirs" | cut -d: -f2)"
read -r -a config <"$container_config_dir/config"

# run letsencrypt as a docker container using "certonly" mode
# port 80 of the standalone webserver will be forwarded by the proxy
Expand All @@ -28,7 +30,7 @@ letsencrypt_acme_revoke() {
docker run --rm \
--user $DOKKU_UID:$DOKKU_GID \
-p "$acme_port:$acme_port" \
-v "$config_dir:/certs" \
-v "$host_config_dir:/certs" \
"${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION}" \
"${config[@]}" revoke | sed "s/^/ /"

Expand All @@ -48,11 +50,11 @@ letsencrypt_acme_revoke() {
local domain="$(get_app_domains "$app" | xargs | awk '{print $1}')"

# move revoked certificates away
mv -f "$config_dir/certificates/$domain.crt" "$config_dir/certificates/$domain.crt.revoked"
mv -f "$config_dir/certificates/$domain.issuer.crt" "$config_dir/certificates/$domain.issuer.crt"
mv -f "$config_dir/certificates/$domain.key" "$config_dir/certificates/$domain.key"
mv -f "$config_dir/certificates/$domain.key" "$config_dir/certificates/$domain.key"
mv -f "$config_dir/certificates/$domain.pem" "$config_dir/certificates/key.pem.revoked"
mv -f "$container_config_dir/certificates/$domain.crt" "$container_config_dir/certificates/$domain.crt.revoked"
mv -f "$container_config_dir/certificates/$domain.issuer.crt" "$container_config_dir/certificates/$domain.issuer.crt"
mv -f "$container_config_dir/certificates/$domain.key" "$container_config_dir/certificates/$domain.key"
mv -f "$container_config_dir/certificates/$domain.key" "$container_config_dir/certificates/$domain.key"
mv -f "$container_config_dir/certificates/$domain.pem" "$container_config_dir/certificates/key.pem.revoked"

# removing the certificate will automatically reconfigure nginx
if [[ -z $DOKKU_APP_NAME ]]; then
Expand Down

0 comments on commit 6a82b84

Please sign in to comment.