1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- oci_platforms := all
15+ oci_platforms := linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le
1616
1717# Use distroless as minimal base image to package the manager binary
1818# Refer to https://github.com/GoogleContainerTools/distroless for more details
@@ -54,50 +54,31 @@ $(foreach build_name,$(build_names),$(eval $(call check_variables,$(build_name))
5454
5555# #########################################
5656
57+ RELEASE_DRYRUN ?= false
58+
5759CGO_ENABLED ?= 0
60+ GOEXPERIMENT ?= # empty by default
5861
59- build_targets := $(build_names:%=$(bin_dir ) /bin/% )
60- run_targets := $(build_names:%=run-% )
6162oci_build_targets := $(build_names:%=oci-build-% )
6263oci_push_targets := $(build_names:%=oci-push-% )
6364oci_maybe_push_targets := $(build_names:%=oci-maybe-push-% )
6465oci_load_targets := $(build_names:%=oci-load-% )
6566
6667image_tool_dir := $(dir $(lastword $(MAKEFILE_LIST ) ) ) /image_tool/
6768
68- $(bin_dir ) /bin :
69- mkdir -p $@
70-
71- # # Build manager binary.
72- # # @category [shared] Build
73- $(build_targets ) : $(bin_dir ) /bin/% : FORCE | $(NEEDS_GO ) $(bin_dir ) /bin
74- CGO_ENABLED=$(CGO_ENABLED ) \
75- $(GO ) build \
76- -ldflags ' $(go_$*_ldflags)' \
77- -o $@ \
78- $(go_$* _source_path )
79-
80- .PHONY : $(run_targets )
81- ARGS ?= # default empty
82- # # Run a controller from your host.
83- # # @category [shared] Build
84- $(run_targets ) : run-%: | $(NEEDS_GO )
85- $(GO) run \
86- -ldflags '$(go_$*_ldflags)' \
87- $(go_$*_source_path) $(ARGS)
88-
8969.PHONY : $(oci_build_targets )
90- # # Build the oci image.
70+ # # Build the OCI image.
9171# # @category [shared] Build
9272$(oci_build_targets ) : oci-build-% : | $(NEEDS_KO ) $(NEEDS_GO ) $(NEEDS_YQ ) $(bin_dir ) /scratch/image
9373 $(eval oci_layout_path := $(bin_dir ) /scratch/image/oci-layout-$* .$(oci_$* _image_tag ) )
9474 rm -rf $(CURDIR ) /$(oci_layout_path )
95-
75+
9676 echo '{}' | \
9777 $(YQ) '.defaultBaseImage = "$(oci_$*_base_image)"' | \
9878 $(YQ) '.builds[0].id = "$*"' | \
9979 $(YQ) '.builds[0].main = "$(go_$*_source_path)"' | \
10080 $(YQ) '.builds[0].env[0] = "CGO_ENABLED={{.Env.CGO_ENABLED}}"' | \
81+ $(YQ) '.builds[0].env[1] = "GOEXPERIMENT={{.Env.GOEXPERIMENT}}"' | \
10182 $(YQ) '.builds[0].ldflags[0] = "-s"' | \
10283 $(YQ) '.builds[0].ldflags[1] = "-w"' | \
10384 $(YQ) '.builds[0].ldflags[2] = "{{.Env.LDFLAGS}}"' \
@@ -109,6 +90,7 @@ $(oci_build_targets): oci-build-%: | $(NEEDS_KO) $(NEEDS_GO) $(NEEDS_YQ) $(bin_d
10990 KO_GO_PATH=$(GO) \
11091 LDFLAGS="$(go_$*_ldflags)" \
11192 CGO_ENABLED=$(CGO_ENABLED) \
93+ GOEXPERIMENT=$(GOEXPERIMENT) \
11294 $(KO) build $(go_$*_source_path) \
11395 --platform=$(oci_platforms) \
11496 --oci-layout-path=$(CURDIR)/$(oci_layout_path) \
@@ -122,7 +104,7 @@ $(oci_build_targets): oci-build-%: | $(NEEDS_KO) $(NEEDS_GO) $(NEEDS_YQ) $(bin_d
122104 > $(CURDIR)/$(oci_layout_path).digests
123105
124106.PHONY : $(oci_push_targets )
125- # # Push docker image.
107+ # # Build and push OCI image.
126108# # If the tag already exists, this target will overwrite it.
127109# # If an identical image was already built before, we will add a new tag to it, but we will not sign it again.
128110# # Expected pushed images:
@@ -133,6 +115,7 @@ $(oci_push_targets): oci-push-%: oci-build-% | $(NEEDS_CRANE) $(NEEDS_COSIGN) $(
133115 $(eval oci_layout_path := $(bin_dir ) /scratch/image/oci-layout-$* .$(oci_$* _image_tag ) )
134116 $(eval image_ref := $(shell head -1 $(CURDIR ) /$(oci_layout_path ) .digests) )
135117
118+ ifneq ($(RELEASE_DRYRUN ) ,true)
136119 if $(CRANE) image digest $(oci_$*_image_name)@$(image_ref) >/dev/null 2>&1; then \
137120 echo "Digest already exists, will retag without resigning."; \
138121 $(CRANE) push "$(oci_layout_path)" "$(oci_$*_image_name):$(oci_$*_image_tag)"; \
@@ -141,12 +124,10 @@ $(oci_push_targets): oci-push-%: oci-build-% | $(NEEDS_CRANE) $(NEEDS_COSIGN) $(
141124 $(CRANE) push "$(oci_layout_path)" "$(oci_$*_image_name):$(oci_$*_image_tag)"; \
142125 $(COSIGN) sign --yes=true "$(oci_$*_image_name)@$(image_ref)"; \
143126 fi
127+ endif
144128
145129.PHONY : $(oci_maybe_push_targets )
146- # # Push docker image if tag does not already exist.
147- # # Expected pushed images:
148- # # - :v1.2.3, @sha256:0000001
149- # # - :v1.2.3.sig, :sha256-0000001.sig
130+ # # Run 'make oci-push-...' if tag does not already exist in registry.
150131# # @category [shared] Build
151132$(oci_maybe_push_targets ) : oci-maybe-push-% : | $(NEEDS_CRANE )
152133 if $( CRANE) manifest digest $( oci_$* _image_name) :$( oci_$* _image_tag) > /dev/null 2>&1 ; then \
@@ -157,7 +138,8 @@ $(oci_maybe_push_targets): oci-maybe-push-%: | $(NEEDS_CRANE)
157138 fi
158139
159140.PHONY : $(oci_load_targets )
160- # # Load docker image.
141+ # # Build OCI image for the local architecture and load
142+ # # it into the $(kind_cluster_name) kind cluster.
161143# # @category [shared] Build
162144$(oci_load_targets ) : oci_platforms := ""
163145$(oci_load_targets ) : oci-load-% : oci-build-% | kind-cluster $(NEEDS_KIND )
0 commit comments