Improved makefile. Running from git bash

This commit is contained in:
Chris Stuurman 2024-04-16 20:56:58 +02:00
parent 71d8934d46
commit d1e49c7bba
9 changed files with 53 additions and 27 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,3 @@
0.0.5-alpha.77
20240414-1206
77
0.0.5-alpha.90
20240416-2039
90