Merge pull request #1773 from fluxcd/backport-1725-to-release/v1.5.x
[release/v1.5.x] Build controller without CGO
This commit is contained in:
commit
68d5d6d367
39
Dockerfile
39
Dockerfile
|
@ -1,30 +1,16 @@
|
||||||
ARG BASE_VARIANT=alpine
|
|
||||||
ARG GO_VERSION=1.23
|
ARG GO_VERSION=1.23
|
||||||
ARG XX_VERSION=1.6.1
|
ARG XX_VERSION=1.6.1
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS gostable
|
# Docker buildkit multi-arch build requires golang alpine
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS builder
|
||||||
FROM gostable AS go-linux
|
|
||||||
|
|
||||||
# Build-base consists of build platform dependencies and xx.
|
|
||||||
# These will be used at current arch to yield execute the cross compilations.
|
|
||||||
FROM go-${TARGETOS} AS build-base
|
|
||||||
|
|
||||||
RUN apk add --no-cache clang lld
|
|
||||||
|
|
||||||
|
# Copy the build utilities.
|
||||||
COPY --from=xx / /
|
COPY --from=xx / /
|
||||||
|
|
||||||
# build-go-mod can still be cached at build platform architecture.
|
|
||||||
FROM build-base AS build
|
|
||||||
|
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
|
|
||||||
# Some dependencies have to installed
|
|
||||||
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
|
|
||||||
RUN xx-apk add musl-dev gcc clang lld
|
|
||||||
|
|
||||||
# Configure workspace
|
# Configure workspace
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
|
@ -46,19 +32,9 @@ COPY internal/ internal/
|
||||||
ARG TARGETPLATFORM
|
ARG TARGETPLATFORM
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
|
|
||||||
# Reasons why CGO is in use:
|
# build without specifing the arch
|
||||||
# - The SHA1 implementation (sha1cd) used by go-git depends on CGO for
|
ENV CGO_ENABLED=0
|
||||||
# performance reasons. See: https://github.com/pjbgf/sha1cd/issues/15
|
RUN xx-go build -trimpath -a -o source-controller main.go
|
||||||
ENV CGO_ENABLED=1
|
|
||||||
|
|
||||||
RUN export CGO_LDFLAGS="-static -fuse-ld=lld" && \
|
|
||||||
xx-go build \
|
|
||||||
-ldflags "-s -w" \
|
|
||||||
-tags 'netgo,osusergo,static_build' \
|
|
||||||
-o /source-controller -trimpath main.go;
|
|
||||||
|
|
||||||
# Ensure that the binary was cross-compiled correctly to the target platform.
|
|
||||||
RUN xx-verify --static /source-controller
|
|
||||||
|
|
||||||
FROM alpine:3.21
|
FROM alpine:3.21
|
||||||
|
|
||||||
|
@ -66,8 +42,7 @@ ARG TARGETPLATFORM
|
||||||
RUN apk --no-cache add ca-certificates \
|
RUN apk --no-cache add ca-certificates \
|
||||||
&& update-ca-certificates
|
&& update-ca-certificates
|
||||||
|
|
||||||
# Copy over binary from build
|
COPY --from=builder /workspace/source-controller /usr/local/bin/
|
||||||
COPY --from=build /source-controller /usr/local/bin/
|
|
||||||
|
|
||||||
USER 65534:65534
|
USER 65534:65534
|
||||||
ENTRYPOINT [ "source-controller" ]
|
ENTRYPOINT [ "source-controller" ]
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
apiVersion: source.toolkit.fluxcd.io/v1beta1
|
apiVersion: source.toolkit.fluxcd.io/v1
|
||||||
kind: GitRepository
|
kind: GitRepository
|
||||||
metadata:
|
metadata:
|
||||||
name: large-repo
|
name: large-repo
|
||||||
spec:
|
spec:
|
||||||
interval: 10m
|
interval: 10m
|
||||||
timeout: 2m
|
timeout: 2m
|
||||||
url: https://github.com/hashgraph/hedera-mirror-node.git
|
url: https://github.com/nodejs/node.git
|
||||||
ref:
|
ref:
|
||||||
branch: main
|
branch: main
|
||||||
ignore: |
|
|
||||||
/*
|
|
||||||
!/charts
|
|
||||||
|
|
Loading…
Reference in New Issue