Skip to content

Commit 49e3562

Browse files
author
Paulo Gomes
committed
Remove MUSL dependencies
Signed-off-by: Paulo Gomes <[email protected]>
1 parent 46e4f99 commit 49e3562

File tree

4 files changed

+16
-132
lines changed

4 files changed

+16
-132
lines changed

Dockerfile

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ ARG BASE_VARIANT=alpine
22
ARG GO_VERSION=1.18
33
ARG XX_VERSION=1.1.0
44

5-
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2-all
6-
ARG LIBGIT2_TAG=v0.1.2
5+
ARG LIBGIT2_IMG=ghcr.io/pjbgf/golang-with-libgit2-only
6+
ARG LIBGIT2_TAG=v0.0.9
77

88
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} AS libgit2-libs
99

@@ -37,23 +37,6 @@ COPY go.sum go.sum
3737
# Cache modules
3838
RUN go mod download
3939

40-
# The musl-tool-chain layer is an adhoc solution
41-
# for the problem in which xx gets confused during compilation
42-
# and a) looks for gold linker and then b) cannot find musl's dynamic linker.
43-
FROM --platform=$BUILDPLATFORM alpine as musl-tool-chain
44-
45-
COPY --from=xx / /
46-
47-
RUN apk add bash curl tar
48-
49-
WORKDIR /workspace
50-
COPY hack/download-musl.sh .
51-
52-
ARG TARGETPLATFORM
53-
ARG TARGETARCH
54-
RUN ROOT_DIR="$(pwd)" TARGET_ARCH="$(xx-info alpine-arch)" ENV_FILE=true \
55-
./download-musl.sh
56-
5740
# Build stage install per target platform
5841
# dependency and effectively cross compile the application.
5942
FROM build-go-mod as build
@@ -64,7 +47,7 @@ COPY --from=libgit2-libs /usr/local/ /usr/local/
6447

6548
# Some dependencies have to installed
6649
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
67-
RUN xx-apk add musl-dev gcc lld
50+
RUN xx-apk add musl-dev gcc clang lld
6851

6952
WORKDIR /workspace
7053

@@ -74,20 +57,14 @@ COPY controllers/ controllers/
7457
COPY pkg/ pkg/
7558
COPY internal/ internal/
7659

77-
COPY --from=musl-tool-chain /workspace/build /workspace/build
78-
7960
ARG TARGETPLATFORM
8061
ARG TARGETARCH
8162
ENV CGO_ENABLED=1
8263

83-
# Performance related changes:
84-
# - Use read-only bind instead of copying go source files.
85-
# - Cache go packages.
86-
RUN export $(cat build/musl/$(xx-info alpine-arch).env | xargs) && \
87-
export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" && \
88-
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
89-
export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libssh2 openssl libgit2) -static" && \
90-
GOARCH=$TARGETARCH go build \
64+
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)" && \
65+
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig" && \
66+
export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libgit2) -static" && \
67+
xx-go build \
9168
-ldflags "-s -w" \
9269
-tags 'netgo,osusergo,static_build' \
9370
-o /image-automation-controller -trimpath main.go;

Makefile

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ TAG ?= latest
77
CRD_OPTIONS ?= crd:crdVersions=v1
88

99
# Base image used to build the Go binary
10-
LIBGIT2_IMG ?= ghcr.io/fluxcd/golang-with-libgit2-all
11-
LIBGIT2_TAG ?= v0.1.2
10+
LIBGIT2_IMG ?= ghcr.io/pjbgf/golang-with-libgit2-only
11+
LIBGIT2_TAG ?= v0.0.9
1212

1313
# Allows for defining additional Docker buildx arguments,
1414
# e.g. '--push'.
@@ -42,37 +42,20 @@ LIBGIT2_PATH := $(BUILD_DIR)/libgit2/$(LIBGIT2_TAG)
4242
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib
4343
LIBGIT2_LIB64_PATH := $(LIBGIT2_PATH)/lib64
4444
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.a
45-
MUSL-CC =
4645

4746
export CGO_ENABLED=1
4847
export PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig
4948
export LIBRARY_PATH=$(LIBGIT2_LIB_PATH)
5049
export CGO_CFLAGS=-I$(LIBGIT2_PATH)/include -I$(LIBGIT2_PATH)/include/openssl
51-
50+
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libgit2 2>/dev/null)
5251

5352
# The pkg-config command will yield warning messages until libgit2 is downloaded.
5453
ifeq ($(shell uname -s),Darwin)
55-
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libssh2 openssl libgit2 2>/dev/null)
5654
GO_STATIC_FLAGS=-ldflags "-s -w" -tags 'netgo,osusergo,static_build'
57-
else
58-
export PKG_CONFIG_PATH:=$(PKG_CONFIG_PATH):$(LIBGIT2_LIB64_PATH)/pkgconfig
59-
export LIBRARY_PATH:=$(LIBRARY_PATH):$(LIBGIT2_LIB64_PATH)
60-
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libssh2 openssl libgit2 2>/dev/null)
6155
endif
6256

6357
ifeq ($(shell uname -s),Linux)
64-
ifeq ($(shell uname -m),x86_64)
65-
# Linux x86_64 seem to be able to cope with the static libraries
66-
# by having only musl-dev installed, without the need of using musl toolchain.
6758
GO_STATIC_FLAGS=-ldflags "-s -w" -tags 'netgo,osusergo,static_build'
68-
else
69-
MUSL-PREFIX=$(BUILD_DIR)/musl/$(shell uname -m)-linux-musl-native/bin/$(shell uname -m)-linux-musl
70-
MUSL-CC=$(MUSL-PREFIX)-gcc
71-
export CC=$(MUSL-PREFIX)-gcc
72-
export CXX=$(MUSL-PREFIX)-g++
73-
export AR=$(MUSL-PREFIX)-ar
74-
GO_STATIC_FLAGS=-ldflags "-s -w -extldflags \"-static\"" -tags 'netgo,osusergo,static_build'
75-
endif
7659
endif
7760

7861
# API (doc) generation utilities
@@ -213,16 +196,11 @@ controller-gen: ## Download controller-gen locally if necessary.
213196
libgit2: $(LIBGIT2) ## Detect or download libgit2 library
214197

215198
COSIGN = $(GOBIN)/cosign
216-
$(LIBGIT2): $(MUSL-CC)
199+
$(LIBGIT2):
217200
$(call go-install-tool,$(COSIGN),github.com/sigstore/cosign/cmd/cosign@latest)
218201

219202
IMG=$(LIBGIT2_IMG) TAG=$(LIBGIT2_TAG) PATH=$(PATH):$(GOBIN) ./hack/install-libraries.sh
220203

221-
$(MUSL-CC):
222-
ifneq ($(shell uname -s),Darwin)
223-
./hack/download-musl.sh
224-
endif
225-
226204
# Find or download gen-crd-api-reference-docs
227205
GEN_CRD_API_REFERENCE_DOCS = $(GOBIN)/gen-crd-api-reference-docs
228206
.PHONY: gen-crd-api-reference-docs

hack/download-musl.sh

Lines changed: 0 additions & 71 deletions
This file was deleted.

hack/install-libraries.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -euxo pipefail
55
IMG="${IMG:-}"
66
TAG="${TAG:-}"
77
IMG_TAG="${IMG}:${TAG}"
8-
DOWNLOAD_URL="https://github.com/fluxcd/golang-with-libgit2/releases/download/${TAG}"
8+
DOWNLOAD_URL="https://github.com/pjbgf/golang-with-libgit2/releases/download/${TAG}"
99

1010
TMP_DIR=$(mktemp -d)
1111

@@ -136,11 +136,11 @@ install_libraries(){
136136
fi
137137
fi
138138

139-
FILE_NAME="linux-$(uname -m)-all-libs.tar.gz"
140-
DIR="libgit2-linux-all-libs"
139+
FILE_NAME="linux-$(uname -m)-libgit2-only.tar.gz"
140+
DIR="linux-libgit2-only"
141141
if [[ $OSTYPE == 'darwin'* ]]; then
142-
FILE_NAME="darwin-all-libs.tar.gz"
143-
DIR="darwin-all-libs"
142+
FILE_NAME="darwin-libgit2-only.tar.gz"
143+
DIR="darwin-libgit2-only"
144144
fi
145145

146146
download_files "${FILE_NAME}"

0 commit comments

Comments
 (0)