Skip to content

Commit

Permalink
refactor: use pre/post triggers for service-action naming
Browse files Browse the repository at this point in the history
This is a bit more clear as the links aren't always idempotent and may have errors - this allows users to reconcile at what point a link may have failed so that they can take further action.
  • Loading branch information
Jose Diaz-Gonzalez committed Feb 25, 2021
1 parent 9974da1 commit 4e808c6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ service_link() {
fi

[[ -n $LINK ]] && dokku_log_fail "Already linked as $LINK"
plugn trigger service-action pre-link "$SERVICE" "$APP"
touch "$LINKS_FILE"
echo "$APP" >>"$LINKS_FILE"
sort "$LINKS_FILE" -u -o "$LINKS_FILE"
Expand All @@ -465,8 +466,9 @@ service_link() {
dokku docker-options:add "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME"
fi
[[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}"
plugn trigger service-action post-link "$SERVICE" "$APP"
config_set "$APP" "${ALIAS}_URL=$SERVICE_URL"
plugn trigger service-action link "$SERVICE" "$APP"
plugn trigger service-action post-link-complete "$SERVICE" "$APP"
}

service_linked_apps() {
Expand Down Expand Up @@ -772,6 +774,7 @@ service_unlink() {
local SERVICE_DNS_HOSTNAME=$(service_dns_hostname "$SERVICE")
local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true

plugn trigger service-action pre-unlink "$SERVICE" "$APP"
remove_from_links_file "$SERVICE" "$APP"

if declare -f -F add_passed_docker_option >/dev/null; then
Expand All @@ -783,8 +786,9 @@ service_unlink() {
fi

[[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP"
plugn trigger service-action post-unlink "$SERVICE" "$APP"
config_unset "$APP" "${LINK[*]}"
plugn trigger service-action unlink "$SERVICE" "$APP"
plugn trigger service-action post-unlink-complete "$SERVICE" "$APP"
}

service_version() {
Expand Down

0 comments on commit 4e808c6

Please sign in to comment.