Skip to content

Commit ed6569e

Browse files
committed
Add GitHub workflow to build & publish container to ghcr.io
1 parent 4b6fbd4 commit ed6569e

3 files changed

Lines changed: 132 additions & 4 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build & publish container
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch: {}
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: Build container image
54+
run: |
55+
buildah unshare ./build.sh
56+
57+
- name: Container image metadata
58+
run: |
59+
podman image inspect "localhost/$IMAGE:${TAGS%% *}"
60+
61+
- name: Push container image
62+
uses: redhat-actions/push-to-registry@v2
63+
with:
64+
image: ${{ env.IMAGE }}
65+
registry: ${{ env.REGISTRY }}/${{ env.OWNER }}
66+
tags: ${{ env.TAGS }}

container.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
REGISTRY="ghcr.io"
2-
OWNER="sgsgermany"
3-
IMAGE="butane"
4-
TAGS="latest"
1+
REGISTRY="${REGISTRY:-ghcr.io}"
2+
OWNER="${OWNER:-sgsgermany}"
3+
IMAGE="${IMAGE:-butane}"
4+
TAGS="${TAGS:-latest}"
55

66
BUTANE_GIT_REPO="https://github.com/coreos/butane"
77
BUTANE_BINARY_URL="$BUTANE_GIT_REPO/releases/latest/download/butane-x86_64-unknown-linux-gnu"

tags.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/github.sh.inc"
24+
25+
BUILD_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
26+
source "$BUILD_DIR/container.env"
27+
28+
BUILD_INFO=""
29+
if [ $# -gt 0 ] && [[ "$1" =~ ^[a-zA-Z0-9_.-]+$ ]]; then
30+
BUILD_INFO=".${1,,}"
31+
fi
32+
33+
# get latest Butane version
34+
GITHUB_REPO_IDENT="${BUTANE_GIT_REPO#https://github.com/}"
35+
VERSION="$(github_latest "$GITHUB_REPO_IDENT")"
36+
37+
if [ -z "$VERSION" ]; then
38+
echo "Unable to read Butane version from GitHub API" >&2
39+
exit 1
40+
elif ! [[ "$VERSION" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)([+~-]|$) ]]; then
41+
echo "Unable to read Butane version from GitHub API: '$VERSION' is no valid version" >&2
42+
exit 1
43+
fi
44+
45+
VERSION_FULL="${VERSION:1}"
46+
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
47+
VERSION_MINOR="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
48+
VERSION_MAJOR="${BASH_REMATCH[1]}"
49+
50+
# build tags
51+
BUILD_INFO="$(date --utc +'%Y%m%d')$BUILD_INFO"
52+
53+
TAGS=(
54+
"v$VERSION" "v$VERSION-$BUILD_INFO"
55+
"v$VERSION_MINOR" "v$VERSION_MINOR-$BUILD_INFO"
56+
"v$VERSION_MAJOR" "v$VERSION_MAJOR-$BUILD_INFO"
57+
"latest"
58+
)
59+
60+
printf 'MILESTONE="%s"\n' "$VERSION_MINOR"
61+
printf 'VERSION="%s"\n' "$VERSION_FULL"
62+
printf 'TAGS="%s"\n' "${TAGS[*]}"

0 commit comments

Comments
 (0)