From 8ef3e201d65f44ebfdf3bee07fd87fb96747f057 Mon Sep 17 00:00:00 2001 From: Thomas Peetz Date: Sat, 24 Oct 2026 02:08:56 +0200 Subject: [PATCH] add version information --- kontor-gin/.gitignore | 2 + kontor-gin/.goreleaser.yaml | 58 ++++++++++++++++++++++++++ kontor-gin/Containerfile | 5 ++- kontor-gin/cibuild | 10 ++++- kontor-gin/cibuild.local | 9 ++++ kontor-gin/go.mod | 4 +- kontor-gin/go.sum | 4 -- kontor-gin/internal/cmd/version.go | 30 +++++++++++++ kontor-gin/internal/globals/globals.go | 10 +++-- 9 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 kontor-gin/.gitignore create mode 100644 kontor-gin/.goreleaser.yaml create mode 100755 kontor-gin/cibuild.local create mode 100644 kontor-gin/internal/cmd/version.go diff --git a/kontor-gin/.gitignore b/kontor-gin/.gitignore new file mode 100644 index 0000000..69dcb52 --- /dev/null +++ b/kontor-gin/.gitignore @@ -0,0 +1,2 @@ +# Added by goreleaser init: +dist/ diff --git a/kontor-gin/.goreleaser.yaml b/kontor-gin/.goreleaser.yaml new file mode 100644 index 0000000..dd65f02 --- /dev/null +++ b/kontor-gin/.goreleaser.yaml @@ -0,0 +1,58 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +builds: + - main: ./... + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - arm64 + - amd64 + - "386" + +archives: + - formats: [tar.gz] + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + formats: [zip] + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + footer: >- + + --- + + Released by [GoReleaser](https://github.com/goreleaser/goreleaser). diff --git a/kontor-gin/Containerfile b/kontor-gin/Containerfile index 0eadfc6..5f09699 100644 --- a/kontor-gin/Containerfile +++ b/kontor-gin/Containerfile @@ -9,8 +9,11 @@ COPY go.mod go.sum ./ RUN go mod download # Copy the source code COPY . . +ARG VERSION="dev" +ARG COMMIT="unset" +ARG DATE="unset" # Build the Go application (strip debug info for smaller size) -RUN go build -trimpath -ldflags="-s -w" -o kontor cmd/kontor/main.go +RUN go build -trimpath -ldflags="-s -w -X kontor-api-gin/internal/globals.Version=${VERSION} -X kontor-api-gin/internal/globals.Commit=${COMMIT} -X kontor-api-gin/internal/globals.Date=${DATE}" -o kontor cmd/kontor/main.go # ---------- Stage 2: Final ---------- FROM alpine:latest diff --git a/kontor-gin/cibuild b/kontor-gin/cibuild index b8b4fb0..dc50a52 100755 --- a/kontor-gin/cibuild +++ b/kontor-gin/cibuild @@ -9,5 +9,13 @@ cd "$(dirname "$0")/.." source version echo " => Baue Image localhost/kontor-gin:$kontorVersion" -buildah build -t kontor-gin:$kontorVersion kontor-gin +buildah build \ + -t kontor-gin:$kontorVersion \ + --build-arg VERSION=0.4.0-SNAPSHOT \ + --build-arg COMMIT=$(git rev-parse HEAD) \ + --build-arg DATE=$(date +%Y-%m-%dT%H:%M:%S) \ + kontor-gin +cd kontor-gin +go build -ldflags "-X kontor-api-gin/internal/cmd.commit=`git rev-parse HEAD` -X kontor-api-gin/internal/cmd.version=0.4.0-SNAPSHOT -X kontor-api-gin/internal/cmd.date=`date +%Y-%m-%dT%H:%M:%S`" -o ~/.local/bin/kontor-cli cmd/kontor-cli/main.go +go build -ldflags "-X kontor-api-gin/internal/globals.Version=0.4.0-SNAPSHOT -X kontor-api-gin/internal/globals.Commit=`git rev-parse HEAD` -X kontor-api-gin/internal/globals.Date=`date +%Y-%m-%dT%H:%M:%S`" -o ~/.local/bin/kontor cmd/kontor/main.go diff --git a/kontor-gin/cibuild.local b/kontor-gin/cibuild.local new file mode 100755 index 0000000..eda80cf --- /dev/null +++ b/kontor-gin/cibuild.local @@ -0,0 +1,9 @@ +#!/bin/bash + +# script/cibuild.inky: + +set -e + +go build -ldflags "-X kontor-api-gin/internal/cmd.commit=`git rev-parse HEAD` -X kontor-api-gin/internal/cmd.version=0.4.0-SNAPSHOT -X kontor-api-gin/internal/cmd.date=`date +%Y-%m-%dT%H:%M:%S`" -o ~/.local/bin/kontor-cli cmd/kontor-cli/main.go + +go build -ldflags "-X kontor-api-gin/internal/globals.Version=0.4.0-SNAPSHOT -X kontor-api-gin/internal/globals.Commit=`git rev-parse HEAD` -X kontor-api-gin/internal/globals.Date=`date +%Y-%m-%dT%H:%M:%S`" -o ~/.local/bin/kontor cmd/kontor/main.go diff --git a/kontor-gin/go.mod b/kontor-gin/go.mod index fc853cc..56eaa3c 100644 --- a/kontor-gin/go.mod +++ b/kontor-gin/go.mod @@ -3,11 +3,11 @@ module kontor-api-gin go 1.26.8 require ( - github.com/JanikL/go-artemis v0.0.0-20250315150102-10f50406b94d github.com/gin-contrib/cors v1.7.2 github.com/gin-contrib/sessions v1.1.2 github.com/gin-contrib/slog v1.1.0 github.com/gin-gonic/gin v1.12.0 + github.com/go-stomp/stomp/v3 v3.1.5 github.com/golang-jwt/jwt/v5 v5.3.1 github.com/google/uuid v1.6.0 github.com/spf13/cobra v1.10.2 @@ -32,8 +32,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.30.3 // indirect - github.com/go-stomp/stomp v2.1.4+incompatible // indirect - github.com/go-stomp/stomp/v3 v3.1.5 // indirect github.com/go-viper/mapstructure/v2 v2.5.0 // indirect github.com/goccy/go-json v0.10.6 // indirect github.com/goccy/go-yaml v1.19.2 // indirect diff --git a/kontor-gin/go.sum b/kontor-gin/go.sum index 699c959..929ca37 100644 --- a/kontor-gin/go.sum +++ b/kontor-gin/go.sum @@ -1,5 +1,3 @@ -github.com/JanikL/go-artemis v0.0.0-20250315150102-10f50406b94d h1:kXaXwcE0eB92pqrluNv1/9IlSJyn56g8Kfl9KdFbHUM= -github.com/JanikL/go-artemis v0.0.0-20250315150102-10f50406b94d/go.mod h1:vVJ6kbfbD0LWMirPFhis2ZZCg5kP6IZYAbRJEGBJwE0= github.com/bytedance/gopkg v0.1.4 h1:oZnQwnX82KAIWb7033bEwtxvTqXcYMxDBaQxo5JJHWM= github.com/bytedance/gopkg v0.1.4/go.mod h1:v1zWfPm21Fb+OsyXN2VAHdL6TBb2L88anLQgdyje6R4= github.com/bytedance/sonic v1.15.4 h1:FgtV/4aBHpla9AxuMpuuzVUpa/Cf3izufkxNmnEzdI8= @@ -36,8 +34,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.30.3 h1:4MU6YkEwx7GbcPJOZxrtbu+QfF3pJLJuaYTeAH0DYy8= github.com/go-playground/validator/v10 v10.30.3/go.mod h1:4Axh7oCNGcoGkqLoE4YWt6n20mcEIsPRlB7vPk3lpyc= -github.com/go-stomp/stomp v2.1.4+incompatible h1:D3SheUVDOz9RsjVWkoh/1iCOwD0qWjyeTZMUZ0EXg2Y= -github.com/go-stomp/stomp v2.1.4+incompatible/go.mod h1:VqCtqNZv1226A1/79yh+rMiFUcfY3R109np+7ke4n0c= github.com/go-stomp/stomp/v3 v3.1.5 h1:Pikz1OSusmSKUm5mRKYfXQZaDatfZ+EnBBA1JJ2xENQ= github.com/go-stomp/stomp/v3 v3.1.5/go.mod h1:ztzZej6T2W4Y6FlD+Tb5n7HQP3/O5UNQiuC169pIp10= github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= diff --git a/kontor-gin/internal/cmd/version.go b/kontor-gin/internal/cmd/version.go new file mode 100644 index 0000000..80eb042 --- /dev/null +++ b/kontor-gin/internal/cmd/version.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "fmt" + "log/slog" + + "github.com/spf13/cobra" +) + +var ( + version = "unset" + commit = "unset" + date = "unset" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Show Kontor Version", + Long: "Show Kontor Version", + Run: func(cmd *cobra.Command, args []string) { + slog.Info("version kontor") + fmt.Println("Version: ", version) + fmt.Println("Version: ", commit) + fmt.Println("Version: ", date) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/kontor-gin/internal/globals/globals.go b/kontor-gin/internal/globals/globals.go index a4b6795..8143cea 100644 --- a/kontor-gin/internal/globals/globals.go +++ b/kontor-gin/internal/globals/globals.go @@ -1,7 +1,11 @@ package globals -var Secret = []byte("secret") +var ( + Secret = []byte("secret") + + Version = "0.4.0" + Commit = "unset" + Date = "unset" +) const UserKey = "user" - -const Version = "0.4.0"