Skip to content

Commit 3a5b5f4

Browse files
committed
Added GitHub Actions workflow for building base images
Manually triggered workflow that builds and pushes container images to ghcr.io. Builds all platforms in parallel via a matrix strategy. Ticket: ENT-13784 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent 1859e0c commit 3a5b5f4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build base images
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-and-push:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
packages: write
11+
strategy:
12+
matrix:
13+
platform:
14+
- ubuntu-20
15+
- ubuntu-22
16+
- ubuntu-24
17+
- debian-11
18+
- debian-12
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v6
22+
23+
- name: Log in to ghcr.io
24+
uses: docker/login-action@v4
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build and push image
31+
run: ./build-in-container.py --platform ${{ matrix.platform }} --push-image

build-in-container.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,25 @@ def pull_image(platform_name):
152152
return ref
153153

154154

155+
def image_exists_in_registry(platform_name):
156+
"""Check if an image tag already exists in the registry."""
157+
ref = registry_image_ref(platform_name)
158+
result = subprocess.run(
159+
["docker", "manifest", "inspect", ref],
160+
capture_output=True,
161+
text=True,
162+
)
163+
return result.returncode == 0
164+
165+
155166
def push_image(platform_name, local_tag):
156167
"""Tag a local image with the registry reference and push it."""
157168
ref = registry_image_ref(platform_name)
169+
170+
if image_exists_in_registry(platform_name):
171+
log.error(f"Image {ref} already exists. Bump IMAGE_VERSION.")
172+
sys.exit(1)
173+
158174
log.info(f"Tagging {local_tag} as {ref}...")
159175
result = subprocess.run(["docker", "tag", local_tag, ref])
160176
if result.returncode != 0:

0 commit comments

Comments
 (0)