Add build script and basic versioning
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-06-09 20:56:44 +02:00
parent ca822496b0
commit 12530471d0
3 changed files with 28 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/kubectl-persistent-logger

13
build.sh Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
gitchanges="false"
if [[ `git status --porcelain` ]]; then
gitchanges="true"
fi
gitsha1=$(git rev-parse HEAD | head -c 9)
buildtime=$(date --iso-8601=seconds)
go build -ldflags "-X main.gitchanges=$gitchanges -X main.gitSHA1=$gitsha1 -X main.buildTime=$buildtime"

14
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"os"
@ -12,16 +13,29 @@ import (
clientconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
)
var (
gitChanges = "unknown"
gitSHA1 = "unknown"
buildTime = "unknown"
)
func main() {
var (
container string
strictExist bool
version bool
)
flag.StringVar(&container, "container", "", "name of a specific container")
flag.BoolVar(&strictExist, "strict", false, "require deployment to exist on launch")
flag.BoolVar(&version, "version", false, "print version and exit")
flag.Parse()
if version {
fmt.Fprintf(os.Stderr, "kubectl-persistent-logger, gitSHA1 = %s, gitChanges = %s, buildTime = %v\n", gitSHA1, gitChanges, buildTime)
os.Exit(0)
}
var params logs.WatcherParams
switch len(flag.Args()) {