Skip to content

Commit bfc2d02

Browse files
committed
ghr cache
1 parent 3b6e6f4 commit bfc2d02

2 files changed

Lines changed: 43 additions & 41 deletions

File tree

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: "Prepare builder"
2-
description: "Prepares the build environment for Debian packages"
2+
description: "Prepares build environment using Podman with GHCR caching"
33
author: "embtom"
44

55
inputs:
66
service:
7-
description: "The service that was built"
7+
description: "The service in docker-compose.yml"
88
required: true
99

1010
runs:
@@ -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 }}"

.github/workflows/ci-build.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ jobs:
1313
matrix:
1414
include:
1515
- platform: linux-amd64
16+
arch: amd64
1617
runner: ubuntu-24.04
1718
service: builder
1819
- platform: linux-arm64
20+
arch: arm64
1921
runner: ubuntu-24.04-arm
2022
service: builder-arm64
2123

2224
runs-on: ${{ matrix.runner }}
25+
permissions:
26+
packages: write
2327

2428
steps:
2529
- name: Checkout repository
@@ -34,14 +38,6 @@ jobs:
3438
- name: Show parsed version
3539
run: echo Version=${{ steps.changelog.outputs.version }}
3640

37-
# - name: Set up cache for Podman
38-
# uses: actions/cache@v3
39-
# with:
40-
# path: ~/.local/share/containers/storage
41-
# key: podman-cache-${{ matrix.platform }}-${{ hashFiles('Dockerfile') }}
42-
# restore-keys: |
43-
# podman-cache-${{ matrix.platform }}-
44-
4541
- name: Prepare build environment
4642
uses: ./.github/actions/prepare-builder
4743
with:

0 commit comments

Comments
 (0)