Skip to content

Commit f7a64b1

Browse files
author
Paulo Gomes
authored
Merge pull request #977 from fluxcd/remove-libgit2
Remove libgit2 and git2go from codebase
2 parents aad4060 + cc75764 commit f7a64b1

26 files changed

+128
-2113
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
build/libgit2/
1+
build/

ATTRIBUTIONS.md

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

DEVELOPMENT.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,6 @@ There are a number of dependencies required to be able to run the controller and
1313
- [Install Docker](https://docs.docker.com/engine/install/)
1414
- (Optional) [Install Kubebuilder](https://book.kubebuilder.io/quick-start.html#installation)
1515

16-
The [libgit2](https://libgit2.org/) dependency is now automatically managed by the Makefile logic.
17-
However, it depends on [pkg-config](https://freedesktop.org/wiki/Software/pkg-config/) being installed:
18-
19-
### macOS
20-
21-
```console
22-
$ # Ensure pkg-config is installed
23-
$ brew install pkg-config
24-
```
25-
26-
### Linux
27-
28-
```console
29-
$ # Ensure pkg-config is installed
30-
$ pacman -S pkgconf
31-
```
32-
33-
**Note:** Example shown is for Arch Linux, but likewise procedure can be
34-
followed using any other package manager. Some distributions may have slight
35-
variation of package names (e.g. `apt install -y pkg-config`).
36-
3716
In addition to the above, the following dependencies are also used by some of the `make` targets:
3817

3918
- `controller-gen` (v0.7.0)
@@ -149,18 +128,11 @@ Create a `.vscode/launch.json` file:
149128
"type": "go",
150129
"request": "launch",
151130
"mode": "auto",
152-
"envFile": "${workspaceFolder}/build/.env",
153131
"program": "${workspaceFolder}/main.go"
154132
}
155133
]
156134
}
157135
```
158136

159-
Create the environment file containing details on how to load
160-
`libgit2` dependencies:
161-
```bash
162-
make env
163-
```
164-
165137
Start debugging by either clicking `Run` > `Start Debugging` or using
166138
the relevant shortcut.

Dockerfile

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ ARG BASE_VARIANT=alpine
22
ARG GO_VERSION=1.19
33
ARG XX_VERSION=1.1.2
44

5-
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2-only
6-
ARG LIBGIT2_TAG=v0.4.0
7-
8-
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} AS libgit2-libs
9-
105
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
116

127
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
@@ -17,12 +12,18 @@ FROM gostable AS go-linux
1712
# These will be used at current arch to yield execute the cross compilations.
1813
FROM go-${TARGETOS} AS build-base
1914

20-
RUN apk add --no-cache clang lld pkgconfig
15+
RUN apk add --no-cache clang lld
2116

2217
COPY --from=xx / /
2318

2419
# build-go-mod can still be cached at build platform architecture.
25-
FROM build-base as build-go-mod
20+
FROM build-base as build
21+
22+
ARG TARGETPLATFORM
23+
24+
# Some dependencies have to installed
25+
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
26+
RUN xx-apk add musl-dev gcc clang lld
2627

2728
# Configure workspace
2829
WORKDIR /workspace
@@ -37,21 +38,6 @@ COPY go.sum go.sum
3738
# Cache modules
3839
RUN go mod download
3940

40-
41-
# Build stage install per target platform
42-
# dependency and effectively cross compile the application.
43-
FROM build-go-mod as build
44-
45-
ARG TARGETPLATFORM
46-
47-
COPY --from=libgit2-libs /usr/local/ /usr/local/
48-
49-
# Some dependencies have to installed
50-
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
51-
RUN xx-apk add musl-dev gcc clang lld
52-
53-
WORKDIR /workspace
54-
5541
# Copy source code
5642
COPY main.go main.go
5743
COPY controllers/ controllers/
@@ -60,11 +46,13 @@ COPY internal/ internal/
6046

6147
ARG TARGETPLATFORM
6248
ARG TARGETARCH
49+
50+
# Reasons why CGO is in use:
51+
# - The SHA1 implementation (sha1cd) used by go-git depends on CGO for
52+
# performance reasons. See: https://github.com/pjbgf/sha1cd/issues/15
6353
ENV CGO_ENABLED=1
6454

65-
# Instead of using xx-go, (cross) compile with vanilla go leveraging musl tool chain.
66-
RUN export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig" && \
67-
export CGO_LDFLAGS="$(pkg-config --static --libs --cflags libgit2) -static -fuse-ld=lld" && \
55+
RUN export CGO_LDFLAGS="-static -fuse-ld=lld" && \
6856
xx-go build \
6957
-ldflags "-s -w" \
7058
-tags 'netgo,osusergo,static_build' \
@@ -73,7 +61,6 @@ RUN export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig" && \
7361
# Ensure that the binary was cross-compiled correctly to the target platform.
7462
RUN xx-verify --static /source-controller
7563

76-
7764
FROM alpine:3.16
7865

7966
ARG TARGETPLATFORM
@@ -82,7 +69,6 @@ RUN apk --no-cache add ca-certificates \
8269

8370
# Copy over binary from build
8471
COPY --from=build /source-controller /usr/local/bin/
85-
COPY ATTRIBUTIONS.md /
8672

8773
USER 65534:65534
8874
ENTRYPOINT [ "source-controller" ]

Makefile

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
IMG ?= fluxcd/source-controller
33
TAG ?= latest
44

5-
# Base image used to build the Go binary
6-
LIBGIT2_IMG ?= ghcr.io/fluxcd/golang-with-libgit2-only
7-
LIBGIT2_TAG ?= v0.4.0
8-
95
# Allows for defining additional Go test args, e.g. '-tags integration'.
106
GO_TEST_ARGS ?= -race
117

@@ -39,14 +35,6 @@ ENVTEST_BIN_VERSION ?= 1.24.0
3935
# each fuzzer should run for.
4036
FUZZ_TIME ?= 1m
4137

42-
# Caches libgit2 versions per tag, "forcing" rebuild only when needed.
43-
LIBGIT2_PATH := $(BUILD_DIR)/libgit2/$(LIBGIT2_TAG)
44-
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib
45-
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.a
46-
47-
export CGO_ENABLED=1
48-
export PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig
49-
export CGO_LDFLAGS=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs --static --cflags libgit2 2>/dev/null)
5038
GO_STATIC_FLAGS=-ldflags "-s -w" -tags 'netgo,osusergo,static_build$(addprefix ,,$(GO_TAGS))'
5139

5240
# API (doc) generation utilities
@@ -75,11 +63,11 @@ endif
7563

7664
all: build
7765

78-
build: check-deps $(LIBGIT2) ## Build manager binary
66+
build: check-deps ## Build manager binary
7967
go build $(GO_STATIC_FLAGS) -o $(BUILD_DIR)/bin/manager main.go
8068

8169
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
82-
test: $(LIBGIT2) install-envtest test-api check-deps ## Run all tests
70+
test: install-envtest test-api check-deps ## Run all tests
8371
HTTPS_PROXY="" HTTP_PROXY="" \
8472
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
8573
GIT_CONFIG_GLOBAL=/dev/null \
@@ -88,7 +76,7 @@ test: $(LIBGIT2) install-envtest test-api check-deps ## Run all tests
8876
$(GO_TEST_ARGS) \
8977
-coverprofile cover.out
9078

91-
test-ctrl: $(LIBGIT2) install-envtest test-api check-deps ## Run controller tests
79+
test-ctrl: install-envtest test-api check-deps ## Run controller tests
9280
HTTPS_PROXY="" HTTP_PROXY="" \
9381
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
9482
GIT_CONFIG_GLOBAL=/dev/null \
@@ -105,7 +93,7 @@ endif
10593
test-api: ## Run api tests
10694
cd api; go test $(GO_TEST_ARGS) ./... -coverprofile cover.out
10795

108-
run: $(LIBGIT2) generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
96+
run: generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
10997
go run $(GO_STATIC_FLAGS) ./main.go
11098

11199
install: manifests ## Install CRDs into a cluster
@@ -139,7 +127,7 @@ fmt: ## Run go fmt against code
139127
go fmt ./...
140128
cd api; go fmt ./...
141129

142-
vet: $(LIBGIT2) ## Run go vet against code
130+
vet: ## Run go vet against code
143131
go vet ./...
144132
cd api; go vet ./...
145133

@@ -148,8 +136,6 @@ generate: controller-gen ## Generate API code
148136

149137
docker-build: ## Build the Docker image
150138
docker buildx build \
151-
--build-arg LIBGIT2_IMG=$(LIBGIT2_IMG) \
152-
--build-arg LIBGIT2_TAG=$(LIBGIT2_TAG) \
153139
--platform=$(BUILD_PLATFORMS) \
154140
-t $(IMG):$(TAG) \
155141
$(BUILD_ARGS) .
@@ -182,40 +168,14 @@ install-envtest: setup-envtest ## Download envtest binaries locally.
182168
# setup-envtest sets anything below k8s to 0555
183169
chmod -R u+w $(BUILD_DIR)/testbin
184170

185-
libgit2: $(LIBGIT2) ## Detect or download libgit2 library
186-
187-
COSIGN = $(GOBIN)/cosign
188-
$(LIBGIT2):
189-
$(call go-install-tool,$(COSIGN),github.com/sigstore/cosign/cmd/cosign@latest)
190-
191-
IMG=$(LIBGIT2_IMG) TAG=$(LIBGIT2_TAG) PATH=$(PATH):$(GOBIN) ./hack/install-libraries.sh
192-
193-
194171
.PHONY: help
195172
help: ## Display this help menu
196173
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
197174

198-
update-attributions:
199-
./hack/update-attributions.sh
200-
201175
e2e:
202176
./hack/ci/e2e.sh
203177

204-
verify: update-attributions fmt vet manifests api-docs tidy
205-
ifneq ($(shell grep -o 'LIBGIT2_IMG ?= \w.*' Makefile | cut -d ' ' -f 3):$(shell grep -o 'LIBGIT2_TAG ?= \w.*' Makefile | cut -d ' ' -f 3), \
206-
$(shell grep -o "LIBGIT2_IMG=\w.*" Dockerfile | cut -d'=' -f2):$(shell grep -o "LIBGIT2_TAG=\w.*" Dockerfile | cut -d'=' -f2))
207-
@{ \
208-
echo "LIBGIT2_IMG and LIBGIT2_TAG must match in both Makefile and Dockerfile"; \
209-
exit 1; \
210-
}
211-
endif
212-
ifneq ($(shell grep -o 'LIBGIT2_TAG ?= \w.*' Makefile | cut -d ' ' -f 3), $(shell grep -o "LIBGIT2_TAG=.*" tests/fuzz/oss_fuzz_prebuild.sh | sed 's;LIBGIT2_TAG="$${LIBGIT2_TAG:-;;g' | sed 's;}";;g'))
213-
@{ \
214-
echo "LIBGIT2_TAG must match in both Makefile and tests/fuzz/oss_fuzz_prebuild.sh"; \
215-
exit 1; \
216-
}
217-
endif
218-
178+
verify: fmt vet manifests api-docs tidy
219179
@if [ ! "$$(git status --porcelain --untracked-files=no)" = "" ]; then \
220180
echo "working directory is dirty:"; \
221181
git --no-pager diff; \
@@ -236,7 +196,7 @@ rm -rf $$TMP_DIR ;\
236196
endef
237197

238198
# Build fuzzers used by oss-fuzz.
239-
fuzz-build: $(LIBGIT2)
199+
fuzz-build:
240200
rm -rf $(shell pwd)/build/fuzz/
241201
mkdir -p $(shell pwd)/build/fuzz/out/
242202

@@ -260,15 +220,3 @@ fuzz-native:
260220
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
261221
FUZZ_TIME=$(FUZZ_TIME) \
262222
./tests/fuzz/native_go_run.sh
263-
264-
# Creates an env file that can be used to load all source-controller's dependencies
265-
# this is handy when you want to run adhoc debug sessions on tests or start the
266-
# controller in a new debug session.
267-
env: $(LIBGIT2)
268-
echo 'GO_ENABLED="1"' > $(BUILD_DIR)/.env
269-
echo 'PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"' >> $(BUILD_DIR)/.env
270-
echo 'LIBRARY_PATH="$(LIBRARY_PATH)"' >> $(BUILD_DIR)/.env
271-
echo 'CGO_CFLAGS="$(CGO_CFLAGS)"' >> $(BUILD_DIR)/.env
272-
echo 'CGO_LDFLAGS="$(CGO_LDFLAGS)"' >> $(BUILD_DIR)/.env
273-
echo 'KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)' >> $(BUILD_DIR)/.env
274-
echo 'GIT_CONFIG_GLOBAL=/dev/null' >> $(BUILD_DIR)/.env

api/v1beta2/gitrepository_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type GitRepositorySpec struct {
9797

9898
// GitImplementation specifies which Git client library implementation to
9999
// use. Defaults to 'go-git', valid values are ('go-git', 'libgit2').
100+
// Deprecated: gitImplementation is deprecated now that 'go-git' is the
101+
// only supported implementation.
100102
// +kubebuilder:validation:Enum=go-git;libgit2
101103
// +kubebuilder:default:=go-git
102104
// +optional

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,10 @@ spec:
411411
type: object
412412
gitImplementation:
413413
default: go-git
414-
description: GitImplementation specifies which Git client library
415-
implementation to use. Defaults to 'go-git', valid values are ('go-git',
416-
'libgit2').
414+
description: 'GitImplementation specifies which Git client library
415+
implementation to use. Defaults to ''go-git'', valid values are
416+
(''go-git'', ''libgit2''). Deprecated: gitImplementation is deprecated
417+
now that ''go-git'' is the only supported implementation.'
417418
enum:
418419
- go-git
419420
- libgit2

config/testdata/git/large-repo.yaml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
apiVersion: source.toolkit.fluxcd.io/v1beta1
22
kind: GitRepository
33
metadata:
4-
name: large-repo-go-git
4+
name: large-repo
55
spec:
6-
gitImplementation: go-git
7-
interval: 10m
8-
timeout: 2m
9-
url: https://github.com/hashgraph/hedera-mirror-node.git
10-
ref:
11-
branch: main
12-
ignore: |
13-
/*
14-
!/charts
15-
---
16-
apiVersion: source.toolkit.fluxcd.io/v1beta1
17-
kind: GitRepository
18-
metadata:
19-
name: large-repo-libgit2
20-
spec:
21-
gitImplementation: libgit2
226
interval: 10m
237
timeout: 2m
248
url: https://github.com/hashgraph/hedera-mirror-node.git

0 commit comments

Comments
 (0)