diff --git a/Makefile b/Makefile index 5dc18eb..ca2a599 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GO ?= $(shell which go) OS ?= $(shell $(GO) env GOOS) ARCH ?= $(shell $(GO) env GOARCH) -IMAGE_NAME := "webhook" +IMAGE_NAME := "cert-manager-webhook-sthome" IMAGE_TAG := "latest" OUT := $(shell pwd)/_out @@ -11,6 +11,10 @@ KUBEBUILDER_VERSION=1.28.0 HELM_FILES := $(shell find deploy/sthome-webhook) +dependencies: + go mod tidy + go mod vendor + test: _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/etcd _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/kube-apiserver _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/kubectl TEST_ASSET_ETCD=_test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/etcd \ TEST_ASSET_KUBE_APISERVER=_test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/kube-apiserver \ @@ -28,7 +32,9 @@ clean: rm -r _test $(OUT) .PHONY: build -build: +build: dependencies + go run cmd/buildnumber.go + go build -o $(IMAGE_NAME) docker build -t "$(IMAGE_NAME):$(IMAGE_TAG)" . .PHONY: rendered-manifest.yaml diff --git a/cmd/buildnumber.go b/cmd/buildnumber.go new file mode 100644 index 0000000..2240ead --- /dev/null +++ b/cmd/buildnumber.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "os" + "strconv" + "strings" + "time" +) + +func main() { + // Load the file content + vFileData, _ := os.ReadFile("version.txt") + + // Convert from Byte array to string and split + // on newlines. We now have a slice of strings + vLines := strings.Split(string(vFileData), "\n") + + // Generate a timestamp. + bTime := time.Now().Format("20060102-1504") + + // Load the count from the 3rd line of the file + // It's a string so we need to convert to integer + // Then increment it by 1 + bNum, _ := strconv.Atoi(vLines[2]) + bNum++ + + // Generate a single string to write back to the file + // Note, we didn't change the version string + outStr := vLines[0] + "\n" + bTime + "\n" + fmt.Sprint(bNum) + + // Write the data back to the file. + _ = os.WriteFile("version.txt", []byte(outStr), 0777) +} diff --git a/deploy/sthome-webhook/values.yaml b/deploy/sthome-webhook/values.yaml index 0ec7e7f..3cabc21 100644 --- a/deploy/sthome-webhook/values.yaml +++ b/deploy/sthome-webhook/values.yaml @@ -32,7 +32,7 @@ image: repository: stuurmcp/cert-manager-webhook-sthome tag: 0.0.3 #pullPolicy should be IfNotPresent. Set to Always for testing purposes - pullPolicy: Always + pullPolicy: IfNotPresent imageCredentials: name: docker-registry-credentials diff --git a/main.go b/main.go index 4254df8..892df38 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main import ( + _ "embed" + "strings" + "os" "github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd" @@ -8,6 +11,13 @@ import ( "github.com/stuurmcp/cert-manager-webhook-sthome/sthome" ) +var ( + // Version : current version + Version string = strings.TrimSpace(version) + //go:embed version.txt + version string +) + var GroupName = os.Getenv("GROUP_NAME") func main() { diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 0000000..e69de29 diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..f688bf2 --- /dev/null +++ b/version.txt @@ -0,0 +1,3 @@ +0.0.3(Alpha) +20240328-0000 +01 \ No newline at end of file