From d1219111502d11497f0c499dc8b82f91166128f8 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 4 Feb 2025 15:06:17 +0800 Subject: [PATCH 1/4] chore: update build target command * get runtime version information dynamically * update command syntax for goreleaser 2.x --- .goreleaser.yaml | 1 - Makefile | 4 ++-- cmd/ssh-portal-api/version.go | 4 ++-- cmd/ssh-portal/version.go | 4 ++-- cmd/ssh-token/version.go | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 20ed3840..1319cf5b 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,7 +9,6 @@ builds: -s -w -X "main.commit={{.Commit}}" -X "main.date={{.Date}}" - -X "main.goVersion={{.Env.GOVERSION}}" -X "main.projectName={{.ProjectName}}" -X "main.version=v{{.Version}}" env: diff --git a/Makefile b/Makefile index aacc1ca7..5f7da365 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,8 @@ generate: mod-tidy .PHONY: build build: - GOVERSION=$$(go version) \ - goreleaser build --clean --debug --single-target --snapshot + # build a binary for the local architecture only + goreleaser build --verbose --clean --single-target --snapshot .PHONY: lint lint: diff --git a/cmd/ssh-portal-api/version.go b/cmd/ssh-portal-api/version.go index 6eee5390..f80aa886 100644 --- a/cmd/ssh-portal-api/version.go +++ b/cmd/ssh-portal-api/version.go @@ -3,13 +3,13 @@ package main import ( "encoding/json" "fmt" + "runtime" ) // These variables are set by GoReleaser during the build. var ( commit string date string - goVersion string projectName string version string ) @@ -31,7 +31,7 @@ func (*VersionCmd) Run() error { version, commit, date, - goVersion, + runtime.Version(), }) if err != nil { return err diff --git a/cmd/ssh-portal/version.go b/cmd/ssh-portal/version.go index 6eee5390..f80aa886 100644 --- a/cmd/ssh-portal/version.go +++ b/cmd/ssh-portal/version.go @@ -3,13 +3,13 @@ package main import ( "encoding/json" "fmt" + "runtime" ) // These variables are set by GoReleaser during the build. var ( commit string date string - goVersion string projectName string version string ) @@ -31,7 +31,7 @@ func (*VersionCmd) Run() error { version, commit, date, - goVersion, + runtime.Version(), }) if err != nil { return err diff --git a/cmd/ssh-token/version.go b/cmd/ssh-token/version.go index 6eee5390..f80aa886 100644 --- a/cmd/ssh-token/version.go +++ b/cmd/ssh-token/version.go @@ -3,13 +3,13 @@ package main import ( "encoding/json" "fmt" + "runtime" ) // These variables are set by GoReleaser during the build. var ( commit string date string - goVersion string projectName string version string ) @@ -31,7 +31,7 @@ func (*VersionCmd) Run() error { version, commit, date, - goVersion, + runtime.Version(), }) if err != nil { return err From 0f1b00e5f3dc518ff5c47efbc820ef02a5e50cec Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 4 Feb 2025 15:07:13 +0800 Subject: [PATCH 2/4] chore: add release-snapshot Makefile target This target will build all architectures and docker images. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 5f7da365..e0d82b3f 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,12 @@ build: # build a binary for the local architecture only goreleaser build --verbose --clean --single-target --snapshot +.PHONY: release-snapshot +release-snapshot: + # build binaries for all architectures, and multi-arch docker images, but + # don't validate or publish anything + GITHUB_REPOSITORY=uselagoon goreleaser release --verbose --clean --snapshot + .PHONY: lint lint: golangci-lint run --enable gocritic From 8469896907cbf2f8f04d00bd00be98d6202f5090 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Tue, 4 Feb 2025 15:18:27 +0800 Subject: [PATCH 3/4] chore: add more local development instructions to README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 38f65068..2a42514d 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,21 @@ This helps to correlate error messages reported by users with detailed errors in ## Development tips +### Build locally + +The build process requires [goreleaser](https://github.com/goreleaser/goreleaser) 2.x to be installed in your path. + +`make build` will build a binary for your local architecture in `dist/`. + +`make release-snapshot` will build binaries and docker images for all configured architectures. + +### Running tests + +`make test` will run the test suite. +It regenerates code, so requires [mockgen](https://github.com/uber-go/mock/) and [enumer](https://github.com/dmarkham/enumer/) to be installed in your path. + +Alternatively you can just run `go test -v ./...` manually to avoid regenerating any code. + ### Debugging Keycloak permissions A command to debug Keycloak permissions locally is included in `./cmd/keycloak-debug`. From 435eafa303f50baafadba1bc2368655f4efbb52e Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Wed, 5 Feb 2025 09:26:20 +0800 Subject: [PATCH 4/4] chore: add manual build commands --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 2a42514d..14e6c6f4 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,17 @@ The build process requires [goreleaser](https://github.com/goreleaser/goreleaser `make release-snapshot` will build binaries and docker images for all configured architectures. +### Build manually + +Regular `go build` / `docker build` also works with the right incantations: + +```bash +# example manual build command for ssh-portal binary/image +# adjust as required for other binaries/architectures +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o dist/ssh-portal ./cmd/ssh-portal +docker build --build-arg=BINARY=dist/ssh-portal -t foo/ssh-portal:v99 --platform=linux/amd64 . +``` + ### Running tests `make test` will run the test suite.