|
15 | 15 | $(bin_dir)/scratch/image: |
16 | 16 | @mkdir -p $@ |
17 | 17 |
|
18 | | -define ko_config_target |
19 | | -.PHONY: $(ko_config_path_$1:$(CURDIR)/%=%) |
20 | | -$(ko_config_path_$1:$(CURDIR)/%=%): | $(NEEDS_YQ) $(bin_dir)/scratch/image |
| 18 | +.PHONY: $(oci_build_targets) |
| 19 | +## 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)) |
| 22 | +## @category [shared] Build |
| 23 | +$(oci_build_targets): oci-build-%: | $(NEEDS_KO) $(NEEDS_GO) $(NEEDS_YQ) $(NEEDS_IMAGE-TOOL) $(bin_dir)/scratch/image |
| 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) |
| 30 | + |
21 | 31 | echo '{}' | \ |
22 | | - $(YQ) '.defaultBaseImage = "$(oci_$1_base_image)"' | \ |
23 | | - $(YQ) '.builds[0].id = "$1"' | \ |
24 | | - $(YQ) '.builds[0].dir = "$(go_$1_mod_dir)"' | \ |
25 | | - $(YQ) '.builds[0].main = "$(go_$1_main_dir)"' | \ |
26 | | - $(YQ) '.builds[0].env[0] = "CGO_ENABLED=$(go_$1_cgo_enabled)"' | \ |
27 | | - $(YQ) '.builds[0].env[1] = "GOEXPERIMENT=$(go_$1_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)"' | \ |
28 | 38 | $(YQ) '.builds[0].ldflags[0] = "-s"' | \ |
29 | 39 | $(YQ) '.builds[0].ldflags[1] = "-w"' | \ |
30 | 40 | $(YQ) '.builds[0].ldflags[2] = "{{.Env.LDFLAGS}}"' | \ |
31 | | - $(YQ) '.builds[0].flags[0] = "$(go_$1_flags)"' | \ |
32 | | - $(YQ) '.builds[0].linux_capabilities = "$(oci_$1_linux_capabilities)"' \ |
33 | | - > $(CURDIR)/$(oci_layout_path_$1).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 |
34 | 44 |
|
35 | | -ko-config-$1: $(ko_config_path_$1:$(CURDIR)/%=%) |
36 | | -endef |
37 | | - |
38 | | -.PHONY: $(ko_config_targets) |
39 | | -$(foreach build_name,$(build_names),$(eval $(call ko_config_target,$(build_name)))) |
40 | | - |
41 | | -.PHONY: $(oci_build_targets) |
42 | | -## Build the OCI image. |
43 | | -## @category [shared] Build |
44 | | -$(oci_build_targets): oci-build-%: ko-config-% | $(NEEDS_KO) $(NEEDS_GO) $(NEEDS_YQ) $(NEEDS_IMAGE-TOOL) $(bin_dir)/scratch/image |
45 | | - rm -rf $(CURDIR)/$(oci_layout_path_$*) |
46 | 45 | GOWORK=off \ |
47 | | - KO_DOCKER_REPO=$(oci_$*_image_name_development) \ |
| 46 | + KO_DOCKER_REPO=$(oci_$a_image_name_development) \ |
48 | 47 | KOCACHE=$(CURDIR)/$(bin_dir)/scratch/image/ko_cache \ |
49 | | - KO_CONFIG_PATH=$(ko_config_path_$*) \ |
| 48 | + KO_CONFIG_PATH=$(CURDIR)/$(layout_path).ko_config.yaml \ |
50 | 49 | SOURCE_DATE_EPOCH=$(GITEPOCH) \ |
51 | 50 | KO_GO_PATH=$(GO) \ |
52 | | - LDFLAGS="$(go_$*_ldflags)" \ |
53 | | - $(KO) build $(go_$*_mod_dir)/$(go_$*_main_dir) \ |
54 | | - --platform=$(oci_platforms) \ |
55 | | - $(oci_$*_build_args) \ |
56 | | - --oci-layout-path=$(oci_layout_path_$*) \ |
57 | | - --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 \ |
58 | 57 | --sbom=spdx \ |
59 | 58 | --push=false \ |
60 | 59 | --bare |
61 | 60 |
|
62 | 61 | $(IMAGE-TOOL) append-layers \ |
63 | | - $(CURDIR)/$(oci_layout_path_$*) \ |
64 | | - $(oci_$*_additional_layers) |
| 62 | + $(CURDIR)/$(layout_path) \ |
| 63 | + $(oci_$a_additional_layers) |
65 | 64 |
|
66 | 65 | $(IMAGE-TOOL) list-digests \ |
67 | | - $(CURDIR)/$(oci_layout_path_$*) \ |
68 | | - > $(oci_digest_path_$*) |
| 66 | + $(CURDIR)/$(layout_path) \ |
| 67 | + > $(digest_path) |
69 | 68 |
|
70 | 69 | # Only include the oci-load target if kind is provided by the kind makefile-module |
71 | 70 | ifdef kind_cluster_name |
|
80 | 79 | ## Build Docker tarball image for the local architecture |
81 | 80 | ## @category [shared] Build |
82 | 81 | .PHONY: $(docker_tarball_targets) |
83 | | -$(docker_tarball_targets): oci_platforms := "linux/$(HOST_ARCH)" |
84 | | -$(docker_tarball_targets): docker-tarball-%: oci-build-% | $(NEEDS_GO) $(NEEDS_IMAGE-TOOL) |
85 | | - $(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