@@ -17,47 +17,54 @@ $(bin_dir)/scratch/image:
1717
1818.PHONY : $(oci_build_targets )
1919# # Build the OCI image.
20+ # # - oci-build-$(build_name) = build the oci directory (multi-arch)
21+ # # - oci-build-$(build_name)__local = build the oci directory (local arch: linux/$(HOST_ARCH))
2022# # @category [shared] Build
2123$(oci_build_targets ) : oci-build-% : | $(NEEDS_KO ) $(NEEDS_GO ) $(NEEDS_YQ ) $(NEEDS_IMAGE-TOOL ) $(bin_dir ) /scratch/image
22- rm -rf $(CURDIR ) /$(oci_layout_path_$* )
24+ $(eval a := $(patsubst % __local,% ,$* ) )
25+ $(eval is_local := $(if $(findstring $a__local,$* ) ,true) )
26+ $(eval layout_path := $(if $(is_local ) ,$(oci_layout_path_$a ) .local,$(oci_layout_path_$a ) ) )
27+ $(eval digest_path := $(if $(is_local ) ,$(oci_digest_path_$a ) .local,$(oci_digest_path_$a ) ) )
28+
29+ rm -rf $(CURDIR)/$(layout_path)
2330
2431 echo '{}' | \
25- $(YQ) '.defaultBaseImage = "$(oci_$*_base_image )"' | \
26- $(YQ) '.builds[0].id = "$* "' | \
27- $(YQ) '.builds[0].dir = "$(go_$*_mod_dir )"' | \
28- $(YQ) '.builds[0].main = "$(go_$*_main_dir )"' | \
29- $(YQ) '.builds[0].env[0] = "CGO_ENABLED=$(go_$*_cgo_enabled )"' | \
30- $(YQ) '.builds[0].env[1] = "GOEXPERIMENT=$(go_$*_goexperiment )"' | \
32+ $(YQ) '.defaultBaseImage = "$(oci_$a_base_image )"' | \
33+ $(YQ) '.builds[0].id = "$a "' | \
34+ $(YQ) '.builds[0].dir = "$(go_$a_mod_dir )"' | \
35+ $(YQ) '.builds[0].main = "$(go_$a_main_dir )"' | \
36+ $(YQ) '.builds[0].env[0] = "CGO_ENABLED=$(go_$a_cgo_enabled )"' | \
37+ $(YQ) '.builds[0].env[1] = "GOEXPERIMENT=$(go_$a_goexperiment )"' | \
3138 $(YQ) '.builds[0].ldflags[0] = "-s"' | \
3239 $(YQ) '.builds[0].ldflags[1] = "-w"' | \
3340 $(YQ) '.builds[0].ldflags[2] = "{{.Env.LDFLAGS}}"' | \
34- $(YQ) '.builds[0].flags[0] = "$(go_$*_flags )"' | \
35- $(YQ) '.builds[0].linux_capabilities = "$(oci_$*_linux_capabilities )"' \
36- > $(CURDIR)/$(oci_layout_path_$* ).ko_config.yaml
41+ $(YQ) '.builds[0].flags[0] = "$(go_$a_flags )"' | \
42+ $(YQ) '.builds[0].linux_capabilities = "$(oci_$a_linux_capabilities )"' \
43+ > $(CURDIR)/$(layout_path ).ko_config.yaml
3744
3845 GOWORK=off \
39- KO_DOCKER_REPO=$(oci_$*_image_name_development ) \
46+ KO_DOCKER_REPO=$(oci_$a_image_name_development ) \
4047 KOCACHE=$(CURDIR)/$(bin_dir)/scratch/image/ko_cache \
41- KO_CONFIG_PATH=$(CURDIR)/$(oci_layout_path_$* ).ko_config.yaml \
48+ KO_CONFIG_PATH=$(CURDIR)/$(layout_path ).ko_config.yaml \
4249 SOURCE_DATE_EPOCH=$(GITEPOCH) \
4350 KO_GO_PATH=$(GO) \
44- LDFLAGS="$(go_$*_ldflags )" \
45- $(KO) build $(go_$*_mod_dir )/$(go_$*_main_dir ) \
46- --platform=$(oci_platforms ) \
47- $(oci_$*_build_args ) \
48- --oci-layout-path=$(oci_layout_path_$* ) \
49- --sbom-dir=$(CURDIR)/$(oci_layout_path_$* ).sbom \
51+ LDFLAGS="$(go_$a_ldflags )" \
52+ $(KO) build $(go_$a_mod_dir )/$(go_$a_main_dir ) \
53+ --platform=$(if $(is_local),linux/$(HOST_ARCH),$(oci_$a_platforms) ) \
54+ $(oci_$a_build_args ) \
55+ --oci-layout-path=$(layout_path ) \
56+ --sbom-dir=$(CURDIR)/$(layout_path ).sbom \
5057 --sbom=spdx \
5158 --push=false \
5259 --bare
5360
5461 $(IMAGE-TOOL) append-layers \
55- $(CURDIR)/$(oci_layout_path_$* ) \
56- $(oci_$*_additional_layers )
62+ $(CURDIR)/$(layout_path ) \
63+ $(oci_$a_additional_layers )
5764
5865 $(IMAGE-TOOL) list-digests \
59- $(CURDIR)/$(oci_layout_path_$* ) \
60- > $(oci_digest_path_$* )
66+ $(CURDIR)/$(layout_path ) \
67+ > $(digest_path )
6168
6269# Only include the oci-load target if kind is provided by the kind makefile-module
6370ifdef kind_cluster_name
7279# # Build Docker tarball image for the local architecture
7380# # @category [shared] Build
7481.PHONY : $(docker_tarball_targets )
75- $(docker_tarball_targets ) : oci_platforms := "linux/$(HOST_ARCH ) "
76- $(docker_tarball_targets ) : docker-tarball-% : oci-build-% | $(NEEDS_GO ) $(NEEDS_IMAGE-TOOL )
77- $(IMAGE-TOOL ) convert-to-docker-tar $(CURDIR ) /$(oci_layout_path_$* ) $(docker_tarball_path_$* ) $(oci_$* _image_name_development ) :$(oci_$* _image_tag )
82+ $(docker_tarball_targets ) : docker-tarball-% : oci-build-% __local | $(NEEDS_GO ) $(NEEDS_IMAGE-TOOL )
83+ $(IMAGE-TOOL ) convert-to-docker-tar $(CURDIR ) /$(oci_layout_path_$* ) .local $(docker_tarball_path_$* ) $(oci_$* _image_name_development ) :$(oci_$* _image_tag )
0 commit comments