A single static binary
Static means the binary bundles everything it needs. You can copy it to any Linux machine of the same arch and it runs. That is the property you want for dropping the agent into a CI runner, a sandbox VM, or a distroless image.
terminal
bash
# Build and inspect
go build -ldflags="-s -w" -o bin/agent .
file bin/agent
# bin/agent: ELF 64-bit LSB executable, statically linked, ...
# Confirm no dynamic libs
ldd bin/agent
# not a dynamic executable
# Size check
du -h bin/agent
# around 8M on amd64file confirms the binary is statically linked. ldd reports "not a dynamic executable", which is the gold standard for container deployments.
terminal
bash
# Cross-compile for Linux from macOS or Windows
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/agent-linux-amd64 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/agent-linux-arm64 .
# Drop either into distroless and you are done.Cross-compilation is a one-liner in Go. Build on your laptop, ship to a remote arch, no emulator needed.
Quiz: Quiz
Loading practice…