@@ -3,52 +3,65 @@ name: Build & Publish Docker Image
33on :
44
55 pull_request :
6- branches :
7- - docker
6+ branches : [ docker ]
87 paths :
98 - ' docker/Dockerfile'
109 - ' docker/requirements.txt'
1110 - ' docker/docker-compose.yml'
1211 - ' .github/workflows/docker-publish.yml'
1312
1413 push :
15- branches :
16- - docker
14+ branches : [ docker ]
1715 paths :
1816 - ' docker/Dockerfile'
1917 - ' docker/requirements.txt'
2018 - ' docker/docker-compose.yml'
2119 - ' .github/workflows/docker-publish.yml'
2220
21+
22+ # ─────────────── global env ──────────────────────────────────────────────────
23+ env :
24+ REGISTRY : ghcr.io
25+ IMAGE_NAME : deeptrackai/deep-learning-crash-course # change once here
26+
2327jobs :
2428 build-and-push :
2529 runs-on : ubuntu-latest
2630 permissions :
27- contents : read # for checkout
28- packages : write # to push to GHCR
31+ contents : read
32+ packages : write # needed to push to GHCR
33+
2934 steps :
30- - uses : actions/checkout@v3
35+ - uses : actions/checkout@v4
3136
32- - name : Set up QEMU (for multi-arch builds)
33- uses : docker/setup-qemu -action@v2
37+ - uses : docker/setup-qemu-action@v3 # multi-arch emulation
38+ - uses : docker/setup-buildx -action@v3 # Buildx driver with cache support
3439
35- - name : Set up Docker Buildx
36- uses : docker/setup-buildx-action@v2
40+ # -------- optional, but speeds repeat builds -----------
41+ - name : Restore Docker layer cache
42+ uses : actions/cache@v4
43+ with :
44+ path : /tmp/.buildx-cache
45+ key : ${{ runner.os }}-buildx-${{ github.sha }}
46+ restore-keys : ${{ runner.os }}-buildx-
47+ # --------------------------------------------------------
3748
38- - name : Log in to GitHub Container Registry
39- uses : docker/login-action@v2
49+ - name : Log in to GHCR
50+ uses : docker/login-action@v3
4051 with :
4152 registry : ghcr.io
4253 username : ${{ github.actor }}
4354 password : ${{ secrets.GITHUB_TOKEN }}
4455
45- - name : Build and push
46- uses : docker/build-push-action@v3
56+ - name : Build ( and push on main branch)
57+ uses : docker/build-push-action@v5
4758 with :
48- context : . # or ./docker if you keep your Dockerfile there
49- file : ./docker/Dockerfile # adjust path if needed
50- push : true
59+ context : .
60+ file : docker/Dockerfile # adjust if your Dockerfile moves
5161 platforms : linux/amd64,linux/arm64
62+ push : ${{ github.event_name == 'push' }} # PRs build but don’t publish
5263 tags : |
5364 ghcr.io/deeptrackai/deep-learning-crash-course:latest
5465 ghcr.io/deeptrackai/deep-learning-crash-course:${{ github.sha }}
66+ cache-from : type=local,src=/tmp/.buildx-cache
67+ cache-to : type=local,dest=/tmp/.buildx-cache,mode=max
0 commit comments