@@ -35,7 +35,8 @@ fatal_if_undefined = $(if $(findstring undefined,$(origin $1)),$(error $1 is not
35
35
36
36
define check_variables
37
37
$(call fatal_if_undefined,go_$1_ldflags)
38
- $(call fatal_if_undefined,go_$1_source_path)
38
+ $(call fatal_if_undefined,go_$1_main_dir)
39
+ $(call fatal_if_undefined,go_$1_mod_dir)
39
40
$(call fatal_if_undefined,oci_$1_base_image_flavor)
40
41
$(call fatal_if_undefined,oci_$1_image_name)
41
42
$(call fatal_if_undefined,oci_$1_image_name_development)
48
49
$$(error oci_$1_base_image_flavor has unknown value "$(oci_$1_base_image_flavor)")
49
50
endif
50
51
52
+ ifneq ($(go_$1_main_dir:.%=. ) ,.)
53
+ $$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES start with ".")
54
+ endif
55
+ ifeq ($(go_$1_main_dir:%/=/ ) ,/)
56
+ $$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES NOT end with "/")
57
+ endif
58
+ ifeq ($(go_$1_main_dir:%.go=.go ) ,.go)
59
+ $$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES NOT end with ".go")
60
+ endif
61
+ ifneq ($(go_$1_mod_dir:.%=. ) ,.)
62
+ $$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES start with ".")
63
+ endif
64
+ ifeq ($(go_$1_mod_dir:%/=/ ) ,/)
65
+ $$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES NOT end with "/")
66
+ endif
67
+ ifeq ($(go_$1_mod_dir:%.go=.go ) ,.go)
68
+ $$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES NOT end with ".go")
69
+ endif
70
+
51
71
endef
52
72
53
73
$(foreach build_name,$(build_names),$(eval $(call check_variables,$(build_name))))
@@ -73,34 +93,44 @@ $(oci_build_targets): oci-build-%: | $(NEEDS_KO) $(NEEDS_GO) $(NEEDS_YQ) $(bin_d
73
93
$(eval oci_layout_path := $(bin_dir ) /scratch/image/oci-layout-$* .$(oci_$* _image_tag ) )
74
94
rm -rf $(CURDIR ) /$(oci_layout_path )
75
95
96
+ @if [ ! -f "$(go_$*_mod_dir)/go.mod" ]; then \
97
+ echo "ERROR: Specified directory "$(go_$*_mod_dir)" does not contain a go.mod file."; \
98
+ exit 1; \
99
+ fi
100
+
101
+ @if [ ! -f "$(go_$*_mod_dir)/$(go_$*_main_dir)/main.go" ]; then \
102
+ echo "ERROR: Specified directory "$(go_$*_mod_dir)$(go_$*_main_dir)" does not contain a main.go file."; \
103
+ exit 1; \
104
+ fi
105
+
76
106
echo '{}' | \
77
107
$(YQ) '.defaultBaseImage = "$(oci_$*_base_image)"' | \
78
108
$(YQ) '.builds[0].id = "$*"' | \
79
- $(YQ) '.builds[0].main = "$(go_$*_source_path)"' | \
80
- $(YQ) '.builds[0].env[0] = "CGO_ENABLED={{.Env.CGO_ENABLED}}"' | \
81
- $(YQ) '.builds[0].env[1] = "GOEXPERIMENT={{.Env.GOEXPERIMENT}}"' | \
109
+ $(YQ) '.builds[0].dir = "$(go_$*_mod_dir)"' | \
110
+ $(YQ) '.builds[0].main = "$(go_$*_main_dir)"' | \
111
+ $(YQ) '.builds[0].env[0] = "CGO_ENABLED=$(CGO_ENABLED)"' | \
112
+ $(YQ) '.builds[0].env[1] = "GOEXPERIMENT=$(GOEXPERIMENT)"' | \
82
113
$(YQ) '.builds[0].ldflags[0] = "-s"' | \
83
114
$(YQ) '.builds[0].ldflags[1] = "-w"' | \
84
115
$(YQ) '.builds[0].ldflags[2] = "{{.Env.LDFLAGS}}"' \
85
116
> $(CURDIR)/$(oci_layout_path).ko_config.yaml
86
117
118
+ GOWORK=off \
87
119
KO_DOCKER_REPO=$(oci_$*_image_name_development) \
88
120
KOCACHE=$(bin_dir)/scratch/image/ko_cache \
89
121
KO_CONFIG_PATH=$(CURDIR)/$(oci_layout_path).ko_config.yaml \
90
122
SOURCE_DATE_EPOCH=$(GITEPOCH) \
91
123
KO_GO_PATH=$(GO) \
92
124
LDFLAGS="$(go_$*_ldflags)" \
93
- CGO_ENABLED=$(CGO_ENABLED) \
94
- GOEXPERIMENT=$(GOEXPERIMENT) \
95
- $(KO) build $(go_$*_source_path) \
125
+ $(KO) build $(go_$*_mod_dir)/$(go_$*_main_dir) \
96
126
--platform=$(oci_platforms) \
97
127
--oci-layout-path=$(oci_layout_path) \
98
128
--sbom-dir=$(CURDIR)/$(oci_layout_path).sbom \
99
129
--sbom=spdx \
100
130
--push=false \
101
131
--bare
102
132
103
- cd $(image_tool_dir) && $(GO) run . list-digests \
133
+ cd $(image_tool_dir) && GOWORK=off $(GO) run . list-digests \
104
134
$(CURDIR)/$(oci_layout_path) \
105
135
> $(CURDIR)/$(oci_layout_path).digests
106
136
@@ -146,5 +176,5 @@ $(oci_load_targets): oci_platforms := ""
146
176
$(oci_load_targets ) : oci-load-% : oci-build-% | kind-cluster $(NEEDS_KIND )
147
177
$(eval oci_layout_path := $(bin_dir ) /scratch/image/oci-layout-$* .$(oci_$* _image_tag ) )
148
178
149
- cd $(image_tool_dir) && $(GO) run . convert-to-docker-tar $(CURDIR)/$(oci_layout_path) $(CURDIR)/$(oci_layout_path).docker.tar $(oci_$*_image_name_development):$(oci_$*_image_tag)
179
+ cd $(image_tool_dir) && GOWORK=off $(GO) run . convert-to-docker-tar $(CURDIR)/$(oci_layout_path) $(CURDIR)/$(oci_layout_path).docker.tar $(oci_$*_image_name_development):$(oci_$*_image_tag)
150
180
$(KIND) load image-archive --name $(kind_cluster_name) $(oci_layout_path).docker.tar
0 commit comments