Skip to content

Commit c1a094d

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 <hello@hidde.co>
1 parent d7afc35 commit c1a094d

File tree

17 files changed

+266
-125
lines changed

17 files changed

+266
-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 cd libgit2 \
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: 108 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ 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+
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
810

911
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1012
ifeq (,$(shell go env GOBIN))
@@ -13,121 +15,168 @@ else
1315
GOBIN=$(shell go env GOBIN)
1416
endif
1517

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

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
21+
LIBGIT2_SHARED_DIR := $(LIBGIT2_DIR)/shared
22+
LIBGIT2_SHARED_LIB := $(LIBGIT2_SHARED_DIR)/install/lib
23+
LIBGIT2_SHARED_BUILD := $(LIBGIT2_SHARED_LIB)/libgit2.so
24+
LIBGIT2_SHARED_PKG_CONFIG := $(LIBGIT2_SHARED_LIB)/pkgconfig
25+
26+
LIBGIT2_STATIC_DIR := $(LIBGIT2_DIR)/static
27+
LIBGIT2_STATIC_LIB := $(LIBGIT2_STATIC_DIR)/install/lib
28+
LIBGIT2_STATIC_BUILD := $(LIBGIT2_STATIC_LIB)/libgit2.a
29+
LIBGIT2_STATIC_PKG_CONFIG := $(LIBGIT2_STATIC_LIB)/pkgconfig
30+
31+
all: build
2232

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

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

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

35-
# Uninstall CRDs from a cluster
36-
uninstall: manifests
69+
uninstall: manifests ## Uninstall CRDs from a cluster
3770
kustomize build config/crd | kubectl delete -f -
3871

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

44-
# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
45-
dev-deploy:
76+
dev-deploy: ## Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
4677
mkdir -p config/dev && cp config/default/* config/dev
4778
cd config/dev && kustomize edit set image fluxcd/source-controller=${IMG}
4879
kustomize build config/dev | kubectl apply -f -
4980
rm -rf config/dev
5081

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

56-
# Generate API reference documentation
57-
api-docs: gen-crd-api-reference-docs
86+
api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
5887
$(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
5988

60-
# Run go mod tidy
61-
tidy:
89+
tidy: ## Run go mod tidy
6290
go mod tidy
6391
cd api; go mod tidy
6492

65-
# Run go fmt against code
66-
fmt:
93+
fmt: ## Run go fmt against code
6794
go fmt ./...
6895
cd api; go fmt ./...
6996

70-
# Run go vet against code
71-
vet:
97+
vet: ## Run go vet against code
7298
go vet ./...
7399
cd api; go vet ./...
74100

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

79-
# Build the docker image
80-
docker-build:
104+
docker-build: ## Build the docker image
81105
docker build . -t ${IMG}
82106

83-
# Push the docker image
84-
docker-push:
107+
docker-push: ## Push docker image
85108
docker push ${IMG}
86109

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

103-
# Find or download gen-crd-api-reference-docs
104-
gen-crd-api-reference-docs:
150+
gen-crd-api-reference-docs: ## Find or download gen-crd-api-reference-docs
105151
ifeq (, $(shell which gen-crd-api-reference-docs))
106152
@{ \
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 ;\
153+
set -e; \
154+
API_REF_GEN_TMP_DIR=$$(mktemp -d); \
155+
cd $$API_REF_GEN_TMP_DIR; \
156+
go mod init tmp; \
157+
go get github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_API_REF_DOCS_VERSION); \
158+
rm -rf $$API_REF_GEN_TMP_DIR; \
113159
}
114160
API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs
115161
else
116162
API_REF_GEN=$(shell which gen-crd-api-reference-docs)
117163
endif
118164

119-
# Find or download setup-envtest
120-
setup-envtest:
165+
setup-envtest: ## Find or download setup-envtest
121166
ifeq (, $(shell which setup-envtest))
122167
@{ \
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 ;\
168+
set -e; \
169+
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d); \
170+
cd $$SETUP_ENVTEST_TMP_DIR; \
171+
go mod init tmp; \
172+
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest; \
173+
rm -rf $$SETUP_ENVTEST_TMP_DIR; \
129174
}
130175
SETUP_ENVTEST=$(GOBIN)/setup-envtest
131176
else
132177
SETUP_ENVTEST=$(shell which setup-envtest)
133178
endif
179+
180+
.PHONY: help
181+
help: ## Display this help menu.
182+
@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)