105 lines
2.4 KiB
Bash
Executable file
105 lines
2.4 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
|
|
|
|
has() {
|
|
hash "$1" &>/dev/null
|
|
}
|
|
|
|
prompt() {
|
|
msg() {
|
|
local text=$1
|
|
local div_width="120"
|
|
printf "%${div_width}s\n" ' ' | tr ' ' -
|
|
printf "%s\n" "$text"
|
|
}
|
|
local question=$1
|
|
while true; do
|
|
msg "$question"
|
|
read -p "[y]es or [n]o (default: no) : " -r answer
|
|
case "$answer" in
|
|
y | Y | yes | YES | Yes)
|
|
return 0
|
|
;;
|
|
n | N | no | NO | No | *[[:blank:]]* | "")
|
|
return 1
|
|
;;
|
|
*)
|
|
msg "Please answer [y]es or [n]o."
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
if has podman; 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/rust-tcpaste-http
|
|
image_tags=(
|
|
"${image_uri}:${revision}"
|
|
"${image_uri}:${version}"
|
|
"${image_uri}:${branch}"
|
|
"${image_uri}:latest"
|
|
)
|
|
|
|
$RUNTIME build \
|
|
--file="${project_root}/oci/Containerfile.http" \
|
|
--label=org.opencontainers.image.title="tcp-pasted-http" \
|
|
--label=org.opencontainers.image.authors="Thorsten Schubert <tschubert@bafh.org>" \
|
|
--label=org.opencontainers.image.licenses="AGPL-3.0" \
|
|
--label=org.opencontainers.image.url="https://betaco.de/strom/tcpasters.git" \
|
|
--label=org.opencontainers.image.source="https://betaco.de/strom/tcpasters/raw/branch/main/oci/Containerfile.http" \
|
|
--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}:${revision}" \
|
|
"$project_root"
|
|
|
|
$RUNTIME tag "${image_tags[@]}"
|
|
|
|
if [[ -t 1 ]]; then
|
|
if ! prompt 'Push images to registry?'; then
|
|
exit 0
|
|
fi
|
|
if ! [[ -v AUTH_FILE && -r $AUTH_FILE ]]; then
|
|
printf 'Please set AUTH_FILE environment variable in order to push to the registry.\n'
|
|
exit 1
|
|
fi
|
|
|
|
for tag in "${image_tags[@]}"; do
|
|
$RUNTIME push --authfile="$AUTH_FILE" "${tag}"
|
|
done
|
|
fi
|
|
|
|
# vi: set ft=sh ts=4 sw=4 sts=-1 sr noet si tw=0 fdm=manual:
|