2023-12-18 04:05:16 +00:00
|
|
|
# Build package with chosen $(BUILDER)
|
|
|
|
# Supported BUILDERs: docker
|
|
|
|
# Usage: $(call build,core/$(NAME),$(VERSION),$(TARGET),$(EXTRA_ARGS))
|
|
|
|
# Notes:
|
|
|
|
# - Packages are expected to use the following layer names in order:
|
|
|
|
# - "fetch": [optional] obtain any artifacts from the internet.
|
|
|
|
# - "build": [optional] do any required build work
|
|
|
|
# - "package": [required] scratch layer exporting artifacts for distribution
|
|
|
|
# - "test": [optional] define any tests
|
|
|
|
# - Packages may prefix layer names with "text-" if more than one is desired
|
|
|
|
# - VERSION will be set as a build-arg if defined, otherwise it is "latest"
|
|
|
|
# - TARGET defaults to "package"
|
|
|
|
# - EXTRA_ARGS will be blindly injected
|
|
|
|
# - packages may also define a "test" layer
|
2024-01-17 18:10:39 +00:00
|
|
|
# - the ulimit line is to workaround a bug in patch when the nofile limit is too large:
|
|
|
|
# https://savannah.gnu.org/bugs/index.php?62958
|
2023-12-18 04:05:16 +00:00
|
|
|
# TODO:
|
|
|
|
# - try to disable networking on fetch layers with something like:
|
|
|
|
# $(if $(filter fetch,$(lastword $(subst -, ,$(TARGET)))),,--network=none)
|
|
|
|
# - actually output OCI files for each build (vs plain tar)
|
|
|
|
# - output manifest.txt of all tar/digest hashes for an easy git diff
|
|
|
|
# - support buildah and podman
|
|
|
|
define build
|
|
|
|
$(eval CATEGORY := $(1))
|
|
|
|
$(eval NAME := $(2))
|
|
|
|
$(eval VERSION := $(if $(3),$(3),latest))
|
|
|
|
$(eval TARGET := $(if $(4),$(4),package))
|
|
|
|
$(eval EXTRA_ARGS := $(if $(5),$(5),))
|
2024-01-28 05:49:38 +00:00
|
|
|
$(eval REVISION := $(shell git rev-list HEAD -1 src/$(CATEGORY)/$(NAME)))
|
2023-12-18 04:05:16 +00:00
|
|
|
$(eval BUILD_CMD := \
|
|
|
|
DOCKER_BUILDKIT=1 \
|
2024-01-28 05:49:38 +00:00
|
|
|
BUILDKIT_MULTI_PLATFORM=1 \
|
2023-12-18 04:05:16 +00:00
|
|
|
SOURCE_DATE_EPOCH=1 \
|
|
|
|
$(BUILDER) \
|
|
|
|
build \
|
2024-01-17 18:10:39 +00:00
|
|
|
--ulimit nofile=2048:16384 \
|
2024-01-28 06:23:34 +00:00
|
|
|
--tag $(REGISTRY)/$(NAME):$(VERSION) \
|
2023-12-18 04:05:16 +00:00
|
|
|
--build-arg REGISTRY=$(REGISTRY) \
|
|
|
|
--platform $(PLATFORM) \
|
|
|
|
--progress=plain \
|
|
|
|
$(if $(filter latest,$(VERSION)),,--build-arg VERSION=$(VERSION)) \
|
2024-01-28 05:59:02 +00:00
|
|
|
--output type=oci,force-compression=true,name=$(NAME),annotation.org.opencontainers.image.revision=$(REVISION),annotation.org.opencontainers.image.version=$(VERSION),dest=- \
|
2023-12-18 04:05:16 +00:00
|
|
|
--target $(TARGET) \
|
|
|
|
$(EXTRA_ARGS) \
|
|
|
|
src/$(CATEGORY)/$(NAME) \
|
2024-01-28 05:49:38 +00:00
|
|
|
| gzip > $@; \
|
2024-01-28 06:23:34 +00:00
|
|
|
gunzip -c $@ | docker load; \
|
2023-12-18 04:05:16 +00:00
|
|
|
)
|
|
|
|
$(eval TIMESTAMP := $(shell TZ=GMT date +"%Y-%m-%dT%H:%M:%SZ"))
|
|
|
|
mkdir -p out/
|
|
|
|
echo $(TIMESTAMP) $(BUILD_CMD) >> out/build.log
|
|
|
|
$(BUILD_CMD)
|
2024-01-28 05:49:38 +00:00
|
|
|
tar -xf $@ index.json -O \
|
|
|
|
| jq -r '.manifests[].digest | sub("sha256:";"")' \
|
|
|
|
> $@.digest
|
2023-12-18 04:05:16 +00:00
|
|
|
endef
|