Skip to content

Commit

Permalink
Merge pull request #501 from uselagoon/fix-build
Browse files Browse the repository at this point in the history
Improve local development experience
  • Loading branch information
smlx authored Feb 6, 2025
2 parents f8ebda3 + 435eafa commit 8285ae8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
1 change: 0 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssh-portal-api/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -31,7 +31,7 @@ func (*VersionCmd) Run() error {
version,
commit,
date,
goVersion,
runtime.Version(),
})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssh-portal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -31,7 +31,7 @@ func (*VersionCmd) Run() error {
version,
commit,
date,
goVersion,
runtime.Version(),
})
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/ssh-token/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -31,7 +31,7 @@ func (*VersionCmd) Run() error {
version,
commit,
date,
goVersion,
runtime.Version(),
})
if err != nil {
return err
Expand Down

0 comments on commit 8285ae8

Please sign in to comment.