Skip to content

Commit b42fae2

Browse files
Fix ARM64 container startup failure due to dynamic OPA linking (#293)
* Fix ARM64 container startup failure due to dynamic OPA linking * Added comments about why we avoid dynamic linking * ombines both improvements
1 parent 368ddee commit b42fae2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,25 @@ FROM golang:bullseye AS opa_build
5858
COPY 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
6273
RUN --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 \

0 commit comments

Comments
 (0)