fix: use absolute paths and static linking in Dockerfile #49
Reference in New Issue
Block a user
Delete Branch "fix/absolute-path-in-dockerfile"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #48
Problem
The Docker container failed to start with:
Two root causes:
Relative paths:
COPYdestination andCMDused relative paths (./webhooker), depending onWORKDIRcontext.Dynamic linking (the actual root cause): The binary was built with CGO enabled on Debian (glibc) via
make build, but deployed to an Alpine runtime (musl). The kernel couldn't find the glibc dynamic linker (/lib64/ld-linux-x86-64.so.2), producing the misleading "no such file or directory" error — even though the file existed on disk.Fix
Absolute paths throughout:
COPY --from=builder /build/bin/webhooker /app/webhookerandCMD ["/app/webhooker"]— no reliance on WORKDIR.Static rebuild for Alpine: Added a
RUN CGO_ENABLED=1 go build -ldflags '-extldflags "-static"' -o bin/webhooker ./cmd/webhookerstep aftermake check. This rebuilds the binary with static linking so it runs on Alpine without glibc. Themake checkstep still runs normally (formatting, linting, tests, dynamic build) — the static rebuild is only for the deployment binary.Verification
docker build .passes (all checks green)Code Review: PR #49 — fix: use absolute paths and static linking in Dockerfile
Requirements Checklist (Issue #48)
COPYdestination changed from.to/app/webhooker;CMDchanged from["./webhooker"]to["/app/webhooker"]. No WORKDIR dependency.CGO_ENABLED=1 go build -ldflags '-extldflags "-static"') aftermake check, so the deploy binary runs on Alpine without glibc.Policy Compliance Check
No violations found. Specifically verified:
@sha256:hash with version/date comments ✅.golangci.ymlunmodified ✅Makefileunmodified ✅make checkstill runs as build step (fmt-check, lint, test, build) ✅Build Result
docker build .passes — all tests green, all linting passesdlopenandgetaddrinfoin static builds are expected (standard glibc static linking caveats, non-fatal; sqlite amalgamated code doesn't call dlopen at runtime, and Go has a pure-Go DNS fallback)Container Verification
exec ./webhooker: no such file or directory):8080/.well-known/healthcheckresponds with 200Notes
The approach of running
make checkwith a normal CGO build (for tests/linting) followed by a separate static rebuild for the deploy binary is sound. It adds ~2s to the Docker build but maintains the integrity of the check pipeline while producing a binary that actually works on Alpine. The PR description and inline comments clearly explain the rationale.Verdict: PASS ✅
Minimal, correct, well-documented fix that addresses both root causes of the container breakage.