cli/registry/login: Add the --password-env
flag
#5972
+80
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
- What I did
Adds support for providing registry passwords via environment variables, which is particularly useful in CI pipelines. For example, GitLab stores registry passwords in the
CI_REGISTRY_PASSWORD
environment variable.With this change, authenticating to a registry is as simple as:
Alternatives Considered
Using
docker login -p "${VAR}"
with warning suppressionPassing passwords via STDIN (current recommended method):
sh echo "${CI_REGISTRY_PASSWORD}" | docker login --username "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
Avoids warnings but adds complexity to command chains
- How I did it
loginOptions
struct, addingpasswordEnv string
.verifyLoginOptions
to use aswitch
statement instead ofif
blocks to ensure only one block is evaluated.- How to verify it
Verify the following command fails with a "variable DOCKER_TOKEN not defined" error:
Store login credentials in the
DOCKER_TOKEN
environment variable:DOCKER_TOKEN="f00bar"
Verify the command from step 1 now succeeds.
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)
AI generated picutre of a Tanuki
Closes: #5971