Skip to content

Commit a688255

Browse files
author
Prakash
committed
Fixing a buildx related issue with multi platform support
1 parent 5f97b34 commit a688255

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

.github/workflows/build-and-publish.yml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
NODE_VERSION: '22'
1313

1414
jobs:
15-
test-and-lint:
15+
lint-and-test:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout code
@@ -42,7 +42,7 @@ jobs:
4242
severity: 'CRITICAL,HIGH'
4343

4444
build-and-publish:
45-
needs: test-and-lint
45+
needs: lint-and-test
4646
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
4747
runs-on: ubuntu-latest
4848
permissions:
@@ -84,44 +84,38 @@ jobs:
8484
username: ${{ github.actor }}
8585
password: ${{ secrets.GITHUB_TOKEN }}
8686

87-
# Build image locally without pushing
88-
- name: Build multi-arch image locally
87+
# Build and push to a temporary tag for scanning
88+
- name: Build and push multi-arch image (temp)
8989
uses: docker/build-push-action@v5
9090
with:
9191
context: .
9292
file: package/docker/Dockerfile
9393
platforms: linux/amd64,linux/arm64
94-
push: false
95-
load: true
94+
push: true
9695
tags: |
97-
${{ env.IMAGE_NAME }}:local-scan
96+
${{ env.IMAGE_NAME }}:scan-${{ github.sha }}
9897
cache-from: type=gha
9998
cache-to: type=gha,mode=max
10099

101-
# Scan the local image before pushing
100+
# Scan the pushed image
102101
- name: Scan Docker image for vulnerabilities
103102
uses: aquasecurity/trivy-action@0.30.0
104103
with:
105-
image-ref: '${{ env.IMAGE_NAME }}:local-scan'
104+
image-ref: '${{ env.IMAGE_NAME }}:scan-${{ github.sha }}'
106105
format: 'table'
107106
exit-code: '1'
108107
severity: 'CRITICAL,HIGH'
109108

110-
# Only push if security scan passes
111-
- name: Push multi-arch image
109+
# If scan passes, tag the image with final tags
110+
- name: Tag image with final tags
112111
if: success()
113-
uses: docker/build-push-action@v5
114-
with:
115-
context: .
116-
file: package/docker/Dockerfile
117-
platforms: linux/amd64,linux/arm64
118-
push: true
119-
tags: |
120-
${{ env.IMAGE_NAME }}:latest
121-
${{ env.IMAGE_NAME }}:${{ github.sha }}
122-
${{ env.IMAGE_NAME }}:v${{ steps.package-version.outputs.version }}
123-
cache-from: type=gha
124-
cache-to: type=gha,mode=max
112+
run: |
113+
# Tag the scanned image with final tags
114+
docker buildx imagetools create \
115+
--tag ${{ env.IMAGE_NAME }}:latest \
116+
--tag ${{ env.IMAGE_NAME }}:${{ github.sha }} \
117+
--tag ${{ env.IMAGE_NAME }}:v${{ steps.package-version.outputs.version }} \
118+
${{ env.IMAGE_NAME }}:scan-${{ github.sha }}
125119
126120
# This step dispatches an event to the utils repo to trigger downstream deployments
127121
- name: Repository Dispatch

0 commit comments

Comments
 (0)