Adding auto versioning

This commit is contained in:
Chris Stuurman 2024-03-28 20:05:44 +02:00
parent 0127488459
commit 334ac1b217
6 changed files with 56 additions and 3 deletions

View File

@ -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

34
cmd/buildnumber.go Normal file
View File

@ -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)
}

View File

@ -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

10
main.go
View File

@ -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() {

0
vendor/modules.txt vendored Normal file
View File

3
version.txt Normal file
View File

@ -0,0 +1,3 @@
0.0.3(Alpha)
20240328-0000
01