Skip to content

Commit 2a75182

Browse files
committed
Add GitHub workflow to auto update (rebuild & publish) containers
1 parent ed6569e commit 2a75182

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Periodically rebuild & publish containers (auto update)
2+
3+
on:
4+
schedule:
5+
# run once a day at 21:50 UTC
6+
- cron: '50 21 * * *'
7+
8+
concurrency: build
9+
10+
env:
11+
CI_TOOLS_SETUP: https://raw.githubusercontent.com/SGSGermany/ci-tools/main/setup.sh
12+
13+
defaults:
14+
run:
15+
shell: bash -eu -o pipefail {0}
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
env:
25+
REGISTRY: ghcr.io
26+
OWNER: sgsgermany
27+
IMAGE: butane
28+
29+
steps:
30+
- name: Setup CI tools
31+
run: |
32+
. <(curl -fsS -L "$CI_TOOLS_SETUP" | bash -s ~/ci-tools)
33+
echo "CI_TOOLS=$CI_TOOLS" | tee -a "$GITHUB_ENV"
34+
echo "CI_TOOLS_PATH=$CI_TOOLS_PATH" | tee -a "$GITHUB_ENV"
35+
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
39+
- name: Log into container registry ${{ env.REGISTRY }}
40+
uses: redhat-actions/podman-login@v1
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Generate container image tags
47+
run: |
48+
source <(./tags.sh "$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER")
49+
echo "MILESTONE=$MILESTONE" | tee -a "$GITHUB_ENV"
50+
echo "VERSION=$VERSION" | tee -a "$GITHUB_ENV"
51+
echo "TAGS=$TAGS" | tee -a "$GITHUB_ENV"
52+
53+
- name: Check for updates
54+
run: |
55+
BUILD_ACTION="$(./check-for-updates.sh)"
56+
echo "BUILD_ACTION=$BUILD_ACTION" | tee -a "$GITHUB_ENV"
57+
58+
- name: Build container image
59+
if: ${{ env.BUILD_ACTION != '' }}
60+
run: |
61+
buildah unshare ./build.sh
62+
63+
- name: Container image metadata
64+
run: |
65+
"$CI_TOOLS_PATH/containers/get-metadata.sh" "$REGISTRY/$OWNER" "$IMAGE:${TAGS%% *}"
66+
67+
- name: Push container image
68+
if: ${{ env.BUILD_ACTION != '' }}
69+
uses: redhat-actions/push-to-registry@v2
70+
with:
71+
image: ${{ env.IMAGE }}
72+
registry: ${{ env.REGISTRY }}/${{ env.OWNER }}
73+
tags: ${{ env.TAGS }}

check-for-updates.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Unbound
3+
# A container running Butane, a config translator for FCOS' Ignition.
4+
#
5+
# Copyright (c) 2025 SGS Serious Gaming & Simulations GmbH
6+
#
7+
# This work is licensed under the terms of the MIT license.
8+
# For a copy, see LICENSE file or <https://opensource.org/licenses/MIT>.
9+
#
10+
# SPDX-License-Identifier: MIT
11+
# License-Filename: LICENSE
12+
13+
set -eu -o pipefail
14+
export LC_ALL=C.UTF-8
15+
16+
[ -v CI_TOOLS ] && [ "$CI_TOOLS" == "SGSGermany" ] \
17+
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS' not set or invalid" >&2; exit 1; }
18+
19+
[ -v CI_TOOLS_PATH ] && [ -d "$CI_TOOLS_PATH" ] \
20+
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS_PATH' not set or invalid" >&2; exit 1; }
21+
22+
source "$CI_TOOLS_PATH/helper/common.sh.inc"
23+
source "$CI_TOOLS_PATH/helper/chkupd.sh.inc"
24+
source "$CI_TOOLS_PATH/helper/github.sh.inc"
25+
26+
BUILD_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
27+
source "$BUILD_DIR/container.env"
28+
29+
TAG="${TAGS%% *}"
30+
31+
# check whether the base image was updated
32+
chkupd_baseimage "$REGISTRY/$OWNER/$IMAGE" "$TAG" || exit 0
33+
34+
# check whether a different Git tag was marked as latest GitHub release
35+
GITHUB_REPO_IDENT="${BUTANE_GIT_REPO#https://github.com/}"
36+
GITHUB_LATEST_VERSION="$(github_latest "$GITHUB_REPO_IDENT")"
37+
38+
chkupd_image_version "$REGISTRY/$OWNER/$IMAGE:$TAG" \
39+
"${GITHUB_LATEST_VERSION#v}" \
40+
|| exit 0

0 commit comments

Comments
 (0)