-
Notifications
You must be signed in to change notification settings - Fork 373
Copy production image with direct Docker registry auth #758
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -340,6 +340,7 @@ jobs: | |||||||||
| env: | ||||||||||
| # Pass the upstream token via env rather than `-t` so it doesn't appear in /proc/<pid>/cmdline. | ||||||||||
| CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }} | ||||||||||
| CPLN_TOKEN_PRODUCTION: ${{ secrets.CPLN_TOKEN_PRODUCTION }} | ||||||||||
| PRODUCTION_APP_NAME: ${{ vars.PRODUCTION_APP_NAME }} | ||||||||||
| CPLN_ORG_STAGING: ${{ vars.CPLN_ORG_STAGING }} | ||||||||||
| CPLN_ORG_PRODUCTION: ${{ vars.CPLN_ORG_PRODUCTION }} | ||||||||||
|
|
@@ -379,7 +380,10 @@ jobs: | |||||||||
| '[.items[].name | select(startswith($prefix)) | (try capture("^[^:]+:(?<number>[0-9]+)") catch empty) | .number | tonumber] | max // 0' | ||||||||||
| )" | ||||||||||
| production_image="${PRODUCTION_APP_NAME}:$((latest_number + 1))_${staging_commit}" | ||||||||||
| staging_registry="${CPLN_ORG_STAGING}.registry.cpln.io" | ||||||||||
| production_registry="${CPLN_ORG_PRODUCTION}.registry.cpln.io" | ||||||||||
| source_image_ref="${CPLN_ORG_STAGING}.registry.cpln.io/${STAGING_IMAGE}" | ||||||||||
| production_image_ref="${CPLN_ORG_PRODUCTION}.registry.cpln.io/${production_image}" | ||||||||||
|
|
||||||||||
| docker_config_dir="$(mktemp -d)" | ||||||||||
| cleanup_copy_credentials() { | ||||||||||
|
|
@@ -391,14 +395,14 @@ jobs: | |||||||||
|
|
||||||||||
| copy_status=1 | ||||||||||
| for attempt in $(seq 1 "${copy_image_attempts}"); do | ||||||||||
| if CPLN_TOKEN="${CPLN_TOKEN_STAGING}" cpln image docker-login --org "${CPLN_ORG_STAGING}" >/dev/null && | ||||||||||
| if printf '%s' "${CPLN_TOKEN_STAGING}" | | ||||||||||
| docker login "${staging_registry}" -u '<token>' --password-stdin >/dev/null && | ||||||||||
| printf '%s' "${CPLN_TOKEN_PRODUCTION}" | | ||||||||||
| docker login "${production_registry}" -u '<token>' --password-stdin >/dev/null && | ||||||||||
| docker manifest inspect "${source_image_ref}" >/dev/null && | ||||||||||
| CPLN_TOKEN="${CPLN_TOKEN_STAGING}" \ | ||||||||||
| cpln image copy "${STAGING_IMAGE}" \ | ||||||||||
| --org "${CPLN_ORG_STAGING}" \ | ||||||||||
| --to-profile default \ | ||||||||||
| --to-org "${CPLN_ORG_PRODUCTION}" \ | ||||||||||
| --to-name "${production_image}"; then | ||||||||||
| docker pull "${source_image_ref}" && | ||||||||||
| docker tag "${source_image_ref}" "${production_image_ref}" && | ||||||||||
| docker push "${production_image_ref}"; then | ||||||||||
|
Comment on lines
+403
to
+405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multi-arch concern: If multi-arch is not needed, this is fine. Otherwise consider using
Suggested change
(that replaces the three lines — if this one-liner works in your buildx setup, remove the pull/tag lines entirely).
Comment on lines
+403
to
+405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||
| copy_status=0 | ||||||||||
| break | ||||||||||
| else | ||||||||||
|
|
||||||||||
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.
These two
docker logincalls run on every retry attempt, but credentials never change between retries. Consider hoisting them above the loop so they run once — retries are really only needed for the pull/tag/push operations.(Move the two
docker logincalls to just after theexport DOCKER_CONFIGline, before the retry loop.)