refactor: use pre/post triggers for service-action naming

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.
This commit is contained in:
Jose Diaz-Gonzalez
2021-02-25 16:05:24 -05:00
parent 6ca823d417
commit 476ccb73e1

View File

@@ -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"
@@ -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() {
@@ -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
@@ -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() {