From c216d9f691b227bbb868c02ae1b0ddbf577ea2ae Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Wed, 4 Nov 2026 19:23:01 +0100 Subject: [PATCH 1/2] Add script to build and push images without GitHub Actions bin/build-and-push.sh builds the images on a workstation the way the build workflow does: from the latest release tag, for linux/amd64 and linux/arm64, with the same tags and labels. The PHP branches are read from the workflow of that tag, and the PHP version of each is taken from the version label of the newest harbor.flownative.io/docker/php image, as flownative/action-docker-get-label does. Without options it only shows the plan; --build builds without pushing, --push builds and pushes after a confirmation. Refs OPS-8S Co-Authored-By: Claude Opus 5.5 --- README.md | 26 +++++ bin/build-and-push.sh | 243 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100755 bin/build-and-push.sh diff --git a/README.md b/README.md index d025c2d..8190fd7 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,32 @@ docker build \ -t flownative/beach-php:8.3.11 . ``` +### Building without GitHub Actions + +If GitHub Actions is not available, `bin/build-and-push.sh` builds the +images on a workstation the way the build workflow does: from the latest +release tag, for `linux/amd64` and `linux/arm64`, with the same tags and +labels. The PHP branches come from `.github/workflows/docker.build.yaml` +of that tag, and each image is based on the newest +`harbor.flownative.io/docker/php` image of its branch, so rebuild +[docker-php](https://github.com/flownative/docker-php) first if needed. + +```bash +docker login +docker login harbor.flownative.io + +bin/build-and-push.sh # show what would be built +bin/build-and-push.sh --push # build and push all PHP branches +bin/build-and-push.sh --push --php 8.4 # only one PHP branch +``` + +`--build` builds without pushing, `--ref ` builds another tag, and +`--no-cache` builds from scratch. See `bin/build-and-push.sh --help`. + +The script triggers neither `docker-beach-php-k8s` nor +`versions.flownative.io`. Run the script of the same name in +`docker-beach-php-k8s` once the images are pushed. + ## Testing this image The workflow `.github/workflows/docker.test.yaml` builds the image for diff --git a/bin/build-and-push.sh b/bin/build-and-push.sh new file mode 100755 index 0000000..d4c90c0 --- /dev/null +++ b/bin/build-and-push.sh @@ -0,0 +1,243 @@ +#!/usr/bin/env bash +# +# Builds the Beach PHP images on a workstation the way the GitHub workflow +# .github/workflows/docker.build.yaml does, and optionally pushes them. +# Meant for the case that GitHub Actions is not available. +# +# Runs with the Bash 3.2 that ships with macOS. + +set -euo pipefail + +IMAGES="flownative/beach-php harbor.flownative.io/docker/beach-php" +BASE_IMAGE="harbor.flownative.io/docker/php" +PLATFORMS="linux/amd64,linux/arm64" +SOURCE_URL="https://github.com/flownative/docker-beach-php" +WORKFLOW_FILE=".github/workflows/docker.build.yaml" +NEXT_STEPS="Images derived from these need to be rebuilt next: + docker-beach-php-k8s +Run bin/build-and-push.sh --push there. + +versions.flownative.io is not notified; update it by hand if needed." + +usage() { + cat < Only build this PHP branch, e.g. 8.4 + --ref Build this Git tag instead of the latest release tag + --build Build all platforms, but do not push (e.g. to measure) + --push Build and push to Docker Hub and Harbor + --builder Buildx builder to use (default: flownative, created if missing) + --no-cache Build from scratch + --yes Do not ask before pushing + -h, --help Show this help + +Log in first: + docker login + docker login harbor.flownative.io +EOF +} + +info() { printf '\033[1m%s\033[0m\n' "$*"; } +warn() { printf '\033[33mWarning: %s\033[0m\n' "$*" >&2; } +fail() { printf '\033[31mError: %s\033[0m\n' "$*" >&2; exit 1; } + +php_filter="" +ref="" +mode="plan" +builder="flownative" +assume_yes=false +use_cache=true + +while [ $# -gt 0 ]; do + case "$1" in + --php) php_filter="${2:?--php needs a PHP branch}"; shift 2 ;; + --ref) ref="${2:?--ref needs a tag}"; shift 2 ;; + --build) mode="build"; shift ;; + --push) mode="push"; shift ;; + --builder) builder="${2:?--builder needs a name}"; shift 2 ;; + --yes) assume_yes=true; shift ;; + --no-cache) use_cache=false; shift ;; + -h|--help) usage; exit 0 ;; + *) usage >&2; echo >&2; fail "Unknown option: $1" ;; + esac +done + +command -v docker >/dev/null || fail "docker is not installed" +docker buildx version >/dev/null 2>&1 || fail "docker buildx is not available" + +repository_root="$(cd "$(dirname "$0")/.." && git rev-parse --show-toplevel)" + +# --- Source ------------------------------------------------------------------- + +# GitHub may be the very thing that is down, so local tags have to do then. +if ! git -C "${repository_root}" fetch --quiet --tags --force origin 2>/dev/null; then + warn "Could not fetch tags from origin, using the tags known locally" +fi + +if [ -z "${ref}" ]; then + ref="$(git -C "${repository_root}" tag --list 'v*.*.*' --sort=-v:refname | head -n 1)" + [ -n "${ref}" ] || fail "No release tag found" +fi +git -C "${repository_root}" rev-parse --verify --quiet "${ref}^{commit}" >/dev/null \ + || fail "Unknown ref: ${ref}" + +work_directory="$(mktemp -d)" +worktree="${work_directory}/source" +cleanup() { + git -C "${repository_root}" worktree remove --force "${worktree}" 2>/dev/null || true + rm -rf "${work_directory}" +} +trap cleanup EXIT + +git -C "${repository_root}" worktree add --quiet --detach "${worktree}" "${ref}" +revision="$(git -C "${worktree}" rev-parse HEAD)" +created="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + +# --- Versions ----------------------------------------------------------------- + +# The matrix line looks like: php: [ "8.2", "8.3", "8.4", "8.5" ] +matrix="$(sed -n 's/^[[:space:]]*php:[[:space:]]*\[\(.*\)\].*$/\1/p' "${worktree}/${WORKFLOW_FILE}" | head -n 1 | tr -d '"'"'" | tr ',' ' ' | tr -s ' ' | sed 's/^ //; s/ $//')" +[ -n "${matrix}" ] || fail "No PHP branches found in ${WORKFLOW_FILE} of ${ref}" + +branches="" +for branch in ${matrix}; do + echo "${branch}" | grep -Eq '^[0-9]+\.[0-9]+$' \ + || fail "Unexpected PHP branch '${branch}' in ${WORKFLOW_FILE}" + if [ -z "${php_filter}" ] || [ "${php_filter}" = "${branch}" ]; then + branches="${branches} ${branch}" + fi +done +[ -n "${branches}" ] || fail "PHP ${php_filter} is not built by ${ref} (available: ${matrix})" + +# Like flownative/action-docker-get-label: the PHP version is the one of the +# newest PHP image of that branch. +latest_php_version() { + docker buildx imagetools inspect "${BASE_IMAGE}:$1" \ + --format '{{ index (index .Image "linux/amd64").Config.Labels "org.opencontainers.image.version" }}' 2>/dev/null +} + +versions="" +for branch in ${branches}; do + version="$(latest_php_version "${branch}")" \ + || fail "Could not read ${BASE_IMAGE}:${branch}; are you logged in (docker login harbor.flownative.io)?" + echo "${version}" | grep -Eq "^${branch//./\\.}\.[0-9]+$" \ + || fail "${BASE_IMAGE}:${branch} has an unexpected version label: '${version}'" + versions="${versions} ${version}" +done + +tags_for() { + local version="$1" image + for image in ${IMAGES}; do + echo "${image}:${version%.*}" + echo "${image}:${version}" + done +} + +# --- Plan --------------------------------------------------------------------- + +info "Source: ${ref} (${revision})" +info "Platforms: ${PLATFORMS}" +info "Mode: ${mode}" +info "Cache: ${use_cache}" +for version in ${versions}; do + echo + info "PHP ${version} (from ${BASE_IMAGE}:${version})" + tags_for "${version}" | sed 's/^/ /' +done +echo + +if [ "${mode}" = "plan" ]; then + echo "Nothing was built. Use --build to build or --push to build and push." + exit 0 +fi + +# --- Preconditions ------------------------------------------------------------ + +if [ "${mode}" = "push" ]; then + docker_config="${DOCKER_CONFIG:-${HOME}/.docker}/config.json" + for registry in "https://index.docker.io/v1/" "harbor.flownative.io"; do + grep -q "\"${registry}\"" "${docker_config}" 2>/dev/null \ + || fail "Not logged in to ${registry}, run: docker login ${registry#https://index.docker.io/v1/}" + done + + if [ "${assume_yes}" != true ]; then + [ -t 0 ] || fail "Refusing to push without confirmation, pass --yes" + read -r -p "Push these images to Docker Hub and Harbor? [y/N] " answer + case "${answer}" in + y|Y|yes) ;; + *) echo "Aborted."; exit 1 ;; + esac + fi +fi + +if ! docker buildx inspect "${builder}" >/dev/null 2>&1; then + info "Creating buildx builder ${builder}" + docker buildx create --name "${builder}" --driver docker-container --bootstrap >/dev/null +fi + +# --- Build -------------------------------------------------------------------- + +summary="" +for version in ${versions}; do + metadata_file="${work_directory}/metadata-${version}.json" + + # --pull, because the nightly builds of docker-php replace the image + # behind the same tag. + arguments=( + --builder "${builder}" + --platform "${PLATFORMS}" + --pull + --build-arg "PHP_BASE_IMAGE=${BASE_IMAGE}:${version}" + --label "org.opencontainers.image.title=Beach PHP" + --label "org.opencontainers.image.description=Docker image providing PHP for Beach and Local Beach" + --label "org.opencontainers.image.licenses=MIT" + --label "org.opencontainers.image.vendor=Flownative GmbH" + --label "org.opencontainers.image.authors=Robert Lemke " + --label "org.opencontainers.image.version=${version}" + --label "org.opencontainers.image.created=${created}" + --label "org.opencontainers.image.revision=${revision}" + --label "org.opencontainers.image.source=${SOURCE_URL}" + --label "org.opencontainers.image.url=${SOURCE_URL}" + --metadata-file "${metadata_file}" + ) + if [ "${use_cache}" != true ]; then + arguments+=(--no-cache) + fi + for tag in $(tags_for "${version}"); do + arguments+=(--tag "${tag}") + done + if [ "${mode}" = "push" ]; then + # Like docker/build-push-action does for public repositories + arguments+=(--push --provenance "mode=max") + fi + + info "Building PHP ${version}" + started=${SECONDS} + if ! docker buildx build "${arguments[@]}" "${worktree}"; then + fail "Build of PHP ${version} failed after $(( (SECONDS - started) / 60 )) min" + fi + duration=$(( SECONDS - started )) + + digest="$(sed -n 's/.*"containerimage\.digest":[[:space:]]*"\([^"]*\)".*/\1/p' "${metadata_file}" | head -n 1)" + summary="${summary}$(printf ' PHP %-8s %3d min %02d s %s' "${version}" $((duration / 60)) $((duration % 60)) "${digest}") +" +done + +# --- Summary ------------------------------------------------------------------ + +echo +info "Done (${mode})" +printf '%s' "${summary}" +if [ "${mode}" = "push" ]; then + echo + echo "${NEXT_STEPS}" +fi From 0f3a18436fe70fbd7d248a31fb6367672916a30b Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Thu, 5 Nov 2026 09:10:54 +0100 Subject: [PATCH 2/2] Read the build matrix from main, like the workflow On GitHub the matrix comes from the workflow on main, while the code is the one of the latest release tag. The script read the matrix from the workflow of the tag instead, so a version entered on main but not yet tagged was built by the workflow but not by the script. Refs OPS-8S Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- bin/build-and-push.sh | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8190fd7..9715303 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ If GitHub Actions is not available, `bin/build-and-push.sh` builds the images on a workstation the way the build workflow does: from the latest release tag, for `linux/amd64` and `linux/arm64`, with the same tags and labels. The PHP branches come from `.github/workflows/docker.build.yaml` -of that tag, and each image is based on the newest +on `main`, and each image is based on the newest `harbor.flownative.io/docker/php` image of its branch, so rebuild [docker-php](https://github.com/flownative/docker-php) first if needed. diff --git a/bin/build-and-push.sh b/bin/build-and-push.sh index d4c90c0..50ffcc9 100755 --- a/bin/build-and-push.sh +++ b/bin/build-and-push.sh @@ -13,6 +13,9 @@ BASE_IMAGE="harbor.flownative.io/docker/php" PLATFORMS="linux/amd64,linux/arm64" SOURCE_URL="https://github.com/flownative/docker-beach-php" WORKFLOW_FILE=".github/workflows/docker.build.yaml" +# Like on GitHub, the matrix comes from the workflow on main, while the +# code is the one of the latest release tag. +WORKFLOW_REF="origin/main" NEXT_STEPS="Images derived from these need to be rebuilt next: docker-beach-php-k8s Run bin/build-and-push.sh --push there. @@ -101,12 +104,15 @@ trap cleanup EXIT git -C "${repository_root}" worktree add --quiet --detach "${worktree}" "${ref}" revision="$(git -C "${worktree}" rev-parse HEAD)" created="$(date -u +%Y-%m-%dT%H:%M:%SZ)" +workflow="${work_directory}/workflow.yaml" +git -C "${repository_root}" show "${WORKFLOW_REF}:${WORKFLOW_FILE}" > "${workflow}" \ + || fail "Could not read ${WORKFLOW_FILE} from ${WORKFLOW_REF}" # --- Versions ----------------------------------------------------------------- # The matrix line looks like: php: [ "8.2", "8.3", "8.4", "8.5" ] -matrix="$(sed -n 's/^[[:space:]]*php:[[:space:]]*\[\(.*\)\].*$/\1/p' "${worktree}/${WORKFLOW_FILE}" | head -n 1 | tr -d '"'"'" | tr ',' ' ' | tr -s ' ' | sed 's/^ //; s/ $//')" -[ -n "${matrix}" ] || fail "No PHP branches found in ${WORKFLOW_FILE} of ${ref}" +matrix="$(sed -n 's/^[[:space:]]*php:[[:space:]]*\[\(.*\)\].*$/\1/p' "${workflow}" | head -n 1 | tr -d '"'"'" | tr ',' ' ' | tr -s ' ' | sed 's/^ //; s/ $//')" +[ -n "${matrix}" ] || fail "No PHP branches found in ${WORKFLOW_FILE} of ${WORKFLOW_REF}" branches="" for branch in ${matrix}; do @@ -116,7 +122,7 @@ for branch in ${matrix}; do branches="${branches} ${branch}" fi done -[ -n "${branches}" ] || fail "PHP ${php_filter} is not built by ${ref} (available: ${matrix})" +[ -n "${branches}" ] || fail "PHP ${php_filter} is not built according to ${WORKFLOW_REF} (available: ${matrix})" # Like flownative/action-docker-get-label: the PHP version is the one of the # newest PHP image of that branch. @@ -145,6 +151,7 @@ tags_for() { # --- Plan --------------------------------------------------------------------- info "Source: ${ref} (${revision})" +info "Matrix: ${WORKFLOW_FILE} on ${WORKFLOW_REF}" info "Platforms: ${PLATFORMS}" info "Mode: ${mode}" info "Cache: ${use_cache}"