Fully automated versioning
This commit is contained in:
parent
9748b34f19
commit
2b74e52b82
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ charts
|
||||
_test
|
||||
icon
|
||||
vendor
|
||||
_out
|
||||
|
||||
35
Makefile
35
Makefile
@ -2,8 +2,11 @@ GO ?= $(shell which go)
|
||||
OS ?= $(shell $(GO) env GOOS)
|
||||
ARCH ?= $(shell $(GO) env GOARCH)
|
||||
|
||||
IMAGE_NAME := "cert-manager-webhook-sthome"
|
||||
IMAGE_TAG := "0.0.3-alpha.2"
|
||||
IMAGE_NAME := cert-manager-webhook-sthome
|
||||
IMAGE_TAG = "0.0.3"
|
||||
|
||||
TMP = \Temp\gotemp
|
||||
export TMP
|
||||
|
||||
OUT := $(shell pwd)/_out
|
||||
|
||||
@ -13,7 +16,15 @@ HELM_FILES := $(shell find deploy/sthome-webhook)
|
||||
|
||||
dependencies:
|
||||
go mod tidy
|
||||
go mod vendor
|
||||
# go mod vendor
|
||||
|
||||
bin/buildversion.exe: cmd/buildversion.go
|
||||
set TMP="C:\Temp\gotemp"
|
||||
go build -o bin/buildversion.exe cmd/buildversion.go
|
||||
set TMP="C:\Users\Chris\AppData\Local\Temp"
|
||||
|
||||
version.txt: bin/buildversion.exe
|
||||
bin/buildversion.exe
|
||||
|
||||
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 \
|
||||
@ -31,21 +42,25 @@ _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH)/etcd _test/kubebuilder-$(
|
||||
clean:
|
||||
rm -r _test $(OUT)
|
||||
|
||||
.PHONY: package
|
||||
package: rendered-manifest.yaml
|
||||
helm package deploy\sthome-webhook -d \\\truenas\Shared_data\Chris\clusterissuer\charts\
|
||||
|
||||
.PHONY: build
|
||||
build: dependencies
|
||||
go run cmd/buildnumber.go
|
||||
docker build -t "$(IMAGE_NAME):$(IMAGE_TAG)" .
|
||||
docker tag $(IMAGE_NAME) "docker.io/stuurmcp/$(IMAGE_NAME):$(IMAGE_TAG)"
|
||||
docker image push "stuurmcp/$(IMAGE_NAME):$(IMAGE_TAG)"
|
||||
build: rendered-manifest.yaml dependencies version.txt
|
||||
docker build -t "$(IMAGE_NAME):$(shell head -n 1 version.txt)" .
|
||||
docker tag $(IMAGE_NAME) "docker.io/stuurmcp/$(IMAGE_NAME):$(shell head -n 1 version.txt)"
|
||||
docker image push "stuurmcp/$(IMAGE_NAME):$(shell head -n 1 version.txt)"
|
||||
helm package deploy\sthome-webhook -d \\\truenas\Shared_data\Chris\clusterissuer\charts\
|
||||
|
||||
.PHONY: rendered-manifest.yaml
|
||||
rendered-manifest.yaml: $(OUT)/rendered-manifest.yaml
|
||||
|
||||
$(OUT)/rendered-manifest.yaml: $(HELM_FILES) | $(OUT)
|
||||
helm template \
|
||||
--name sthome-webhook \
|
||||
sthome-webhook -n sthome-webhook2\
|
||||
--set image.repository=$(IMAGE_NAME) \
|
||||
--set image.tag=$(IMAGE_TAG) \
|
||||
--set image.tag=$(shell head -n 1 version.txt) \
|
||||
deploy/sthome-webhook > $@
|
||||
|
||||
_test $(OUT) _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH):
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "0.0.3-alpha.2"
|
||||
buildTime string
|
||||
)
|
||||
|
||||
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.
|
||||
buildTime = 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 := version + "\n" + buildTime + "\n" + fmt.Sprint(bNum)
|
||||
|
||||
// Write the data back to the file.
|
||||
_ = os.WriteFile("version.txt", []byte(outStr), 0777)
|
||||
}
|
||||
78
cmd/buildversion.go
Normal file
78
cmd/buildversion.go
Normal file
@ -0,0 +1,78 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
version = "0.0.3-alpha.2"
|
||||
chartfile = "./deploy/sthome-webhook/Chart.yaml"
|
||||
valuesfile = "./deploy/sthome-webhook/values.yaml"
|
||||
tagprefix = " tag: "
|
||||
versiontxt = "./version.txt"
|
||||
apiVersion = "v1"
|
||||
description = "Cert-Manager webhook for sthome"
|
||||
name = "sthome-webhook"
|
||||
)
|
||||
|
||||
var (
|
||||
mfimagetag string
|
||||
vfimagetag string
|
||||
buildTime string
|
||||
appVersion string
|
||||
longversion string
|
||||
versiontext string
|
||||
)
|
||||
|
||||
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.
|
||||
buildTime = 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++
|
||||
longversion = version + "." + fmt.Sprint(bNum)
|
||||
mfimagetag = longversion
|
||||
appVersion = "v" + longversion
|
||||
// Generate a single string to write back to the file
|
||||
versiontext = longversion + "\n" + buildTime + "\n" + fmt.Sprint(bNum)
|
||||
chartStr := "apiVersion: " + apiVersion + "\nappVersion: " + appVersion + "\ndescription: " + description + "\nname: " + name + "\nversion: " + longversion + "\n"
|
||||
// Write the data back to the file.
|
||||
_ = os.WriteFile(versiontxt, []byte(versiontext), 0777)
|
||||
_ = os.WriteFile(chartfile, []byte(chartStr), 0777)
|
||||
replacetxtfilelines(valuesfile, tagprefix, tagprefix+longversion)
|
||||
}
|
||||
|
||||
func replacetxtfilelines(filename string, textLinePrefix string, replacetext string) {
|
||||
input, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
lines := strings.Split(string(input), "\n")
|
||||
|
||||
for i, line := range lines {
|
||||
if strings.HasPrefix(line, textLinePrefix) {
|
||||
lines[i] = replacetext
|
||||
}
|
||||
}
|
||||
output := strings.Join(lines, "\n")
|
||||
err = os.WriteFile(filename, []byte(output), 0644)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
apiVersion: v1
|
||||
appVersion: "v0.0.3-alpha.2"
|
||||
appVersion: v0.0.3-alpha.2.39
|
||||
description: Cert-Manager webhook for sthome
|
||||
name: sthome-webhook
|
||||
version: 0.0.3-alpha.2
|
||||
|
||||
version: 0.0.3-alpha.2.39
|
||||
|
||||
@ -31,7 +31,7 @@ clusterIssuer:
|
||||
image:
|
||||
repository: stuurmcp/cert-manager-webhook-sthome
|
||||
#repository: wstat.sthome.net:5000/cert-manager-webhook-sthome
|
||||
tag: 0.0.3-alpha.2
|
||||
tag: 0.0.3-alpha.2.39
|
||||
#pullPolicy should be IfNotPresent. Set to Always for testing purposes
|
||||
pullPolicy: IfNotPresent
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ func (loc *LocalDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error
|
||||
fmt.Sprintf("arg5=%s", ch.Key),
|
||||
}
|
||||
success, _ := Execute(dnsUpdaterScript, command)
|
||||
klog.InfoS("CZ: Execute returned", "success", success)
|
||||
klog.InfoS("CZ: Execute set returned", "success", success)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -108,7 +108,8 @@ func (loc *LocalDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error
|
||||
"arg4=TXT",
|
||||
fmt.Sprintf("arg5=%s", ch.Key),
|
||||
}
|
||||
Execute(dnsUpdaterScript, command)
|
||||
success, _ := Execute(dnsUpdaterScript, command)
|
||||
klog.InfoS("CZ: Execute unset returned", "success", success)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
0.0.3-alpha.2
|
||||
20240329-1707
|
||||
27
|
||||
0.0.3-alpha.2.39
|
||||
20240330-0131
|
||||
39
|
||||
Loading…
Reference in New Issue
Block a user