diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index f718b4356..46a295492 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1757,6 +1757,20 @@ APP="$1" haproxy-build-config "$APP" ``` +### `post-registry-login` + +- Description: Allows running a command after the a registry has been logged into +- Invoked by: `dokku registry:login` +- Arguments: `$DOCKER_REGISTRY_SERVER $DOCKER_REGISTRY_USER` +- Example: + +```shell +#!/usr/bin/env bash + +# the DOCKER_REGISTRY_PASS env var is also set +echo "$DOCKER_REGISTRY_PASS" +``` + ### `post-release-builder` > [!WARNING] diff --git a/plugins/common/plugn.go b/plugins/common/plugn.go index dc65dbac2..4ef69ef61 100644 --- a/plugins/common/plugn.go +++ b/plugins/common/plugn.go @@ -16,6 +16,7 @@ import ( type PlugnTriggerInput struct { Args []string CaptureOutput bool + Env map[string]string StreamStdio bool Trigger string } @@ -42,6 +43,11 @@ func CallPlugnTrigger(input PlugnTriggerInput) (execute.ExecResult, error) { if isatty && !input.CaptureOutput { env = append(env, "FORCE_TTY=1") } + if input.Env != nil { + for k, v := range input.Env { + env = append(env, fmt.Sprintf("%s=%s", k, v)) + } + } args := []string{"trigger", input.Trigger} args = append(args, input.Args...) diff --git a/plugins/registry/subcommands.go b/plugins/registry/subcommands.go index a5d2c5359..2a5c58296 100644 --- a/plugins/registry/subcommands.go +++ b/plugins/registry/subcommands.go @@ -53,6 +53,19 @@ func CommandLogin(server string, username string, password string, passwordStdin return errors.New("Failed to log into registry") } + _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "post-registry-login", + Args: []string{server, username}, + StreamStdio: true, + CaptureOutput: false, + Env: map[string]string{ + "DOCKER_REGISTRY_PASS": password, + }, + }) + if err != nil { + return err + } + return nil }