File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,26 @@ RUN --mount=type=cache,target=/go/pkg/mod \
1616# Copy source & build
1717COPY --link . .
1818
19+ # Build binary:
20+ # -a: force rebuild
21+ # -installsuffix cgo: remove cgo support
22+ # -ldflags="-w -s": omits the DWARF symbol table, symbol table and debug information
23+ # -trimpath: remove all file system paths from the compiled executable
24+ # -o /bin/ryuk: output binary to /bin/ryuk
1925RUN --mount=type=cache,target=/go/pkg/mod \
2026 --mount=type=cache,target=/root/.cache/go-build \
21- go build -ldflags '-s' -o /bin/ryuk
27+ go build \
28+ -a \
29+ -installsuffix cgo \
30+ -ldflags="-w -s" \
31+ -trimpath \
32+ -o /bin/ryuk .
33+
34+ # Compress with UPX (trade-off: smaller size vs startup time)
35+ # Note: UPX is not available for s390x architecture
36+ RUN if [ "$(uname -m)" != "s390x" ]; then \
37+ apk add --no-cache upx && upx --best --lzma /bin/ryuk; \
38+ fi
2239
2340# -----------------
2441# Certificates
Original file line number Diff line number Diff line change @@ -21,7 +21,15 @@ USER ContainerUser
2121
2222# Copy source & build
2323COPY . .
24- RUN go build -v -ldflags "-s" -o /bin/ryuk
24+ # Build binary:
25+ # -a: force rebuild
26+ # -installsuffix cgo: remove cgo support
27+ # -ldflags="-w -s": omits the DWARF symbol table, symbol table and debug information
28+ # -trimpath: remove all file system paths from the compiled executable
29+ # -o /bin/ryuk: output binary to /bin/ryuk
30+ RUN go build -a -installsuffix cgo -ldflags="-w -s" -trimpath -o /bin/ryuk .
31+
32+ # Do not optimise with UPX on Windows, as nanoserver does not have PowerShell to install it
2533
2634# -----------------
2735# Distributed Image
You can’t perform that action at this time.
0 commit comments