Skip to content

Commit b2d3c00

Browse files
authored
Merge pull request #239 from cisagov/bug/push_after_building
Build and push Docker images as separate steps
2 parents 388cca2 + 039eea5 commit b2d3c00

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

.github/workflows/build.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ jobs:
342342
# documentation:
343343
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
344344
cache-to: type=gha,mode=max
345+
# For a list of pre-defined annotation keys and value types see:
346+
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
345347
labels: ${{ needs.prepare.outputs.labels }}
346348
outputs: type=docker,dest=dist/image.tar
347349
# Uncomment the following option if you are building an image for use
@@ -350,8 +352,6 @@ jobs:
350352
# information: https://github.com/docker/buildx/issues/1533
351353
# provenance: false
352354
tags: ${{ needs.repo-metadata.outputs.image-name }}:latest # not to be pushed
353-
# For a list of pre-defined annotation keys and value types see:
354-
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
355355
- name: Compress image
356356
run: gzip dist/image.tar
357357
- name: Upload artifacts
@@ -500,7 +500,17 @@ jobs:
500500
uses: docker/setup-qemu-action@v3
501501
- name: Set up Docker Buildx
502502
uses: docker/setup-buildx-action@v3
503-
- name: Build and push platform images to registries
503+
# We only build to ensure that the image layers are cached to push later. This is
504+
# because if the build takes over 10 minutes the token acquired to push to the
505+
# GitHub Container Registry will have expired. This results in errors like:
506+
#
507+
# <AuthenticationErrorDetail>Signature not valid in the specified time frame:
508+
# Start [Tue, 08 Jul 2025 06:05:02 GMT] - Expiry [Tue, 08 Jul 2025 06:15:07 GMT]
509+
# - Current [Tue, 08 Jul 2025 06:16:10 GMT]</AuthenticationErrorDetail>
510+
#
511+
# Please see https://github.com/docker/build-push-action/issues/1371 for more
512+
# information.
513+
- name: Build platform images
504514
id: docker_build
505515
uses: docker/build-push-action@v6
506516
with:
@@ -511,17 +521,40 @@ jobs:
511521
# documentation:
512522
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
513523
cache-to: type=gha,mode=max
524+
# For a list of pre-defined annotation keys and value types see:
525+
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
514526
labels: ${{ needs.prepare.outputs.labels }}
515527
platforms: ${{ join(fromJSON(needs.repo-metadata.outputs.image-platforms)) }}
516528
# Uncomment the following option if you are building an image for use
517529
# on Google Cloud Run or AWS Lambda. The current default image output
518530
# is unable to run on either. Please see the following issue for more
519531
# information: https://github.com/docker/buildx/issues/1533
520532
# provenance: false
521-
push: true
522533
tags: ${{ needs.prepare.outputs.tags }}
534+
# Now that the image layers should be available from the cache we can push to the
535+
# registries.
536+
- name: Push platform images to registries
537+
id: docker_push
538+
uses: docker/build-push-action@v6
539+
with:
540+
cache-from: type=gha
541+
# We use the max mode to cache all layers which includes ones from
542+
# intermediate steps. This will provide us the potential for more cache hits
543+
# and thus better build times. It is also the suggested setting per the
544+
# documentation:
545+
# https://docs.docker.com/build/ci/github-actions/cache/#cache-backend-api
546+
cache-to: type=gha,mode=max
523547
# For a list of pre-defined annotation keys and value types see:
524548
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
549+
labels: ${{ needs.prepare.outputs.labels }}
550+
platforms: ${{ join(fromJSON(needs.repo-metadata.outputs.image-platforms)) }}
551+
# Uncomment the following option if you are building an image for use
552+
# on Google Cloud Run or AWS Lambda. The current default image output
553+
# is unable to run on either. Please see the following issue for more
554+
# information: https://github.com/docker/buildx/issues/1533
555+
# provenance: false
556+
push: true
557+
tags: ${{ needs.prepare.outputs.tags }}
525558
- name: Setup tmate debug session
526559
uses: mxschmitt/action-tmate@v3
527560
if: env.RUN_TMATE

0 commit comments

Comments
 (0)