Make deploy build script container-engine aware

This commit is contained in:
Tero Halla-aho 2025-12-21 22:04:56 +02:00
parent 8c92385885
commit beb60966d4

View file

@ -3,6 +3,7 @@ set -euo pipefail
cd "$(dirname "$0")/.."
source deploy/env.sh
CONTAINER_TOOL="${CONTAINER_TOOL:-}"
AGE_KEY_FILE_CANDIDATES=(
"${SOPS_AGE_KEY_FILE:-}"
@ -34,14 +35,34 @@ require_cmd() {
}
check_docker() {
if [[ -n "${SKIP_DOCKER_CHECK:-}" ]]; then
echo "Deprecated: check_docker is kept for compatibility. Use check_container_engine instead." >&2
check_container_engine
}
check_container_engine() {
if [[ -n "${SKIP_DOCKER_CHECK:-}" || -n "${SKIP_CONTAINER_BUILD:-}" ]]; then
return
fi
require_cmd docker
if ! docker info >/dev/null 2>&1; then
echo "Docker is installed but the daemon is not reachable. Start Docker Desktop/Engine and try again." >&2
if [[ -n "$CONTAINER_TOOL" ]]; then
require_cmd "$CONTAINER_TOOL"
if "$CONTAINER_TOOL" info >/dev/null 2>&1; then
return
fi
echo "$CONTAINER_TOOL is installed but the daemon/service is not reachable. Start it or choose another engine via CONTAINER_TOOL." >&2
exit 1
fi
for candidate in docker podman nerdctl; do
if command -v "$candidate" >/dev/null 2>&1 && "$candidate" info >/dev/null 2>&1; then
CONTAINER_TOOL="$candidate"
export CONTAINER_TOOL
return
fi
done
echo "No working container engine found (checked docker, podman, nerdctl). Start one or set CONTAINER_TOOL to a reachable engine." >&2
exit 1
}
check_age_setup() {
@ -102,7 +123,7 @@ echo "Running pre-flight checks..."
for tool in git npm; do
require_cmd "$tool"
done
check_docker
check_container_engine
check_age_setup
if [[ -z "${SKIP_DB_MIGRATION_CHECK:-}" ]]; then
if command -v npx >/dev/null 2>&1; then
@ -132,12 +153,21 @@ echo "Building image:"
echo " $IMAGE"
echo " $IMAGE_LATEST"
if [[ -z "${SKIP_NPM_AUDIT:-}" ]]; then
# npm audit (high severity and above)
echo "Running npm audit (high)..."
npm audit --audit-level=high || echo "npm audit reported issues above."
else
echo "Skipping npm audit (SKIP_NPM_AUDIT set)."
fi
if [[ -n "${SKIP_CONTAINER_BUILD:-}" ]]; then
echo "Skipping container build (SKIP_CONTAINER_BUILD set)."
exit 0
fi
# Build
docker build --build-arg APP_VERSION="$GIT_SHA" -t "$IMAGE" -t "$IMAGE_LATEST" .
"${CONTAINER_TOOL:-docker}" build --build-arg APP_VERSION="$GIT_SHA" -t "$IMAGE" -t "$IMAGE_LATEST" .
echo "$IMAGE" > deploy/.last-image