Prerequisites
- Go 1.26 or newer
- Git
- pre-commit (recommended for development)
- golangci-lint (required for pre-commit hooks)
Quick Start
Clone and install in one step:GOBIN directory (usually $HOME/go/bin).
Build Methods
go install (Recommended for Development)
Installs the binary directly to yourGOBIN directory:
- Binary installed to
$GOBIN/check-image - Version shows as
dev(no version injection) - Automatically available in PATH if
GOBINis configured
go build (Manual Build)
Builds the binary in the current directory:- Binary created as
./check-image - Version shows as
dev(no version injection) - Must manually move to PATH if desired
Production Build (with Version Injection)
For production builds with correct version information:-s -w: Strip debug information and symbol table (reduces binary size)-X: Inject version variables at build time
Cross-Compilation
Build for different platforms:Pre-Commit Hooks
Pre-commit hooks enforce code quality standards before each commit.Installation
-
Install pre-commit framework:
-
Install golangci-lint:
-
(Optional) Install gosec for security scanning:
-
Install the hooks:
Usage
Hooks run automatically ongit commit:
What Hooks Check
See.pre-commit-config.yaml for the complete configuration.
File quality:
- Trailing whitespace
- End-of-file newlines
- Mixed line endings
- Large files (>1MB)
- YAML syntax
- JSON syntax
- hadolint linting
- actionlint validation
gofmtformattinggo mod tidygo vetanalysisgolangci-lintlintinggo testwith race detection
gosecscanning (warning only, doesn’t block)
- Conventional Commits format validation
Version Injection
The version system uses Go’s ldflags to inject build metadata.How It Works
Version variables are defined ininternal/version/version.go:
-ldflags:
When Version Injection Happens
Production builds:- Pre-built binaries from releases (GoReleaser)
- Docker images (Dockerfile with build args)
- Homebrew formula (via GoReleaser)
go install→ version isdevgo buildwithout ldflags → version isdev
GoReleaser Configuration
See.goreleaser.yml for the release build configuration:
{{.Version}}: Release version (e.g.,0.19.4){{.ShortCommit}}: 7-character commit hash{{.Date}}: RFC3339 UTC timestamp
Docker Build Args
The Dockerfile accepts build arguments:VERSION=dev, COMMIT=none, BUILD_DATE=unknown
Dependencies
Managing Dependencies
Download dependencies:Key Dependencies
Seego.mod for the complete list:
- github.com/spf13/cobra: CLI command structure
- github.com/google/go-containerregistry: Container registry operations
- github.com/sirupsen/logrus: Structured logging
- github.com/mattn/go-isatty: Terminal detection
- github.com/stretchr/testify: Test assertions
- gopkg.in/yaml.v3: YAML parsing
The project minimizes external dependencies and prefers the Go standard library where possible.
Troubleshooting
Binary Not Found After Install
EnsureGOBIN is in your PATH:
Pre-Commit Hook Failures
Run the specific hook to see detailed errors:Module Download Failures
Clear the module cache:Next Steps
Testing
Run tests and check coverage
Architecture
Understand the codebase structure