diff --git a/.vscode/settings.json b/.vscode/settings.json index 0e1afa8..4a0f365 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { - "terminal.explorerKind": "integrated" + "terminal.explorerKind": "integrated", + "makefile.makePath": "C:\\MinGW\\msys\\1.0\\bin\\make.exe", + "makefile.makefilePath": "./Makefile", + "makefile.buildLog": "./makefile.log" } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index aee2198..ad21908 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,13 +29,12 @@ RUN apk add --no-cache ca-certificates RUN apk add --no-cache zsh bash bind-tools coreutils krb5 tcpdump COPY ./config/zsh.sh /root/.zshrc COPY ./config/bash.sh /root/.bashrc -#COPY ./config/krb5.conf /etc + RUN chown -R root:root /root/.zshrc && \ chown -R root:root /root/.bashrc && \ /bin/zsh /root/.zshrc RUN apk add --no-cache alpine-conf && \ setup-timezone -z Africa/Johannesburg -# chmod 0644 /etc/krb5.conf ENV RUNNING_IN_DOCKER true ENV DEBIAN_FRONTEND=noninteractive diff --git a/Makefile b/Makefile index ea55fef..3ad2253 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,15 @@ -GO ?= $(shell which go) +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" +IMAGE_SHORTNAME := sthome-webhook +IMAGE_NAMESPACE := ix-$(IMAGE_SHORTNAME)2 +DEPLOY_DIR := deploy/$(IMAGE_SHORTNAME) +IMAGE_TAG = "0.0.3" + +SHARED_DIR := //truenas/Shared_data/Chris/clusterissuer/charts +CHART_FILE := $(SHARED_DIR)/$(IMAGE_NAME)- TMP = \Temp\gotemp export TMP @@ -12,7 +18,7 @@ OUT := $(shell pwd)/_out KUBEBUILDER_VERSION=1.28.0 -HELM_FILES := $(shell find "deploy/sthome-webhook") +HELM_FILES := $(shell find "$(DEPLOY_DIR)") dependencies: go mod tidy @@ -23,11 +29,6 @@ bin/buildversion.exe: cmd/buildversion.go go build -o bin/buildversion.exe cmd/buildversion.go set TMP="C:\Users\Chris\AppData\Local\Temp" -#bin/cert-manager-webhook-sthome.exe: dependencies version.txt -# set TMP="C:\Temp\gotemp" -# go build -o bin/cert-manager-webhook-sthome.exe -# set TMP="C:\Users\Chris\AppData\Local\Temp" - version.txt: bin/buildversion.exe dependencies bin/buildversion.exe @@ -48,21 +49,23 @@ clean: rm -r _test $(OUT) .PHONY: build -build: rendered-manifest.yaml dependencies bin/buildversion.exe version.txt +build: dependencies bin/buildversion.exe version.txt docker build --pull --rm -f "Dockerfile" -t "stuurmcp/$(IMAGE_NAME):latest" -t "stuurmcp/$(IMAGE_NAME):$(shell head -n 1 version.txt)" "." docker image push "docker.io/stuurmcp/$(IMAGE_NAME):$(shell head -n 1 version.txt)" + helm package -n $(IMAGE_NAMESPACE) --version $(shell head -n 1 version.txt) $(DEPLOY_DIR) -d $(SHARED_DIR)/ docker image push "docker.io/stuurmcp/$(IMAGE_NAME):latest" - helm package -n ix-sthome-webhook2 --version $(shell head -n 1 version.txt) deploy/sthome-webhook -d //truenas/Shared_data/Chris/clusterissuer/charts/ + +.PHONY: chart +chart: $(CHART_FILE).tgz + + $(CHART_FILE).tgz: $(HELM_FILES) + helm package -n $(IMAGE_NAMESPACE) --version $(shell head -n 1 version.txt) $(DEPLOY_DIR) -d $(SHARED_DIR)/ .PHONY: rendered-manifest.yaml rendered-manifest.yaml: $(OUT)/rendered-manifest.yaml $(OUT)/rendered-manifest.yaml: $(HELM_FILES) | $(OUT) - helm template \ - sthome-webhook -n ix-sthome-webhook2\ - --set image.repository=$(IMAGE_NAME) \ - --set image.tag=$(shell head -n 1 version.txt) \ - deploy/sthome-webhook > $@ + helm template $(IMAGE_SHORTNAME) -n $(IMAGE_NAMESPACE) --set image.repository=$(IMAGE_NAME) --set image.tag=$(shell head -n 1 version.txt) $(DEPLOY_DIR) > $@ _test $(OUT) _test/kubebuilder-$(KUBEBUILDER_VERSION)-$(OS)-$(ARCH): mkdir -p $@ diff --git a/deploy/sthome-webhook/Chart.yaml b/deploy/sthome-webhook/Chart.yaml index 21d1692..3610e89 100644 --- a/deploy/sthome-webhook/Chart.yaml +++ b/deploy/sthome-webhook/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 -appVersion: v0.0.5-alpha.77 +appVersion: v0.0.5-alpha.90 description: Cert-Manager webhook for sthome name: sthome-webhook -version: 0.0.5-alpha.77 +version: 0.0.5-alpha.90 diff --git a/deploy/sthome-webhook/values.yaml b/deploy/sthome-webhook/values.yaml index 5aa11f8..594d915 100644 --- a/deploy/sthome-webhook/values.yaml +++ b/deploy/sthome-webhook/values.yaml @@ -31,7 +31,7 @@ clusterIssuer: image: repository: stuurmcp/cert-manager-webhook-sthome #repository: wstat.sthome.net:5000/cert-manager-webhook-sthome - tag: 0.0.5-alpha.77 + tag: 0.0.5-alpha.90 #pullPolicy should be IfNotPresent. Set to Always for testing purposes pullPolicy: IfNotPresent diff --git a/pkg/dns/shell.go b/pkg/dns/shell.go index fbb661b..e88e177 100644 --- a/pkg/dns/shell.go +++ b/pkg/dns/shell.go @@ -3,6 +3,8 @@ package dns import ( "bytes" "fmt" + "io" + "os" "os/exec" "strings" @@ -33,3 +35,22 @@ func Execute(shell string, arg ...string) (bool, error) { klog.Infof("Script returned success\n") return true, nil } + +// https://blog.kowalczyk.info/article/wOYk/advanced-command-execution-in-go-with-osexec.html +func Execute2(shell string, arg ...string) (bool, error) { + var stdoutBuf, stderrBuf bytes.Buffer + cmd := exec.Command(shell, arg...) + cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) + cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) + + err := cmd.Run() + if err != nil { + klog.Errorf("Script returned error:\nerr:\n") + klog.Errorf("%s\n============\n", err) + return false, err + } + outStr, errStr := string(stdoutBuf.String()), string(stderrBuf.String()) + fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr) + klog.Infof("Script returned success\n") + return true, nil +} diff --git a/pkg/dns/solver_local.go b/pkg/dns/solver_local.go index 02d617c..c85a749 100644 --- a/pkg/dns/solver_local.go +++ b/pkg/dns/solver_local.go @@ -52,7 +52,7 @@ func (loc *LocalDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error } // TODO: convert shell script to golang //localip := GetOutboundIP(Dnsserver_net) - success, err := Execute( + success, err := Execute2( Shell, // "-c", AcmeAuthCmd, @@ -81,7 +81,7 @@ func (loc *LocalDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error func (loc *LocalDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error { //domainName := extractDomainName(ch.ResolvedZone) //localip := GetOutboundIP(Dnsserver_net) - success, err := Execute( + success, err := Execute2( Shell, // "-c", AcmeAuthCmd, diff --git a/pkg/util/wait.go b/pkg/util/wait.go index dc6483b..35abba2 100644 --- a/pkg/util/wait.go +++ b/pkg/util/wait.go @@ -151,7 +151,7 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro } klog.Infof("%q: must be %s", fqdn, value) - klog.Infof("r.Answer: %s", r.Answer) + //klog.Infof("r.Answer: %s", r.Answer) var found bool var i = 0 for _, rr := range r.Answer { diff --git a/version.txt b/version.txt index 3891ec3..991435c 100644 --- a/version.txt +++ b/version.txt @@ -1,3 +1,3 @@ -0.0.5-alpha.77 -20240414-1206 -77 \ No newline at end of file +0.0.5-alpha.90 +20240416-2039 +90 \ No newline at end of file