tcpasters/oci/build.sh
Thorsten Schubert 3a9b9b748f
All checks were successful
/ build (push) Successful in 2m48s
Renovate container build script
2024-08-16 16:07:44 +02:00

92 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# shellcheck shell=bash
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright © 2022 Thorsten Schubert <tschubert@bafh.org>
set -eo pipefail
shopt -s nullglob
if (($# < 1)); then
echo "Usage: $0 <httpd|pasted> [--tag-all]" >&2
exit 1
fi
BUILD_TYPE="$1"
shift
if [[ $BUILD_TYPE != "httpd" && $BUILD_TYPE != "pasted" ]]; then
echo "Invalid build type. Use 'http' or 'pasted'." >&2
exit 1
fi
extra_args="build-${BUILD_TYPE}.sh.in"
if [[ -f $extra_args ]]; then
# shellcheck disable=1090
source "$extra_args"
fi
if hash podman &>/dev/null; then
RUNTIME=podman
else
RUNTIME=docker
fi
branch=$(git branch --show-current)
project_root=$(git rev-parse --show-toplevel)
revision=$(git rev-parse HEAD)
timestamp=$(date --rfc-3339=seconds)
vcs_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
version="${vcs_tag}-$(git rev-parse --short HEAD)"
while read -r var; do
if [[ -z ${!var} ]]; then
printf "%s empty or not set\n" "$var" >&2
exit 1
fi
done <<EOF
branch
project_root
revision
timestamp
vcs_tag
EOF
image_uri="betaco.de/strom/tcpasters-${BUILD_TYPE}"
declare -a image_tags
if [[ $1 == "--tag-all" ]]; then
image_tags+=(
"${image_uri}:${revision}"
"${image_uri}:${version}"
"${image_uri}:${branch}"
)
fi
build_args=(
--file="${project_root}/oci/Containerfile.${BUILD_TYPE}"
--label=org.opencontainers.image.title="tcpasters-${BUILD_TYPE}"
--label=org.opencontainers.image.authors="Thorsten Schubert <tschubert@bafh.org>"
--label=org.opencontainers.image.licenses="AGPL-3.0"
--label=org.opencontainers.image.url="https://${image_uri}.git"
--label=org.opencontainers.image.source="https://${image_uri}/raw/branch/main/oci/Containerfile.${BUILD_TYPE}"
--label=org.opencontainers.image.created="$timestamp"
--label=org.opencontainers.image.revision="$revision"
--label=org.opencontainers.image.version="$version"
--build-arg="PUID=${PUID:-1000}"
--build-arg="PGID=${PGID:-1000}"
--tag="${image_uri}:latest"
)
if [[ -v EXTRA_BUILD_ARGS ]]; then
build_args+=("${EXTRA_BUILD_ARGS[@]}")
fi
$RUNTIME build "${build_args[@]}" "$project_root"
if ((${#image_tags[@]} > 0)); then
$RUNTIME tag "${image_tags[@]}"
fi
# vi: set ft=sh ts=4 sw=4 sts=-1 sr noet si tw=0 fdm=manual: