-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub workflow to auto update (rebuild & publish) containers
- Loading branch information
1 parent
0cdd8c5
commit 0af82ca
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Periodically rebuild & publish containers (auto update) | ||
|
||
on: | ||
schedule: | ||
# run once a day at 22:20 UTC | ||
- cron: '20 22 * * *' | ||
|
||
concurrency: build | ||
|
||
env: | ||
CI_TOOLS_SETUP: https://raw.githubusercontent.com/SGSGermany/ci-tools/main/setup.sh | ||
|
||
defaults: | ||
run: | ||
shell: bash -eu -o pipefail {0} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
OWNER: sgsgermany | ||
IMAGE: selfoss | ||
|
||
steps: | ||
- name: Setup CI tools | ||
run: | | ||
. <(curl -fsS -L "$CI_TOOLS_SETUP" | bash -s ~/ci-tools) | ||
echo "CI_TOOLS=$CI_TOOLS" | tee -a "$GITHUB_ENV" | ||
echo "CI_TOOLS_PATH=$CI_TOOLS_PATH" | tee -a "$GITHUB_ENV" | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log into container registry ${{ env.REGISTRY }} | ||
uses: redhat-actions/podman-login@v1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Generate container image tags | ||
run: | | ||
source <(./tags.sh "$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER") | ||
echo "VERSION=$VERSION" | tee -a "$GITHUB_ENV" | ||
echo "HASH=$HASH" | tee -a "$GITHUB_ENV" | ||
echo "TAGS=$TAGS" | tee -a "$GITHUB_ENV" | ||
- name: Check for updates | ||
run: | | ||
BUILD_ACTION="$(./check-for-updates.sh)" | ||
echo "BUILD_ACTION=$BUILD_ACTION" | tee -a "$GITHUB_ENV" | ||
- name: Build container image | ||
if: ${{ env.BUILD_ACTION != '' }} | ||
run: | | ||
buildah unshare ./build.sh | ||
- name: Container image metadata | ||
run: | | ||
"$CI_TOOLS_PATH/containers/get-metadata.sh" "$REGISTRY/$OWNER" "$IMAGE:${TAGS%% *}" | ||
- name: Push container image | ||
if: ${{ env.BUILD_ACTION != '' }} | ||
uses: redhat-actions/push-to-registry@v2 | ||
with: | ||
image: ${{ env.IMAGE }} | ||
registry: ${{ env.REGISTRY }}/${{ env.OWNER }} | ||
tags: ${{ env.TAGS }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
# Selfoss | ||
# A php-fpm container running Selfoss, a RSS reader and feed aggregator. | ||
# | ||
# Copyright (c) 2023 SGS Serious Gaming & Simulations GmbH | ||
# | ||
# This work is licensed under the terms of the MIT license. | ||
# For a copy, see LICENSE file or <https://opensource.org/licenses/MIT>. | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# License-Filename: LICENSE | ||
|
||
set -eu -o pipefail | ||
export LC_ALL=C.UTF-8 | ||
|
||
[ -v CI_TOOLS ] && [ "$CI_TOOLS" == "SGSGermany" ] \ | ||
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS' not set or invalid" >&2; exit 1; } | ||
|
||
[ -v CI_TOOLS_PATH ] && [ -d "$CI_TOOLS_PATH" ] \ | ||
|| { echo "Invalid build environment: Environment variable 'CI_TOOLS_PATH' not set or invalid" >&2; exit 1; } | ||
|
||
source "$CI_TOOLS_PATH/helper/common.sh.inc" | ||
source "$CI_TOOLS_PATH/helper/common-traps.sh.inc" | ||
source "$CI_TOOLS_PATH/helper/git.sh.inc" | ||
source "$CI_TOOLS_PATH/helper/chkupd.sh.inc" | ||
|
||
BUILD_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" | ||
source "$BUILD_DIR/container.env" | ||
|
||
TAG="${TAGS%% *}" | ||
|
||
# check whether the base image was updated | ||
chkupd_baseimage "$REGISTRY/$OWNER/$IMAGE" "$TAG" || exit 0 | ||
|
||
# check whether the image is using the latest Selfoss dev version | ||
if [ -z "${VERSION:-}" ]; then | ||
# check whether the Git repository indicates a new version | ||
echo + "SOURCE_DIR=\"\$(mktemp -d)\"" >&2 | ||
SOURCE_DIR="$(mktemp -d)" | ||
|
||
trap_exit rm -rf "$SOURCE_DIR" | ||
|
||
git_clone "$GIT_REPO" "$GIT_REF" \ | ||
"$SOURCE_DIR" "$SOURCE_DIR" | ||
|
||
echo + "VERSION=\"\$(jq -re '.ver | sub(\"(-SNAPSHOT|-[0-9a-f]+)$\"; \"\")' -C $(quote "$SOURCE_DIR/package.json")\"" >&2 | ||
VERSION="$(jq -re '.ver | sub("(-SNAPSHOT|-[0-9a-f]+)$"; "")' "$SOURCE_DIR/package.json")" | ||
|
||
if [ -z "$VERSION" ]; then | ||
echo "Unable to read Selfoss version from '$SOURCE_DIR/package.json': Version not found" >&2 | ||
exit 1 | ||
elif ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then | ||
echo "Unable to read Selfoss version from '$SOURCE_DIR/package.json': '$VERSION' is no valid version" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo + "HASH_SHORT=\"\$(git -C $(quote "$SOURCE_DIR") rev-parse --short HEAD)\"" >&2 | ||
HASH_SHORT="$(git -C "$SOURCE_DIR" rev-parse --short HEAD)" | ||
|
||
echo + "VERSION=\"$VERSION-$HASH_SHORT\"" >&2 | ||
VERSION="$VERSION-$HASH_SHORT" | ||
fi | ||
|
||
chkupd_image_version "$REGISTRY/$OWNER/$IMAGE:$TAG" "$VERSION" || exit 0 |