Skip to content

Commit 28a512b

Browse files
committed
Refine GitHub Actions Docker workflow
Workflow had outdated dependencies, missing security hardening, and inefficient multi-platform builds for PRs. Fix: - Bump docker/build-push-action v5 → v6 - Add concurrency control to prevent overlapping publishes - Add least-privilege permissions (contents:read, actions:write) - Conditional platforms: PRs build amd64 only, pushes build both - Enable GitHub Actions cache (cache-from/cache-to type=gha)
1 parent 9fc03a2 commit 28a512b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

.github/workflows/docker.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
name: Publish Docker image to DockerHub
2+
23
on:
34
push:
4-
branches: [ dev ]
5+
branches: [dev]
56
pull_request:
6-
branches: [ dev ]
7+
branches: [dev]
8+
9+
concurrency:
10+
group: docker-dev-${{ github.ref }}
11+
cancel-in-progress: true
712

813
# https://docs.docker.com/build/ci/github-actions/multi-platform/
914
jobs:
1015
docker:
1116
name: Build Docker Image and Publish (only on push)
1217
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
actions: write
21+
1322
steps:
14-
1523
- name: Check out the repo
1624
uses: actions/checkout@v4
25+
1726
- name: Set up QEMU
1827
uses: docker/setup-qemu-action@v3
28+
1929
- name: Set up Docker Buildx
2030
uses: docker/setup-buildx-action@v3
31+
2132
- name: Login to Docker Hub
22-
uses: docker/login-action@v3
2333
if: github.event_name == 'push'
34+
uses: docker/login-action@v3
2435
with:
2536
username: ${{ secrets.DOCKERHUB_USERNAME }}
2637
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
38+
2739
- name: Build and push
28-
uses: docker/build-push-action@v5
40+
uses: docker/build-push-action@v6
2941
with:
3042
context: .
31-
platforms: linux/amd64,linux/arm64
43+
platforms: ${{ github.event_name == 'push' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
3244
push: ${{ github.event_name == 'push' }}
3345
tags: sysprog21/chisel-bootcamp:latest
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)