11name : " Prepare builder"
2- description : " Prepares the build environment for Debian packages "
2+ description : " Prepares build environment using Podman with GHCR caching "
33author : " embtom"
44
55inputs :
66 service :
7- description : " The service that was built "
7+ description : " The service in docker-compose.yml "
88 required : true
99
1010runs :
@@ -13,49 +13,55 @@ runs:
1313 - name : Checkout repository
1414 uses : actions/checkout@v4
1515
16- # - name: Set up QEMU
17- # uses: docker/setup-qemu-action@v3
18-
1916 - name : Install Podman and podman-compose
2017 uses : ./.github/actions/setup-podman
2118
22- - name : Podman images
23- id : podman-image
19+ - name : Login to GHCR
2420 shell : bash
2521 run : |
26- image=$(yq -r '.services."${{ inputs.service }}".image' docker-compose.yml)
27- echo "image=${image}" >> $GITHUB_OUTPUT
28-
29- - name : Load cache file
30- id : podman-cache-load
31- uses : actions/cache@v3
32- with :
33- path : podman-cache-${{ inputs.service }}.tar
34- key : podman-image-${{ inputs.service }}-${{ hashFiles('Dockerfile') }}
35-
36- - name : Restore cached image (if available)
37- if : steps.podman-cache-load.outputs.cache-hit == 'true'
22+ echo "${{ github.token }}" | podman login ghcr.io -u "${{ github.actor }}" --password-stdin
23+
24+ - name : Read image name from compose
25+ id : image-name
3826 shell : bash
3927 run : |
40- echo "Loading cached Podman image..."
41- podman load -i podman-cache-${{ inputs.service }}.tar || true
42- podman images
28+ IMG=$(yq -r '.services."${{ inputs.service }}".image' docker-compose.yml)
29+ echo "image=${IMG}" >> $GITHUB_OUTPUT
30+
31+ CACHE_TAG="ghcr.io/${{ github.repository_owner }}/cache-${IMG}"
32+ echo "cache=${CACHE_TAG}" >> $GITHUB_OUTPUT
4333
44- - name : Prepare build environment
34+ - name : Try pulling cache from GHCR
35+ id : pull-cache
4536 shell : bash
4637 run : |
47- SERVICE="${{ inputs.service }}"
48- echo "SERVICE=$SERVICE"
49-
50- if [ "${{ steps.podman-cache-load.outputs.cache-hit }}" == 'true' ]; then
51- echo "Cache hit: skipping podman-compose build"
38+ echo "Trying to pull cache image: ${{ steps.image-name.outputs.cache }}"
39+ if podman pull "${{ steps.image-name.outputs.cache }}"; then
40+ echo "cache-hit=true" >> $GITHUB_OUTPUT
5241 else
53- podman-compose -f docker-compose.yml build "$SERVICE"
42+ echo "cache-hit=false" >> $GITHUB_OUTPUT
5443 fi
5544
56- - name : Save Podman image to cache
45+ - name : Load cached image tag into local tag
46+ if : steps.pull-cache.outputs.cache-hit == 'true'
47+ shell : bash
48+ run : |
49+ podman tag "${{ steps.image-name.outputs.cache }}" \
50+ "${{ steps.image-name.outputs.image }}"
51+
52+ echo "Loaded cached image: ${{ steps.image-name.outputs.image }}"
53+
54+ - name : Build image if cache miss
55+ if : steps.pull-cache.outputs.cache-hit == 'false'
56+ shell : bash
57+ run : |
58+ echo "Cache miss → building image…"
59+ podman-compose -f docker-compose.yml build "${{ inputs.service }}"
60+
61+ - name : Push updated image to GHCR as cache
5762 shell : bash
5863 run : |
59- echo "Saving Podman image to cache..."
60- podman save -o podman-cache-${{ inputs.service }}.tar \
61- "${{ steps.podman-image.outputs.image }}"
64+ podman tag "${{ steps.image-name.outputs.image }}" \
65+ "${{ steps.image-name.outputs.cache }}"
66+
67+ podman push "${{ steps.image-name.outputs.cache }}"
0 commit comments