Files
cozystack/hack/common-envs.mk
T
Myasnikov Daniil 34d7b565a8 perf(ci): build release lines from their own cache, in parallel
Release-line image builds read only main's build cache, which matches
release-1.6 less with every Dockerfile main changes: the rc Prepare
Release job went from 28 minutes on v1.6.4-rc.1 to 43 on v1.6.5-rc.1
and 45 on v1.6.6-rc.1.

The line now keeps a cache of its own. build-release.yaml writes
buildcache-release-1.6 on every push to the line, and rc builds import
it together with main's buildcache. CACHE_FROM_TAGS lists every cache a
build imports; unset, it is CACHE_TAG (buildcache), as before. This
line's cache-args took an optional per-call cache tag that no caller
passes, so it takes main's form instead. A cache write that fails no
longer fails the build (ignore-error=true).

The units of hack/build-matrix.sh build four at a time (make
build-parallel, hack/build-units.sh), each output line carrying its
unit. On this line packages/core/platform waits for the rest, because
it writes backupstrategy-controller's values.yaml.

Tested with bats: the cache macro, the unit builder against a fake make
and the workflow settings, plus a dry run of hack/build-units.sh over
this line's units with make -n.

Assisted-by: LLM
(cherry picked from commit 12eaa49521)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-11-27 13:25:59 +00:00

95 lines
4.7 KiB
Makefile

# macOS-compatible sed in-place
ifeq ($(shell uname),Darwin)
SED_INPLACE := sed -i ''
else
SED_INPLACE := sed -i
endif
REGISTRY ?= ghcr.io/cozystack/cozystack
# CACHE_REGISTRY: registry holding the `:buildcache` mode=max cache images that
# `--cache-from`/`--cache-to` read and write (see the cache-args macro below).
# Defaults to $(REGISTRY) so the cache is co-located with the build registry —
# in CI that is the per-CI registry the runners are closest to, keeping cache
# transfers fast and egress-free.
CACHE_REGISTRY ?= $(REGISTRY)
# IMAGE_TAG: build-unique tag pushed for every image. Set by CI to a value
# that does not collide between concurrent builds:
# * pull-requests.yaml -> pr-<N>-<sha>
# * tags.yaml -> <ref_name> (e.g. v1.5.0)
# * local -> dev (with PUSH=0 by default)
IMAGE_TAG ?= dev
# Opt-in extra tags. Workflows set these explicitly; defaults are off so a
# local `make build` never races with CI or accidentally moves :latest.
# PUBLISH_VERSIONED=1 -> also push :<component-version> (release semantics)
# PUBLISH_FLOATING=1 -> also push :latest (release/main only)
PUBLISH_VERSIONED ?= 0
PUBLISH_FLOATING ?= 0
# WRITE_CACHE=1 enables `--cache-to` (mode=max) to CACHE_REGISTRY/<img>:$(CACHE_TAG).
# Default off: only the serialized main/release cache-warming build writes the
# shared cache ref. PR builds keep it 0 and read-only, so concurrent PR builds
# never race on the cache manifest (the 409 collisions PR #2711 fixed for tags).
WRITE_CACHE ?= 0
PUSH := 1
LOAD := 0
BUILDER ?=
PLATFORM ?=
BUILDX_EXTRA_ARGS ?=
COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags --match 'v*'))
# SBOM=1 attaches a CycloneDX SBOM as a buildx build attestation (--sbom=true).
# Requires the docker-container buildx driver and registry referrers/attestation
# support. Kept OFF by default until an OCIR referrers/attestation probe confirms
# support — otherwise the attestation push fails the build. (NB: the dashboard
# package's bespoke buildx calls don't read BUILDX_ARGS, so they are not yet
# SBOM-covered — follow-up.) See #2937.
SBOM ?= 0
BUILDX_ARGS := --provenance=false --push=$(PUSH) --load=$(LOAD) \
--label org.opencontainers.image.source=https://github.com/cozystack/cozystack \
$(if $(filter 1,$(SBOM)),--sbom=true) \
$(if $(strip $(BUILDER)),--builder=$(BUILDER)) \
$(if $(strip $(PLATFORM)),--platform=$(PLATFORM)) \
$(BUILDX_EXTRA_ARGS)
# image-tags <repo> <versioned-tag>
# Expands to one or more `--tag` flags for `docker buildx build`:
# - always: :$(IMAGE_TAG) (build-unique handle)
# - if PUBLISH_VERSIONED=1: :<versioned-tag> (skipped when arg2 is empty
# or equals IMAGE_TAG)
# - if PUBLISH_FLOATING=1: :latest
# Consumers reference images by digest, so the build-unique tag is enough
# for cluster-side pulls; the versioned and floating tags exist for human
# discoverability and downstream tooling on releases.
define image-tags
--tag $(REGISTRY)/$(1):$(IMAGE_TAG)$(if $(filter 1,$(PUBLISH_VERSIONED)),$(if $(filter-out $(IMAGE_TAG),$(strip $(2))), --tag $(REGISTRY)/$(1):$(strip $(2))))$(if $(filter 1,$(PUBLISH_FLOATING)), --tag $(REGISTRY)/$(1):latest)
endef
# cache-args <image-name>
# Expands to buildx cache flags for one image:
# --cache-from is always emitted (a missing cache 404s harmlessly -> cold build)
# --cache-to is emitted only when WRITE_CACHE=1 (main/release), writing mode=max
# so ALL stages are cached -- including the multistage `builder` layers that
# `--cache-to type=inline` could never export. oci-mediatypes + image-manifest
# keep the cache manifest portable across registries (OCIR/ghcr/ECR).
# ignore-error: OCIR refuses a blob upload now and then, and a lost cache
# write should cost the next build time, not fail this one.
# CACHE_FROM_TAGS lists every cache a build imports; a release line imports its
# own as well as main's, since main's Dockerfiles drift away from the line's.
# $(comma) escapes the literal commas in the --cache-to value so make does not
# mis-parse them as $(if ...) argument separators.
comma := ,
CACHE_TAG ?= buildcache
CACHE_FROM_TAGS ?= $(CACHE_TAG)
cache-args = $(foreach t,$(CACHE_FROM_TAGS),--cache-from type=registry$(comma)ref=$(CACHE_REGISTRY)/$(1):$(t))$(if $(filter 1,$(WRITE_CACHE)), --cache-to type=registry$(comma)ref=$(CACHE_REGISTRY)/$(1):$(CACHE_TAG)$(comma)mode=max$(comma)oci-mediatypes=true$(comma)image-manifest=true$(comma)ignore-error=true)
ifeq ($(COZYSTACK_VERSION),)
$(shell git remote add upstream https://github.com/cozystack/cozystack.git || true)
$(shell git fetch upstream --tags)
COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags --match 'v*'))
endif