Skip to content

Commit 8fbc69a

Browse files
committed
Update github.com/libgit2/git2go to v32
This includes changes to the `libgit2` package to address deprecations and other small signature changes. Signed-off-by: Hidde Beydals <[email protected]>
1 parent d7afc35 commit 8fbc69a

File tree

17 files changed

+267
-125
lines changed

17 files changed

+267
-125
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Excluding the libgit2 directory contents has two goals:
2+
# 1. The compiled dependencies should never be copied over to
3+
# an image, but rather be build within to ensure it is build
4+
# for the right environment, architecture, and set of
5+
# dependencies
6+
# 2. It speeds up the "pre-build" step of the image by a lot,
7+
# as the dependency files are not included in the build
8+
# context
9+
hack/libgit2/**
10+
!hack/libgit2/CMakeLists.txt

.github/actions/run-tests/Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
FROM golang:1.16-buster as builder
22

3-
# Up-to-date libgit2 dependencies are only available in
4-
# unstable, as libssh2 in testing/bullseye has been linked
5-
# against gcrypt which causes issues with PKCS* formats.
6-
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
7-
RUN echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list \
8-
&& echo "deb-src http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list
3+
# Build dependencies
94
RUN set -eux; \
10-
apt-get update \
11-
&& apt-get install -y libgit2-dev/unstable \
5+
apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
cmake \
8+
curl \
9+
python3 \
1210
&& apt-get clean \
1311
&& apt-get autoremove --purge -y \
1412
&& rm -rf /var/lib/apt/lists/*

.github/workflows/e2e.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@ jobs:
115115
kubectl -n source-system get helmcharts -oyaml
116116
kubectl -n source-system get all
117117
kubectl -n source-system logs deploy/source-controller
118+
kubectl -n source-system logs -p deploy/source-controller
118119
kubectl -n minio get all

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
# vendor/
1616
bin/
1717
config/release/
18+
19+
# Exclude all libgit2 related files, except for the CMakeLists instructions
20+
hack/libgit2/**
21+
!hack/libgit2/CMakeLists.txt

Dockerfile

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
FROM golang:1.16-buster as builder
22

3-
# Up-to-date libgit2 dependencies are only available in
4-
# unstable, as libssh2 in testing/bullseye has been linked
5-
# against gcrypt which causes issues with PKCS* formats.
6-
# Explicitly listing all build dependencies is required because
7-
# they can only be automagically found for AMD64 builds.
8-
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
9-
RUN echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list \
10-
&& echo "deb-src http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list
3+
# Install depedencies required to built libgit2
114
RUN set -eux; \
12-
apt-get update \
13-
&& apt-get install -y \
14-
libgit2-dev/unstable \
15-
zlib1g-dev/unstable \
16-
libssh2-1-dev/unstable \
17-
libpcre3-dev/unstable \
5+
apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
cmake \
8+
curl \
9+
python3 \
1810
&& apt-get clean \
1911
&& apt-get autoremove --purge -y \
2012
&& rm -rf /var/lib/apt/lists/*
2113

14+
# Configure workspace
2215
WORKDIR /workspace
2316

24-
# copy api submodule
17+
# Static build libgit2 and other dependencies
18+
COPY hack/libgit2/CMakeLists.txt libgit2/
19+
RUN mkdir -p \
20+
&& cmake -DBUILD_SHARED_LIBS:BOOL=OFF . \
21+
&& cmake --build .
22+
23+
# Copy api submodule
2524
COPY api/ api/
2625

27-
# copy modules manifests
26+
# Copy modules manifests
2827
COPY go.mod go.mod
2928
COPY go.sum go.sum
3029

31-
# cache modules
30+
# Cache modules
3231
RUN go mod download
3332

34-
# copy source code
33+
# Copy source code
3534
COPY main.go main.go
3635
COPY controllers/ controllers/
3736
COPY pkg/ pkg/
3837
COPY internal/ internal/
3938

40-
# build without specifing the arch
41-
RUN CGO_ENABLED=1 go build -o source-controller main.go
39+
# Build a binary with all C dependencies statically linked.
40+
# PKG_CONFIG_PATH is set to the result of our own C libary builds
41+
# to overwrite the git2go defaults that assume a submodule with a
42+
# specific path.
43+
RUN PKG_CONFIG_PATH="$PWD/libgit2/install/lib/pkgconfig" \
44+
LD_LIBRARY_PATH="$PWD/libgit2/install/lib" \
45+
go build -o source-controller \
46+
-tags static,system_libgit2 \
47+
main.go
4248

4349
FROM debian:buster-slim as controller
4450

4551
# link repo to the GitHub Container Registry image
4652
LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
4753

48-
# Up-to-date libgit2 dependencies are only available in
49-
# unstable, as libssh2 in testing/bullseye has been linked
50-
# against gcrypt which causes issues with PKCS* formats.
51-
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
52-
RUN echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list \
53-
&& echo "deb-src http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list
5454
RUN set -eux; \
5555
apt-get update \
5656
&& apt-get install -y \
5757
ca-certificates \
58-
libgit2-1.1 \
58+
libc6 \
5959
&& apt-get clean \
6060
&& apt-get autoremove --purge -y \
6161
&& rm -rf /var/lib/apt/lists/*

Makefile

Lines changed: 109 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ IMG ?= fluxcd/source-controller:latest
33
# Produce CRDs that work back to Kubernetes 1.16
44
CRD_OPTIONS ?= crd:crdVersions=v1
55

6-
ENVTEST_BIN_VERSION?=1.19.2
7-
KUBEBUILDER_ASSETS?=$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
6+
CONTROLLER_GEN_VERSION ?= v0.5.0
7+
GEN_API_REF_DOCS_VERSION ?= 0.3.0
8+
ENVTEST_BIN_VERSION ?= 1.19.2
9+
10+
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
811

912
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1013
ifeq (,$(shell go env GOBIN))
@@ -13,121 +16,168 @@ else
1316
GOBIN=$(shell go env GOBIN)
1417
endif
1518

16-
all: manager
19+
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
20+
LIBGIT2_DIR := hack/libgit2
1721

18-
# Run tests
19-
test: generate fmt vet manifests api-docs setup-envtest
20-
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out
21-
cd api; go test ./... -coverprofile cover.out
22+
LIBGIT2_SHARED_DIR := $(LIBGIT2_DIR)/shared
23+
LIBGIT2_SHARED_LIB := $(LIBGIT2_SHARED_DIR)/install/lib
24+
LIBGIT2_SHARED_BUILD := $(LIBGIT2_SHARED_LIB)/libgit2.so
25+
LIBGIT2_SHARED_PKG_CONFIG := $(LIBGIT2_SHARED_LIB)/pkgconfig
26+
27+
LIBGIT2_STATIC_DIR := $(LIBGIT2_DIR)/static
28+
LIBGIT2_STATIC_LIB := $(LIBGIT2_STATIC_DIR)/install/lib
29+
LIBGIT2_STATIC_BUILD := $(LIBGIT2_STATIC_LIB)/libgit2.a
30+
LIBGIT2_STATIC_PKG_CONFIG := $(LIBGIT2_STATIC_LIB)/pkgconfig
2231

23-
# Build manager binary
24-
manager: generate fmt vet
32+
all: build
33+
34+
build: $(LIBGIT2_SHARED_BUILD) generate fmt vet ## Build manager binary
35+
PKG_CONFIG_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_SHARED_PKG_CONFIG) \
36+
LD_LIBRARY_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_SHARED_LIB) \
2537
go build -o bin/manager main.go
2638

27-
# Run against the configured Kubernetes cluster in ~/.kube/config
28-
run: generate fmt vet manifests
39+
build-static: $(LIBGIT2_STATIC_BUILD) generate fmt vet ## Build static manager binary
40+
PKG_CONFIG_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_STATIC_PKG_CONFIG) \
41+
LD_LIBRARY_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_STATIC_LIB) \
42+
go build -tags static,system_libgit2 -o bin/manager-static main.go
43+
44+
test: $(LIBGIT2_SHARED_BUILD) test-api ## Run tests
45+
PKG_CONFIG_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_SHARED_PKG_CONFIG) \
46+
LD_LIBRARY_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_SHARED_LIB) \
47+
go test ./... -coverprofile cover.out
48+
49+
test-static: $(LIBGIT2_STATIC_BUILD) test-api ## Run static tests
50+
PKG_CONFIG_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_STATIC_PKG_CONFIG) \
51+
LD_LIBRARY_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_STATIC_LIB) \
52+
go test -tags static,system_libgit2 ./... -coverprofile cover.out
53+
54+
test-api: ## Run api tests
55+
cd api; go test ./... -coverprofile cover.out
56+
57+
run: $(LIBGIT2_SHARED_BUILD) generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
58+
PKG_CONFIG_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_SHARED_PKG_CONFIG) \
59+
LD_LIBRARY_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_SHARED_LIB) \
2960
go run ./main.go
3061

31-
# Install CRDs into a cluster
32-
install: manifests
62+
run-static: $(LIBGIT2_STATIC_BUILD) generate fmt vet manifests ## Static run against the configured Kubernetes cluster in ~/.kube/config
63+
PKG_CONFIG_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_STATIC_PKG_CONFIG) \
64+
LD_LIBRARY_PATH=$(REPOSITORY_ROOT)/$(LIBGIT2_STATIC_LIB) \
65+
go run ./main.go
66+
67+
install: manifests ## Install CRDs into a cluster
3368
kustomize build config/crd | kubectl apply -f -
3469

35-
# Uninstall CRDs from a cluster
36-
uninstall: manifests
70+
uninstall: manifests ## Uninstall CRDs from a cluster
3771
kustomize build config/crd | kubectl delete -f -
3872

39-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
40-
deploy: manifests
73+
deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
4174
cd config/manager && kustomize edit set image fluxcd/source-controller=${IMG}
4275
kustomize build config/default | kubectl apply -f -
4376

44-
# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
45-
dev-deploy:
77+
dev-deploy: ## Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
4678
mkdir -p config/dev && cp config/default/* config/dev
4779
cd config/dev && kustomize edit set image fluxcd/source-controller=${IMG}
4880
kustomize build config/dev | kubectl apply -f -
4981
rm -rf config/dev
5082

51-
# Generate manifests e.g. CRD, RBAC etc.
52-
manifests: controller-gen
83+
manifests: controller-gen ## Generate manifests, e.g. CRD, RBAC, etc.
5384
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths="./..." output:crd:artifacts:config="config/crd/bases"
5485
cd api; $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role paths="./..." output:crd:artifacts:config="../config/crd/bases"
5586

56-
# Generate API reference documentation
57-
api-docs: gen-crd-api-reference-docs
87+
api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
5888
$(API_REF_GEN) -api-dir=./api/v1beta1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api/source.md
5989

60-
# Run go mod tidy
61-
tidy:
90+
tidy: ## Run go mod tidy
6291
go mod tidy
6392
cd api; go mod tidy
6493

65-
# Run go fmt against code
66-
fmt:
94+
fmt: ## Run go fmt against code
6795
go fmt ./...
6896
cd api; go fmt ./...
6997

70-
# Run go vet against code
71-
vet:
98+
vet: ## Run go vet against code
7299
go vet ./...
73100
cd api; go vet ./...
74101

75-
# Generate code
76-
generate: controller-gen
102+
generate: controller-gen ## Generate API code
77103
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..."
78104

79-
# Build the docker image
80-
docker-build:
105+
docker-build: ## Build the docker image
81106
docker build . -t ${IMG}
82107

83-
# Push the docker image
84-
docker-push:
108+
docker-push: ## Push docker image
85109
docker push ${IMG}
86110

87-
# Find or download controller-gen
88-
controller-gen:
111+
$(LIBGIT2_SHARED_BUILD): $(LIBGIT2_SHARED_DIR)
112+
(cd $(LIBGIT2_SHARED_DIR) && cmake -DBUILD_SHARED_LIBS:BOOL=ON .. && cmake --build .)
113+
114+
$(LIBGIT2_STATIC_BUILD): $(LIBGIT2_STATIC_DIR)
115+
(cd $(LIBGIT2_STATIC_DIR) && cmake -DBUILD_SHARED_LIBS:BOOL=OFF .. && cmake --build .)
116+
117+
$(LIBGIT2_SHARED_DIR):
118+
mkdir -p "$@"
119+
120+
$(LIBGIT2_STATIC_DIR):
121+
mkdir -p "$@"
122+
123+
.PHONY: clean
124+
clean: ## Removes dependency builds and clears Go cache
125+
rm -rf $(LIBGIT2_SHARED_DIR)
126+
rm -rf $(LIBGIT2_STATIC_DIR)
127+
128+
# C-binding directives in Go are cached, which means that e.g.
129+
# changes to $PKG_CONFIG_PATH do not have an effect until this cache
130+
# is cleared and the package(s) is forced to be rebuild.
131+
# This can also be done using `go <cmd> -a`, but this would make
132+
# things slow for something that is not expected to change much,
133+
# unless you are specifically dealing with build related changes.
134+
go clean
135+
136+
controller-gen: ## Find or download controller-gen
89137
ifeq (, $(shell which controller-gen))
90138
@{ \
91-
set -e ;\
92-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
93-
cd $$CONTROLLER_GEN_TMP_DIR ;\
94-
go mod init tmp ;\
95-
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0 ;\
96-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
139+
set -e; \
140+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d); \
141+
cd $$CONTROLLER_GEN_TMP_DIR; \
142+
go mod init tmp; \
143+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION); \
144+
rm -rf $$CONTROLLER_GEN_TMP_DIR; \
97145
}
98146
CONTROLLER_GEN=$(GOBIN)/controller-gen
99147
else
100148
CONTROLLER_GEN=$(shell which controller-gen)
101149
endif
102150

103-
# Find or download gen-crd-api-reference-docs
104-
gen-crd-api-reference-docs:
151+
gen-crd-api-reference-docs: ## Find or download gen-crd-api-reference-docs
105152
ifeq (, $(shell which gen-crd-api-reference-docs))
106153
@{ \
107-
set -e ;\
108-
API_REF_GEN_TMP_DIR=$$(mktemp -d) ;\
109-
cd $$API_REF_GEN_TMP_DIR ;\
110-
go mod init tmp ;\
111-
go get github.com/ahmetb/gen-crd-api-reference-docs@v0.3.0 ;\
112-
rm -rf $$API_REF_GEN_TMP_DIR ;\
154+
set -e; \
155+
API_REF_GEN_TMP_DIR=$$(mktemp -d); \
156+
cd $$API_REF_GEN_TMP_DIR; \
157+
go mod init tmp; \
158+
go get github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_API_REF_DOCS_VERSION); \
159+
rm -rf $$API_REF_GEN_TMP_DIR; \
113160
}
114161
API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs
115162
else
116163
API_REF_GEN=$(shell which gen-crd-api-reference-docs)
117164
endif
118165

119-
# Find or download setup-envtest
120-
setup-envtest:
166+
setup-envtest: ## Find or download setup-envtest
121167
ifeq (, $(shell which setup-envtest))
122168
@{ \
123-
set -e ;\
124-
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d) ;\
125-
cd $$SETUP_ENVTEST_TMP_DIR ;\
126-
go mod init tmp ;\
127-
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest ;\
128-
rm -rf $$SETUP_ENVTEST_TMP_DIR ;\
169+
set -e; \
170+
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d); \
171+
cd $$SETUP_ENVTEST_TMP_DIR; \
172+
go mod init tmp; \
173+
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest; \
174+
rm -rf $$SETUP_ENVTEST_TMP_DIR; \
129175
}
130176
SETUP_ENVTEST=$(GOBIN)/setup-envtest
131177
else
132178
SETUP_ENVTEST=$(shell which setup-envtest)
133179
endif
180+
181+
.PHONY: help
182+
help: ## Display this help menu.
183+
@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)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/go-git/go-billy/v5 v5.3.1
2121
github.com/go-git/go-git/v5 v5.4.2
2222
github.com/go-logr/logr v0.4.0
23-
github.com/libgit2/git2go/v31 v31.4.14
23+
github.com/libgit2/git2go/v32 v32.0.4
2424
github.com/minio/minio-go/v7 v7.0.10
2525
github.com/onsi/ginkgo v1.16.4
2626
github.com/onsi/gomega v1.14.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
545545
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
546546
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
547547
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
548-
github.com/libgit2/git2go/v31 v31.4.14 h1:6GOd3965D9e/+gjxCwZF4eQ+vB9kKB4yKFqdQr6XZ2E=
549-
github.com/libgit2/git2go/v31 v31.4.14/go.mod h1:c/rkJcBcUFx6wHaT++UwNpKvIsmPNqCeQ/vzO4DrEec=
548+
github.com/libgit2/git2go/v32 v32.0.4 h1:qK2yWGh88K2Gh76E1+vUEsjKDfOAq0J2THKaoaFIPbA=
549+
github.com/libgit2/git2go/v32 v32.0.4/go.mod h1:FAA2ePV5PlLjw1ccncFIvu2v8hJSZVN5IzEn4lo/vwo=
550550
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
551551
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
552552
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=

0 commit comments

Comments
 (0)