Skip to content

Commit

Permalink
upgrade oci-image module
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <[email protected]>
  • Loading branch information
inteon committed Jan 22, 2024
1 parent dfc1d81 commit 584c889
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
22 changes: 11 additions & 11 deletions klone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,55 @@ targets:
- folder_name: boilerplate
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/boilerplate
- folder_name: cert-manager
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/cert-manager
- folder_name: controller-gen
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/controller-gen
- folder_name: generate-verify
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/generate-verify
- folder_name: helm
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/helm
- folder_name: help
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/help
- folder_name: kind
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/kind
- folder_name: klone
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/klone
- folder_name: oci-image
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/oci-image
- folder_name: repository-base
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/repository-base
- folder_name: tools
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 06bb8b339f2033e196cba881bc0fb724e1315cc5
repo_hash: 1539e50a1ea7d7c3f97ea37b3f9557971295acc1
repo_path: modules/tools
6 changes: 4 additions & 2 deletions make/00_mod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ oci_platforms := linux/amd64,linux/arm64

build_names := manager approver

go_manager_source_path := cmd/csi/main.go
go_manager_main_dir := ./cmd/csi
go_manager_mod_dir := .
go_manager_ldflags := -X $(repo_name)/internal/version.AppVersion=$(VERSION) -X $(repo_name)/internal/version.GitCommit=$(GITCOMMIT)
oci_manager_base_image_flavor := csi-static
oci_manager_image_name := quay.io/jetstack/cert-manager-csi-driver-spiffe
oci_manager_image_tag := $(VERSION)
oci_manager_image_name_development := cert-manager.local/cert-manager-csi-driver-spiffe

go_approver_source_path := cmd/approver/main.go
go_approver_main_dir := ./cmd/approver
go_approver_mod_dir := .
go_approver_ldflags := -X $(repo_name)/internal/version.AppVersion=$(VERSION) -X $(repo_name)/internal/version.GitCommit=$(GITCOMMIT)
oci_approver_base_image_flavor := static
oci_approver_image_name := quay.io/jetstack/cert-manager-csi-driver-spiffe-approver
Expand Down
48 changes: 39 additions & 9 deletions make/_shared/oci-image/01_mod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ fatal_if_undefined = $(if $(findstring undefined,$(origin $1)),$(error $1 is not

define check_variables
$(call fatal_if_undefined,go_$1_ldflags)
$(call fatal_if_undefined,go_$1_source_path)
$(call fatal_if_undefined,go_$1_main_dir)
$(call fatal_if_undefined,go_$1_mod_dir)
$(call fatal_if_undefined,oci_$1_base_image_flavor)
$(call fatal_if_undefined,oci_$1_image_name)
$(call fatal_if_undefined,oci_$1_image_name_development)
Expand All @@ -48,6 +49,25 @@ else
$$(error oci_$1_base_image_flavor has unknown value "$(oci_$1_base_image_flavor)")
endif

ifneq ($(go_$1_main_dir:.%=.),.)
$$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES start with ".")
endif
ifeq ($(go_$1_main_dir:%/=/),/)
$$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES NOT end with "/")
endif
ifeq ($(go_$1_main_dir:%.go=.go),.go)
$$(error go_$1_main_dir "$(go_$1_main_dir)" should be a directory path that DOES NOT end with ".go")
endif
ifneq ($(go_$1_mod_dir:.%=.),.)
$$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES start with ".")
endif
ifeq ($(go_$1_mod_dir:%/=/),/)
$$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES NOT end with "/")
endif
ifeq ($(go_$1_mod_dir:%.go=.go),.go)
$$(error go_$1_mod_dir "$(go_$1_mod_dir)" should be a directory path that DOES NOT end with ".go")
endif

endef

$(foreach build_name,$(build_names),$(eval $(call check_variables,$(build_name))))
Expand All @@ -73,34 +93,44 @@ $(oci_build_targets): oci-build-%: | $(NEEDS_KO) $(NEEDS_GO) $(NEEDS_YQ) $(bin_d
$(eval oci_layout_path := $(bin_dir)/scratch/image/oci-layout-$*.$(oci_$*_image_tag))
rm -rf $(CURDIR)/$(oci_layout_path)

@if [ ! -f "$(go_$*_mod_dir)/go.mod" ]; then \
echo "ERROR: Specified directory "$(go_$*_mod_dir)" does not contain a go.mod file."; \
exit 1; \
fi

@if [ ! -f "$(go_$*_mod_dir)/$(go_$*_main_dir)/main.go" ]; then \
echo "ERROR: Specified directory "$(go_$*_mod_dir)$(go_$*_main_dir)" does not contain a main.go file."; \
exit 1; \
fi

echo '{}' | \
$(YQ) '.defaultBaseImage = "$(oci_$*_base_image)"' | \
$(YQ) '.builds[0].id = "$*"' | \
$(YQ) '.builds[0].main = "$(go_$*_source_path)"' | \
$(YQ) '.builds[0].env[0] = "CGO_ENABLED={{.Env.CGO_ENABLED}}"' | \
$(YQ) '.builds[0].env[1] = "GOEXPERIMENT={{.Env.GOEXPERIMENT}}"' | \
$(YQ) '.builds[0].dir = "$(go_$*_mod_dir)"' | \
$(YQ) '.builds[0].main = "$(go_$*_main_dir)"' | \
$(YQ) '.builds[0].env[0] = "CGO_ENABLED=$(CGO_ENABLED)"' | \
$(YQ) '.builds[0].env[1] = "GOEXPERIMENT=$(GOEXPERIMENT)"' | \
$(YQ) '.builds[0].ldflags[0] = "-s"' | \
$(YQ) '.builds[0].ldflags[1] = "-w"' | \
$(YQ) '.builds[0].ldflags[2] = "{{.Env.LDFLAGS}}"' \
> $(CURDIR)/$(oci_layout_path).ko_config.yaml

GOWORK=off \
KO_DOCKER_REPO=$(oci_$*_image_name_development) \
KOCACHE=$(bin_dir)/scratch/image/ko_cache \
KO_CONFIG_PATH=$(CURDIR)/$(oci_layout_path).ko_config.yaml \
SOURCE_DATE_EPOCH=$(GITEPOCH) \
KO_GO_PATH=$(GO) \
LDFLAGS="$(go_$*_ldflags)" \
CGO_ENABLED=$(CGO_ENABLED) \
GOEXPERIMENT=$(GOEXPERIMENT) \
$(KO) build $(go_$*_source_path) \
$(KO) build $(go_$*_mod_dir)/$(go_$*_main_dir) \
--platform=$(oci_platforms) \
--oci-layout-path=$(oci_layout_path) \
--sbom-dir=$(CURDIR)/$(oci_layout_path).sbom \
--sbom=spdx \
--push=false \
--bare

cd $(image_tool_dir) && $(GO) run . list-digests \
cd $(image_tool_dir) && GOWORK=off $(GO) run . list-digests \
$(CURDIR)/$(oci_layout_path) \
> $(CURDIR)/$(oci_layout_path).digests

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

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)
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)
$(KIND) load image-archive --name $(kind_cluster_name) $(oci_layout_path).docker.tar
2 changes: 1 addition & 1 deletion make/_shared/tools/00_mod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ GO_DEPENDENCIES += helm-tool=github.com/cert-manager/helm-tool

define go_dependency
$$(bin_dir)/downloaded/tools/$1@$($(call UC,$1)_VERSION)_%: | $$(NEEDS_GO) $$(bin_dir)/downloaded/tools
GOBIN=$$(CURDIR)/$$(dir $$@) $$(GO) install $2@$($(call UC,$1)_VERSION)
GOWORK=off GOBIN=$$(CURDIR)/$$(dir $$@) $$(GO) install $2@$($(call UC,$1)_VERSION)
@mv $$(CURDIR)/$$(dir $$@)/$1 $$@
endef

Expand Down

0 comments on commit 584c889

Please sign in to comment.