File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,25 @@ FROM golang:bullseye AS opa_build
5858COPY custom* /custom
5959
6060# Build OPA binary if custom_opa.tar.gz is provided
61+
62+ # Fix for ARM64 compatibility issue (#289): Build fully static binary to avoid dynamic linking issues
63+ # Problem: Dynamic linking creates dependencies on system libc (glibc), but Alpine Linux uses musl libc
64+ # Result: Binary fails with "/lib/ld-musl-aarch64.so.1: /app/bin/opa: Not a valid dynamic program"
65+ # Solution: Build a truly static binary with no external libc dependencies
66+ # - CGO_ENABLED=0: Disables CGO to ensure pure Go compilation (eliminates glibc dependency)
67+ # - -a: Forces rebuilding of all packages to ensure clean static build
68+ # - -tags netgo: Uses pure Go network stack instead of C-based libc resolver
69+ # - -s -w: Strips debug info and symbol table to reduce binary size
70+ # - -extldflags=-static: Ensures static linking if CGO were enabled (defense in depth)
71+
6172# Use BuildKit cache mounts for Go modules and build cache for MUCH faster incremental builds
6273RUN --mount=type=cache,target=/go/pkg/mod \
6374 --mount=type=cache,target=/root/.cache/go-build \
6475 if [ -f /custom/custom_opa.tar.gz ]; \
6576 then \
6677 cd /custom && \
6778 tar xzf custom_opa.tar.gz && \
68- go build -ldflags="-extldflags=-static" -o /opa && \
79+ CGO_ENABLED=0 go build -a - ldflags="-s -w - extldflags=-static" -tags netgo -installsuffix netgo -o /opa && \
6980 rm -rf /custom; \
7081 else \
7182 case $(uname -m) in \
You can’t perform that action at this time.
0 commit comments