diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 20ed384..1319cf5 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 aacc1ca..e0d82b3 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,14 @@ 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: 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: diff --git a/README.md b/README.md index 38f6506..14e6c6f 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,32 @@ 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. + +### 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. +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`. diff --git a/cmd/ssh-portal-api/version.go b/cmd/ssh-portal-api/version.go index 6eee539..f80aa88 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 6eee539..f80aa88 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 6eee539..f80aa88 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