@@ -7,8 +7,14 @@ name: Docker
77
88on :
99 workflow_dispatch :
10+ inputs :
11+ build_arm64 :
12+ description : ' Build and publish ARM64 image (multi-arch manifest)'
13+ type : boolean
14+ default : false
1015 push :
1116 branches :
17+ - ' main'
1218 - ' develop'
1319 - ' release/**'
1420 - ' hotfix/**'
@@ -42,19 +48,40 @@ jobs:
4248
4349 steps :
4450 - name : Checkout repository
45- uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
51+ uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
52+
53+ # Set up QEMU for ARM64 cross-compilation on AMD64 runners
54+ - name : Set up QEMU
55+ uses : docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
4656
4757 # Set up BuildKit Docker container builder to be able to build
4858 # multi-platform images and export cache
4959 # https://github.com/docker/setup-buildx-action
5060 - name : Set up Docker Buildx
51- uses : docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
61+ uses : docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
62+
63+ # ARM64 is included for main, develop, hotfix, release branches, version tags, and manual trigger.
64+ # Pull requests (e.g. feature → develop) build AMD64 only; ARM64 is built on merge (push event).
65+ - name : Determine build platforms
66+ id : platforms
67+ run : |
68+ PLATFORMS="linux/amd64"
69+ if [[ "${{ github.ref }}" == refs/heads/main ]] || \
70+ [[ "${{ github.ref }}" == refs/heads/develop ]] || \
71+ [[ "${{ github.ref }}" == refs/heads/hotfix/* ]] || \
72+ [[ "${{ github.ref }}" == refs/heads/release/* ]] || \
73+ [[ "${{ github.ref }}" == refs/tags/v* ]] || \
74+ [[ "${{ inputs.build_arm64 }}" == "true" ]]; then
75+ PLATFORMS="linux/amd64,linux/arm64"
76+ fi
77+ echo "platforms=$PLATFORMS" >> $GITHUB_OUTPUT
78+ echo "include_arm64=$([ "$PLATFORMS" = "linux/amd64,linux/arm64" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
5279
5380 # Login against a Docker registry except on PR
5481 # https://github.com/docker/login-action
5582 - name : Log into registry ${{ env.REGISTRY }}
5683 if : github.event_name != 'pull_request'
57- uses : docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6 .0
84+ uses : docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2 .0
5885 with :
5986 registry : ${{ env.REGISTRY }}
6087 username : ${{ github.actor }}
@@ -64,62 +91,87 @@ jobs:
6491 # https://github.com/docker/metadata-action
6592 - name : Extract Docker metadata
6693 id : meta
67- uses : docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10 .0
94+ uses : docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1 .0
6895 with :
6996 images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
7097 flavor : |
7198 latest=false
7299 tags : |
73100 type=semver,pattern={{raw}}
74- type=raw,value=develop-{{sha}},enable=${{startsWith(github.ref, 'refs/heads/develop')}}
75- type=raw,value=rc-{{branch}}-{{sha}},enable=${{startsWith(github.ref, 'refs/heads/release/')}}
76- type=raw,value={{branch}}-{{sha}},enable=${{startsWith(github.ref, 'refs/heads/hotfix/')}}
101+ # Priority is set to ensure the develop-{{sha}} tag is preferred over other tags for the develop branch
102+ type=raw,value=develop-{{sha}},enable=${{startsWith(github.ref,'refs/heads/develop')}},priority=201
103+ type=raw,value=develop,enable=${{startsWith(github.ref,'refs/heads/develop')}}
104+ type=raw,value=rc-{{branch}}-{{sha}},enable=${{startsWith(github.ref,'refs/heads/release/')}}
105+ # The following tag is only applied to regular branches except 'develop' and 'release/*' (i.e., not for tags or PRs)
106+ type=raw,value={{branch}}-{{sha}},enable=${{startsWith(github.ref,'refs/heads/') && !startsWith(github.ref,'refs/heads/develop') && !startsWith(github.ref,'refs/heads/release/')}}
77107 type=ref,event=pr
78- type=raw,value=manual-{{branch}}-{{sha}},enable=${{github.event_name == 'workflow_dispatch'}}
79108
80109 # Build and push Docker image with Buildx (don't push on PR)
81110 # https://github.com/docker/build-push-action
82111 - name : Build and push Docker image
83112 id : build-and-push
84- uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18 .0
113+ uses : docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2 .0
85114 with :
86115 sbom : true
87116 provenance : mode=max
88117 context : ${{ env.BUILD_CONTEXT }}
89118 file : ${{ env.DOCKERFILE_PATH }}
119+ platforms : ${{ steps.platforms.outputs.platforms }}
90120 push : ${{ github.event_name != 'pull_request' }}
91121 tags : ${{ steps.meta.outputs.tags }}
92122 labels : ${{ steps.meta.outputs.labels }}
93123 cache-from : type=gha
94124 cache-to : type=gha,mode=max
95125
96-
97126 # Extract the pure application SBOM from the artifact stage, we want to handle it separately from the container SBOM
98127 # This automaticaly re-uses the previously generated stage from cache, so we get the exact sbom from previous build step
99128 - name : Export Application SBOM from artifact stage
100129 if : ${{ github.event_name != 'pull_request' }}
101- uses : docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18 .0
130+ uses : docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2 .0
102131 with :
103132 context : ${{ env.BUILD_CONTEXT }}
104133 file : ${{ env.DOCKERFILE_PATH }}
105134 target : app-sbom-artifact
106135 push : false
107136 outputs : type=local,dest=sbom-output
108137
138+ # Extract the tag with the highest priority from the list for Trivy scanning
139+ - name : Get highest priority image tag
140+ if : ${{ github.event_name != 'pull_request' }}
141+ id : highest-priority-tag
142+ run : |
143+ # The first tag in the list is the one with the highest priority
144+ echo "value=$(echo '${{ steps.meta.outputs.tags }}' | head -n1)" >> $GITHUB_OUTPUT
145+
109146 # Generate container SBOM.
110147 - name : Run Trivy in GitHub SBOM mode to generate CycloneDX SBOM for container
111148 if : ${{ github.event_name != 'pull_request' }}
112- uses : aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
149+ uses : aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # 0.36.0
150+ env :
151+ TRIVY_PLATFORM : linux/amd64
113152 with :
114153 scan-type : ' image'
115154 format : ' cyclonedx'
116- output : ' sbom-output/sbom_container .cyclonedx.json'
117- image-ref : ${{ steps.meta .outputs.tags }}
118- skip-dirs : ' /App' # Skip the /app directory as we handle the content of the application in a seperate SBOM for easier vulnerability management and because trivy misses important fields
155+ output : ' sbom-output/sbom_container_amd64 .cyclonedx.json'
156+ image-ref : ${{ steps.highest-priority-tag .outputs.value }}
157+ skip-dirs : ' /App' # Skip the /app directory as we handle the content of the application in a separate SBOM for easier vulnerability management and because trivy misses important fields
119158
159+ # Scan ARM64 image separately when a multi-arch build was produced
160+ - name : Run Trivy scan for ARM64 image
161+ if : ${{ github.event_name != 'pull_request' && steps.platforms.outputs.include_arm64 == 'true' }}
162+ uses : aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # 0.36.0
163+ env :
164+ TRIVY_PLATFORM : linux/arm64
165+ with :
166+ scan-type : ' image'
167+ format : ' cyclonedx'
168+ output : ' sbom-output/sbom_container_arm64.cyclonedx.json'
169+ image-ref : ${{ steps.highest-priority-tag.outputs.value }}
170+ skip-dirs : ' /App'
171+
120172 - name : Upload trivy/container AND application SBOMs as a Github artifact
121173 if : ${{ github.event_name != 'pull_request' }}
122- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
174+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
123175 with :
124176 name : sbom
125177 path : ' ${{ github.workspace }}/sbom-output/'
0 commit comments