Skip to content

Commit ef4e34c

Browse files
committed
add CI for image building
1 parent 8b33652 commit ef4e34c

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

.github/workflows/main.yml

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Build all images
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
defaults:
8+
run:
9+
shell: bash
10+
11+
jobs:
12+
define-matrix:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
distros: ${{ steps.distros.outputs.distros }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Define Distros
19+
id: distros
20+
run: echo "distros=[$(awk -F= '/DEFAULT_DISTROS/{print $2}' ./internal/lib/distro_info.sh | sed -e 's/ /", "/g')]" >> "$GITHUB_OUTPUT"
21+
22+
build-buildbox:
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
arch:
27+
- name: amd64
28+
runner: ubuntu-24.04
29+
- name: arm64
30+
runner: ubuntu-24.04-arm
31+
name: build buildbox-${{ matrix.arch.name }}
32+
runs-on: ${{ matrix.arch.runner }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Prepare
36+
run: |
37+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
38+
echo "BUILDBOX_IMAGE_VERSION=$(./internal/lib/docker_image_info.sh buildbox_version)" >> $GITHUB_ENV
39+
echo "BUILDBOX_IMAGE_NAME=$(./internal/lib/docker_image_info.sh buildbox_name)" >> $GITHUB_ENV
40+
env:
41+
platform: linux/${{ matrix.arch.name }}
42+
43+
- name: Docker meta
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: |
48+
ghcr.io/${{ env.BUILDBOX_IMAGE_NAME }}
49+
tags: |
50+
type=raw,value=${{ env.BUILDBOX_IMAGE_VERSION }}-${{ matrix.arch.name }}
51+
type=edge,enable=true,priority=700,prefix=,suffix=${{ matrix.arch.name }},branch=$repo.default_branch
52+
53+
- name: Login to GHCR
54+
uses: docker/login-action@v3
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.actor }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Set up QEMU
61+
uses: docker/setup-qemu-action@v3
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v3
65+
66+
- name: Build and push by tag
67+
id: build
68+
uses: docker/build-push-action@v6
69+
with:
70+
context: ./docker-images/buildbox
71+
file: ./docker-images/buildbox/Dockerfile
72+
platforms: linux/${{ matrix.arch.name }}
73+
labels: ${{ steps.meta.outputs.labels }}
74+
tags: ${{ steps.meta.outputs.tags }}
75+
outputs: "type=image,name=ghcr.io/${{ env.BUILDBOX_IMAGE_NAME }},push-by-digest=false,name-canonical=true,push=true"
76+
77+
- name: Export digest
78+
run: |
79+
mkdir -p /tmp/digests
80+
digest="${{ steps.build.outputs.digest }}"
81+
touch "/tmp/digests/${digest#sha256:}"
82+
83+
- name: Upload digest
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: digests-buildbox-${{ env.PLATFORM_PAIR }}
87+
path: /tmp/digests/*
88+
if-no-files-found: error
89+
retention-days: 1
90+
91+
build-testboxes:
92+
needs: define-matrix
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
distro: ${{ fromJSON(needs.define-matrix.outputs.distros) }}
97+
arch:
98+
- name: amd64
99+
runner: ubuntu-24.04
100+
- name: arm64
101+
runner: ubuntu-24.04-arm
102+
name: build testbox ${{ matrix.distro }}-${{ matrix.arch.name }}
103+
runs-on: ${{ matrix.arch.runner }}
104+
steps:
105+
- uses: actions/checkout@v4
106+
- name: Prepare
107+
run: |
108+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
109+
echo "TESTBOX_IMAGE_VERSION=$(./internal/lib/docker_image_info.sh testbox_version)" >> $GITHUB_ENV
110+
export "TESTBOX_BASE_NAME=$(./internal/lib/docker_image_info.sh testbox_base_name)"
111+
echo "TESTBOX_BASE_NAME=$TESTBOX_BASE_NAME" >> $GITHUB_ENV
112+
echo "TESTBOX_IMAGE_NAME=${TESTBOX_BASE_NAME}_${distro//el/rocky_}" >> $GITHUB_ENV
113+
echo "DISTRO_NUM=${distro##el}" >> $GITHUB_ENV
114+
env:
115+
platform: linux/${{ matrix.arch.name }}
116+
distro: ${{ matrix.distro }}
117+
118+
- name: Docker meta
119+
id: meta
120+
uses: docker/metadata-action@v5
121+
with:
122+
images: |
123+
ghcr.io/${{ env.TESTBOX_IMAGE_NAME }}
124+
tags: |
125+
type=raw,value=${{ env.TESTBOX_IMAGE_VERSION }}-${{ matrix.arch.name }}
126+
type=edge,enable=true,priority=700,prefix=,suffix=${{ matrix.arch.name }},branch=$repo.default_branch
127+
128+
- name: Login to GHCR
129+
uses: docker/login-action@v3
130+
with:
131+
registry: ghcr.io
132+
username: ${{ github.actor }}
133+
password: ${{ secrets.GITHUB_TOKEN }}
134+
135+
- name: Set up QEMU
136+
uses: docker/setup-qemu-action@v3
137+
138+
- name: Set up Docker Buildx
139+
uses: docker/setup-buildx-action@v3
140+
141+
- name: Build and push by tag
142+
id: build
143+
uses: docker/build-push-action@v6
144+
with:
145+
context: ./docker-images/testbox-distro-rocky-${{ env.DISTRO_NUM }}
146+
file: ./docker-images/testbox-distro-rocky-${{ env.DISTRO_NUM }}/Dockerfile
147+
platforms: linux/${{ matrix.arch.name }}
148+
labels: ${{ steps.meta.outputs.labels }}
149+
tags: ${{ steps.meta.outputs.tags }}
150+
outputs: "type=image,name=ghcr.io/${{ env.TESTBOX_IMAGE_NAME }},push-by-digest=false,name-canonical=true,push=true"
151+
152+
- name: Export digest
153+
run: |
154+
mkdir -p /tmp/digests
155+
digest="${{ steps.build.outputs.digest }}"
156+
touch "/tmp/digests/${digest#sha256:}"
157+
158+
- name: Upload digest
159+
uses: actions/upload-artifact@v4
160+
with:
161+
name: digests-distro-${{ matrix.distro }}-${{ env.PLATFORM_PAIR }}
162+
path: /tmp/digests/*
163+
if-no-files-found: error
164+
retention-days: 1

0 commit comments

Comments
 (0)