11name : push nuxt app to docker
2-
32on :
43 push :
54 branches :
87 - " README.md"
98 - " .gitignore"
109 workflow_dispatch :
11-
1210permissions :
1311 contents : read
1412 packages : write
1513 actions : write
16-
1714jobs :
1815 build-and-push :
1916 runs-on : ubuntu-latest
20-
21- # Prepare
2217 steps :
2318 - name : Checkout code
2419 uses : actions/checkout@v4
2520
2621 - name : Set up Docker Buildx
2722 uses : docker/setup-buildx-action@v3
23+ with :
24+ platforms : linux/amd64,linux/arm64
2825
2926 - name : Log in to GitHub Container Registry
3027 uses : docker/login-action@v3
@@ -33,76 +30,45 @@ jobs:
3330 username : ${{ github.actor }}
3431 password : ${{ secrets.GITHUB_TOKEN }}
3532
33+ - name : Delete old package versions
34+ uses : actions/delete-package-versions@v5
35+ with :
36+ package-name : ${{ github.event.repository.name }}
37+ package-type : container
38+ min-versions-to-keep : 3
39+
3640 - name : Extract metadata
3741 id : meta
3842 uses : docker/metadata-action@v5
3943 with :
4044 images : ghcr.io/${{ github.repository }}
4145 tags : |
4246 type=raw,value=latest
43- type=sha,prefix=
44-
45- # Caching
46- - name : Check for existing cache
47- id : cache-check
48- uses : actions/cache@v4
49- with :
50- path : /tmp/.buildx-cache
51- key : ${{ runner.os }}-buildx-${{ github.ref }}-${{ hashFiles('Dockerfile', 'package*.json') }}
47+ type=sha,format=long
48+ type=sha,format=short
49+ type=ref,event=branch
5250
53- - name : Delete old caches if no cache found
54- if : steps.cache-check.outputs.cache-hit != ' true'
51+ - name : Cleanup old caches
52+ continue-on-error : true
5553 env :
5654 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5755 run : |
58- if gh cache list --repo ${{ github.repository }} | grep -q 'buildx'; then
59- gh cache delete --all --repo ${{ github.repository }}
60- else
61- echo "No caches to delete."
62- fi
56+ CURRENT_HASH=$(cat Dockerfile package*.json 2>/dev/null | sha256sum | cut -d' ' -f1)
57+ echo "Current dependency hash: $CURRENT_HASH"
58+ gh cache list --json key,id | jq -r '.[] | select(.key | startswith("buildx-")) | select(.key | contains("'$CURRENT_HASH'") | not) | .id' | while read cache_id; do
59+ echo "Deleting old cache: $cache_id"
60+ gh cache delete $cache_id || true
61+ done
6362
64- - name : Cache Docker layers
65- uses : actions/cache@v4
66- with :
67- path : |
68- /tmp/.buildx-cache
69- key : ${{ runner.os }}-buildx-${{ github.ref }}-${{ hashFiles('Dockerfile', 'package*.json') }}
70- restore-keys : |
71- ${{ runner.os }}-buildx-
72-
73- # Delete old packages
74- - name : Delete old package versions
75- uses : actions/delete-package-versions@v5
76- with :
77- # Name of the package.
78- # Required
79- package-name : ${{ github.event.repository.name }}
80-
81- # Type of the package. Can be one of docker (v4 or older), container (v5 or newer), maven, npm, nuget, or rubygems.
82- # Required
83- package-type : container
84-
85- # The number of latest versions to keep.
86- # This cannot be specified with `num-old-versions-to-delete`. By default, `min-versions-to-keep` takes precedence over `num-old-versions-to-delete`.
87- # When set to 0, all deletable versions will be deleted.
88- # When set greater than 0, all deletable package versions except the specified number will be deleted.
89- min-versions-to-keep : 3
90-
91- # Build
9263 - name : Build and push Docker image
9364 uses : docker/build-push-action@v6
9465 with :
9566 context : .
9667 push : true
97- platforms : linux/amd64 # ,linux/arm64
68+ platforms : linux/amd64,linux/arm64
9869 tags : ${{ steps.meta.outputs.tags }}
9970 labels : ${{ steps.meta.outputs.labels }}
100- cache-from : type=local,src=/tmp/.buildx-cache
101- cache-to : type=local,dest=/tmp/.buildx-cache
102- env :
103- BUILDX_NO_DEFAULT_ATTESTATIONS : 1
104-
105- # Temp fix for growing cache size
106- - name : Move cache
107- run : |
108- rm -rf /tmp/.buildx-cache
71+ cache-from : type=gha
72+ cache-to : type=gha,mode=max
73+ build-args : |
74+ BUILDKIT_INLINE_CACHE=1
0 commit comments