Skip to content

Commit 1a50134

Browse files
authored
Merge pull request #183 from inteon/upgrade_oci_module
Upgrade oci-image module
2 parents fe22560 + d537c45 commit 1a50134

File tree

4 files changed

+53
-22
lines changed

4 files changed

+53
-22
lines changed

klone.yaml

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,55 @@ targets:
1010
- folder_name: boilerplate
1111
repo_url: https://github.com/cert-manager/makefile-modules.git
1212
repo_ref: main
13-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
13+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
1414
repo_path: modules/boilerplate
1515
- folder_name: cert-manager
1616
repo_url: https://github.com/cert-manager/makefile-modules.git
1717
repo_ref: main
18-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
18+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
1919
repo_path: modules/cert-manager
2020
- folder_name: controller-gen
2121
repo_url: https://github.com/cert-manager/makefile-modules.git
2222
repo_ref: main
23-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
23+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
2424
repo_path: modules/controller-gen
2525
- folder_name: generate-verify
2626
repo_url: https://github.com/cert-manager/makefile-modules.git
2727
repo_ref: main
28-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
28+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
2929
repo_path: modules/generate-verify
3030
- folder_name: helm
3131
repo_url: https://github.com/cert-manager/makefile-modules.git
3232
repo_ref: main
33-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
33+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
3434
repo_path: modules/helm
3535
- folder_name: help
3636
repo_url: https://github.com/cert-manager/makefile-modules.git
3737
repo_ref: main
38-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
38+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
3939
repo_path: modules/help
4040
- folder_name: kind
4141
repo_url: https://github.com/cert-manager/makefile-modules.git
4242
repo_ref: main
43-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
43+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
4444
repo_path: modules/kind
4545
- folder_name: klone
4646
repo_url: https://github.com/cert-manager/makefile-modules.git
4747
repo_ref: main
48-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
48+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
4949
repo_path: modules/klone
5050
- folder_name: oci-image
5151
repo_url: https://github.com/cert-manager/makefile-modules.git
5252
repo_ref: main
53-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
53+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
5454
repo_path: modules/oci-image
5555
- folder_name: repository-base
5656
repo_url: https://github.com/cert-manager/makefile-modules.git
5757
repo_ref: main
58-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
58+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
5959
repo_path: modules/repository-base
6060
- folder_name: tools
6161
repo_url: https://github.com/cert-manager/makefile-modules.git
6262
repo_ref: main
63-
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
63+
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
6464
repo_path: modules/tools

make/00_mod.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ oci_platforms := linux/amd64,linux/arm64
2121

2222
build_names := manager
2323

24-
go_manager_source_path := cmd/main.go
24+
go_manager_main_dir := ./cmd
25+
go_manager_mod_dir := .
2526
go_manager_ldflags := -X $(repo_name)/internal/version.AppVersion=$(VERSION) -X $(repo_name)/internal/version.GitCommit=$(GITCOMMIT)
2627
oci_manager_base_image_flavor := csi-static
2728
oci_manager_image_name := quay.io/jetstack/cert-manager-csi-driver

make/_shared/oci-image/01_mod.mk

+39-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ fatal_if_undefined = $(if $(findstring undefined,$(origin $1)),$(error $1 is not
3535

3636
define check_variables
3737
$(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)
3940
$(call fatal_if_undefined,oci_$1_base_image_flavor)
4041
$(call fatal_if_undefined,oci_$1_image_name)
4142
$(call fatal_if_undefined,oci_$1_image_name_development)
@@ -48,6 +49,25 @@ else
4849
$$(error oci_$1_base_image_flavor has unknown value "$(oci_$1_base_image_flavor)")
4950
endif
5051

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+
5171
endef
5272

5373
$(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
7393
$(eval oci_layout_path := $(bin_dir)/scratch/image/oci-layout-$*.$(oci_$*_image_tag))
7494
rm -rf $(CURDIR)/$(oci_layout_path)
7595

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+
76106
echo '{}' | \
77107
$(YQ) '.defaultBaseImage = "$(oci_$*_base_image)"' | \
78108
$(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)"' | \
82113
$(YQ) '.builds[0].ldflags[0] = "-s"' | \
83114
$(YQ) '.builds[0].ldflags[1] = "-w"' | \
84115
$(YQ) '.builds[0].ldflags[2] = "{{.Env.LDFLAGS}}"' \
85116
> $(CURDIR)/$(oci_layout_path).ko_config.yaml
86117

118+
GOWORK=off \
87119
KO_DOCKER_REPO=$(oci_$*_image_name_development) \
88120
KOCACHE=$(bin_dir)/scratch/image/ko_cache \
89121
KO_CONFIG_PATH=$(CURDIR)/$(oci_layout_path).ko_config.yaml \
90122
SOURCE_DATE_EPOCH=$(GITEPOCH) \
91123
KO_GO_PATH=$(GO) \
92124
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) \
96126
--platform=$(oci_platforms) \
97127
--oci-layout-path=$(oci_layout_path) \
98128
--sbom-dir=$(CURDIR)/$(oci_layout_path).sbom \
99129
--sbom=spdx \
100130
--push=false \
101131
--bare
102132

103-
cd $(image_tool_dir) && $(GO) run . list-digests \
133+
cd $(image_tool_dir) && GOWORK=off $(GO) run . list-digests \
104134
$(CURDIR)/$(oci_layout_path) \
105135
> $(CURDIR)/$(oci_layout_path).digests
106136

@@ -146,5 +176,5 @@ $(oci_load_targets): oci_platforms := ""
146176
$(oci_load_targets): oci-load-%: oci-build-% | kind-cluster $(NEEDS_KIND)
147177
$(eval oci_layout_path := $(bin_dir)/scratch/image/oci-layout-$*.$(oci_$*_image_tag))
148178

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)
150180
$(KIND) load image-archive --name $(kind_cluster_name) $(oci_layout_path).docker.tar

make/_shared/tools/00_mod.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ GO_DEPENDENCIES += helm-tool=github.com/cert-manager/helm-tool
282282

283283
define go_dependency
284284
$$(bin_dir)/downloaded/tools/$1@$($(call UC,$1)_VERSION)_%: | $$(NEEDS_GO) $$(bin_dir)/downloaded/tools
285-
GOBIN=$$(CURDIR)/$$(dir $$@) $$(GO) install $2@$($(call UC,$1)_VERSION)
285+
GOWORK=off GOBIN=$$(CURDIR)/$$(dir $$@) $$(GO) install $2@$($(call UC,$1)_VERSION)
286286
@mv $$(CURDIR)/$$(dir $$@)/$1 $$@
287287
endef
288288

0 commit comments

Comments
 (0)