Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve local development experience #501

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading