Improve/add initial project structure for ZomboidForge with build system, runtime, and patching logic.
Added version support for building images.
This commit is contained in:
1 parent
bf9228d2be
commit
015e9bb2c8
32 files changed
+1268
-58
No files matched your search
Executable
+139
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Builds the ZomboidForge image for one Project Zomboid version and optionally
|
||||
# publishes it. Published tags:
|
||||
#
|
||||
# <forge>-pz<pz>-build<steam_buildid> immutable; never overwritten
|
||||
# <forge>-pz<pz> moves to the newest Steam build of that version
|
||||
# latest only with LATEST=true
|
||||
#
|
||||
# Nothing is built when the immutable tag already exists in the registry.
|
||||
#
|
||||
# Environment:
|
||||
# IMAGE Image name without tag, e.g. git.security-command.org/overlord/zomboidforge
|
||||
# PZ_BRANCH Steam branch. Default: public
|
||||
# PZ_VERSION Expected Project Zomboid version. Default: pz.version in gradle.properties
|
||||
# PUBLISH true: push the tags. Default: false (build and verify only)
|
||||
# LATEST true: also push "latest". Default: false
|
||||
# CONTAINER_ENGINE docker or podman. Default: docker if installed, else podman
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
readonly REPO_ROOT
|
||||
|
||||
readonly IMAGE="${IMAGE:?IMAGE is required}"
|
||||
readonly PZ_BRANCH="${PZ_BRANCH:-public}"
|
||||
readonly PUBLISH="${PUBLISH:-false}"
|
||||
readonly LATEST="${LATEST:-false}"
|
||||
|
||||
log() {
|
||||
echo "[release] $*" >&2
|
||||
}
|
||||
|
||||
container_engine() {
|
||||
if [[ -n "${CONTAINER_ENGINE:-}" ]]; then
|
||||
echo "${CONTAINER_ENGINE}"
|
||||
elif command -v docker > /dev/null; then
|
||||
echo "docker"
|
||||
else
|
||||
echo "podman"
|
||||
fi
|
||||
}
|
||||
|
||||
# Prints the value of <key>=<value> in gradle.properties.
|
||||
gradle_property() {
|
||||
local key="$1"
|
||||
local line
|
||||
|
||||
while IFS= read -r line; do
|
||||
if [[ "${line}" == "${key}="* ]]; then
|
||||
echo "${line#*=}"
|
||||
return
|
||||
fi
|
||||
done < "${REPO_ROOT}/gradle.properties"
|
||||
|
||||
log "${key} not found in gradle.properties"
|
||||
exit 1
|
||||
}
|
||||
|
||||
image_exists() {
|
||||
local reference="$1"
|
||||
"$(container_engine)" manifest inspect "${reference}" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
build_image() {
|
||||
local reference="$1"
|
||||
local forge_version="$2"
|
||||
local pz_version="$3"
|
||||
local build_id="$4"
|
||||
|
||||
"$(container_engine)" build \
|
||||
--platform linux/amd64 \
|
||||
--build-arg "PZ_BRANCH=${PZ_BRANCH}" \
|
||||
--build-arg "PZ_VERSION=${pz_version}" \
|
||||
--build-arg "FORGE_VERSION=${forge_version}" \
|
||||
--build-arg "STEAM_BUILDID=${build_id}" \
|
||||
--tag "${reference}" \
|
||||
"${REPO_ROOT}"
|
||||
}
|
||||
|
||||
# Steam can publish a new build between the build ID lookup and the download.
|
||||
verify_build_id() {
|
||||
local reference="$1"
|
||||
local expected="$2"
|
||||
local actual
|
||||
|
||||
actual="$("$(container_engine)" run --rm --entrypoint cat "${reference}" /opt/pz/steam-buildid)"
|
||||
if [[ "${actual}" != "${expected}" ]]; then
|
||||
log "Image contains Steam build ${actual}, expected ${expected}; Steam updated during the build."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
push_as() {
|
||||
local source="$1"
|
||||
local target="$2"
|
||||
|
||||
"$(container_engine)" tag "${source}" "${target}"
|
||||
"$(container_engine)" push "${target}"
|
||||
log "Pushed ${target}"
|
||||
}
|
||||
|
||||
main() {
|
||||
local forge_version
|
||||
local pz_version
|
||||
local build_id
|
||||
|
||||
forge_version="$(gradle_property version)"
|
||||
pz_version="${PZ_VERSION:-$(gradle_property pz.version)}"
|
||||
build_id="$("${REPO_ROOT}/ci/steam-buildid.sh" "${PZ_BRANCH}")"
|
||||
|
||||
local immutable_tag="${IMAGE}:${forge_version}-pz${pz_version}-build${build_id}"
|
||||
local version_tag="${IMAGE}:${forge_version}-pz${pz_version}"
|
||||
log "ZomboidForge ${forge_version}, Project Zomboid ${pz_version}, Steam branch ${PZ_BRANCH} build ${build_id}"
|
||||
|
||||
if [[ "${PUBLISH}" == true ]] && image_exists "${immutable_tag}"; then
|
||||
log "${immutable_tag} is already published; nothing to do."
|
||||
return
|
||||
fi
|
||||
|
||||
build_image "${immutable_tag}" "${forge_version}" "${pz_version}" "${build_id}"
|
||||
verify_build_id "${immutable_tag}" "${build_id}"
|
||||
|
||||
if [[ "${PUBLISH}" != true ]]; then
|
||||
log "Built ${immutable_tag} (PUBLISH is not true; nothing pushed)"
|
||||
return
|
||||
fi
|
||||
|
||||
"$(container_engine)" push "${immutable_tag}"
|
||||
log "Pushed ${immutable_tag}"
|
||||
push_as "${immutable_tag}" "${version_tag}"
|
||||
if [[ "${LATEST}" == true ]]; then
|
||||
push_as "${immutable_tag}" "${IMAGE}:latest"
|
||||
fi
|
||||
}
|
||||
|
||||
main
|
||||
Reference in new issue
Block a user