-
Notifications
You must be signed in to change notification settings - Fork 1
feat(DEVS-1547): support pushing images to multiple registries #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8495278
feat(DEVS-1547): support pushing images to multiple registries
0x46616c6b 3a99896
fix(DEVS-1547): log in to the bare host when a registry entry has a p…
0x46616c6b f553415
fix(DEVS-1547): gate on resolved credentials, not just top-level ones
0x46616c6b c2f2dc7
fix(DEVS-1547): wire credentials into tag generation, derive retag AP…
0x46616c6b b469aae
fix(DEVS-1547): keep the primary registry's path prefix in the derive…
0x46616c6b 27454f4
fix(DEVS-1547): fail clearly when docker-registries has only blank lines
0x46616c6b 4c10b17
docs(DEVS-1547): document path preservation in docker-registry-api's …
0x46616c6b 49893c0
docs(DEVS-1547): fix the same path-preservation doc gap in the README…
0x46616c6b 502ca62
test(DEVS-1547): rename stale test name to match what it actually covers
0x46616c6b 9247ab8
fix(DEVS-1547): use Bearer auth for GAR retag, reject conflicting dup…
0x46616c6b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
| # Resolves the set of registries to log into and push to. | ||
| # Sourced by other scripts — not executed directly. | ||
| # | ||
| # INPUT_DOCKER_REGISTRIES is a newline-separated list of | ||
| # "registry[|username[|password]]" entries. The first entry is the primary | ||
| # registry — the one used for GitOps manifest updates and release-retag | ||
| # lookups. A missing username/password on a line falls back to the global | ||
| # INPUT_DOCKER_USERNAME/INPUT_DOCKER_PASSWORD. | ||
| # | ||
| # action.yml declares docker-registries as its only registry input (default | ||
| # 'registry.staffbase.com'), so INPUT_DOCKER_REGISTRIES is always populated — | ||
| # callers only ever deal with this one variable. | ||
| # | ||
| # Required env vars: INPUT_DOCKER_REGISTRIES | ||
| # Optional env vars: INPUT_DOCKER_USERNAME, INPUT_DOCKER_PASSWORD | ||
|
|
||
| # resolve_registries populates the global array REGISTRIES with one | ||
| # "registry<TAB>username<TAB>password" entry per registry. | ||
| resolve_registries() { | ||
| REGISTRIES=() | ||
| local line registry rest username password | ||
|
|
||
| while IFS= read -r line; do | ||
| [[ -z "$line" ]] && continue | ||
| registry="${line%%|*}" | ||
| rest="${line#"$registry"}" | ||
| rest="${rest#|}" | ||
| username="${rest%%|*}" | ||
| password="${rest#"$username"}" | ||
| password="${password#|}" | ||
| REGISTRIES+=("${registry}"$'\t'"${username:-${INPUT_DOCKER_USERNAME:-}}"$'\t'"${password:-${INPUT_DOCKER_PASSWORD:-}}") | ||
| done <<< "${INPUT_DOCKER_REGISTRIES}" | ||
|
|
||
| if [[ ${#REGISTRIES[@]} -eq 0 ]]; then | ||
| log_error "INPUT_DOCKER_REGISTRIES contained no registry entries (only blank lines)" | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| # registry_field extracts one column (1=registry, 2=username, 3=password) from | ||
| # a REGISTRIES entry. | ||
| registry_field() { | ||
| local entry="$1" field="$2" | ||
| cut -f "$field" <<< "$entry" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/usr/bin/env bash | ||
| # Logs Docker into every configured registry (see lib/registries.sh). Entries | ||
| # missing a username or password are skipped — e.g. when the action is used | ||
| # purely to update the GitOps repository without touching any registry. | ||
| # | ||
| # Required env vars: INPUT_DOCKER_REGISTRIES | ||
| # Optional env vars: INPUT_DOCKER_USERNAME, INPUT_DOCKER_PASSWORD | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| # shellcheck source=lib/common.sh | ||
| source "${SCRIPT_DIR}/lib/common.sh" | ||
| # shellcheck source=lib/registries.sh | ||
| source "${SCRIPT_DIR}/lib/registries.sh" | ||
|
|
||
| require_env INPUT_DOCKER_REGISTRIES | ||
| require_tool docker | ||
|
|
||
| resolve_registries | ||
| declare -A seen_username seen_password | ||
| for entry in "${REGISTRIES[@]}"; do | ||
| registry="$(registry_field "$entry" 1)" | ||
| username="$(registry_field "$entry" 2)" | ||
| password="$(registry_field "$entry" 3)" | ||
|
|
||
| if [[ -z "$username" || -z "$password" ]]; then | ||
| log_info "Skipping login for '${registry}': no credentials configured." | ||
| continue | ||
| fi | ||
|
|
||
| # A registry entry may carry a path prefix after the host (e.g. GAR's | ||
| # project/repository, baked in so it ends up in the pushed image ref). | ||
| # `docker login` only accepts the host. | ||
| host="${registry%%/*}" | ||
|
|
||
| # Docker's credential store is keyed by host alone, so two entries sharing | ||
| # a host but carrying different credentials would silently overwrite each | ||
| # other — whichever logs in last wins for every entry on that host. | ||
| if [[ -n "${seen_username[$host]+set}" ]]; then | ||
| if [[ "${seen_username[$host]}" != "$username" || "${seen_password[$host]}" != "$password" ]]; then | ||
| log_error "Multiple docker-registries entries use host '${host}' with different credentials. Docker's credential store is keyed by host, so only one set of credentials can be active for it — use the same credentials for every entry on that host." | ||
| exit 1 | ||
| fi | ||
| log_info "Skipping login for '${registry}': already logged in to '${host}'." | ||
| continue | ||
| fi | ||
| seen_username[$host]="$username" | ||
| seen_password[$host]="$password" | ||
|
|
||
| echo "Logging in to ${host}" | ||
| echo "$password" | docker login "$host" --username "$username" --password-stdin | ||
|
Copilot marked this conversation as resolved.
|
||
| done | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, as you changed now the input, does this works e.g. for krusty-krab now https://github.com/search?q=org%3AStaffbase+docker-registry+NOT+is%3Aarchived&type=code
Are you aware of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They need to upgrade the action by changing the input parameters. This PR introduces breaking changes on purpose.