Skip to content

Commit 045a648

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 045a648

File tree

15 files changed

+163
-150
lines changed

15 files changed

+163
-150
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hack/libgit2/

.github/actions/run-tests/Dockerfile

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
FROM golang:1.16-buster as builder
2-
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
9-
RUN set -eux; \
10-
apt-get update \
11-
&& apt-get install -y libgit2-dev/unstable \
12-
&& apt-get clean \
13-
&& apt-get autoremove --purge -y \
14-
&& rm -rf /var/lib/apt/lists/*
1+
FROM ghcr.io/hiddeco/golang-with-libgit2:dev as builder
152

163
# Use the GitHub Actions uid:gid combination for proper fs permissions
174
RUN groupadd -g 116 test && \

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@
1515
# vendor/
1616
bin/
1717
config/release/
18+
19+
# Exclude all libgit2 related files
20+
hack/libgit2/

Dockerfile

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,57 @@
1-
FROM golang:1.16-buster as builder
2-
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
11-
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 \
18-
&& apt-get clean \
19-
&& apt-get autoremove --purge -y \
20-
&& rm -rf /var/lib/apt/lists/*
1+
ARG BASE_IMG=ghcr.io/hiddeco/golang-with-libgit2
2+
ARG BASE_TAG=dev
3+
FROM ${BASE_IMG}:${BASE_TAG} AS build
214

5+
# Configure workspace
226
WORKDIR /workspace
237

24-
# copy api submodule
8+
# Copy api submodule
259
COPY api/ api/
2610

27-
# copy modules manifests
11+
# Copy modules manifests
2812
COPY go.mod go.mod
2913
COPY go.sum go.sum
3014

31-
# cache modules
15+
# Cache modules
3216
RUN go mod download
3317

34-
# copy source code
18+
# Copy source code
3519
COPY main.go main.go
3620
COPY controllers/ controllers/
3721
COPY pkg/ pkg/
3822
COPY internal/ internal/
3923

40-
# build without specifing the arch
41-
RUN CGO_ENABLED=1 go build -o source-controller main.go
24+
# Build the binary
25+
ENV CGO_ENABLED=1
26+
ARG TARGETPLATFORM
27+
RUN xx-go build -o source-controller -trimpath \
28+
main.go
4229

4330
FROM debian:buster-slim as controller
4431

45-
# link repo to the GitHub Container Registry image
32+
# Link repo to the GitHub Container Registry image
4633
LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
4734

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
54-
RUN set -eux; \
55-
apt-get update \
56-
&& apt-get install -y \
57-
ca-certificates \
58-
libgit2-1.1 \
59-
&& apt-get clean \
60-
&& apt-get autoremove --purge -y \
61-
&& rm -rf /var/lib/apt/lists/*
62-
63-
COPY --from=builder /workspace/source-controller /usr/local/bin/
64-
35+
# Configure user
6536
RUN groupadd controller && \
6637
useradd --gid controller --shell /bin/sh --create-home controller
6738

39+
# Copy libgit2
40+
COPY --from=build /libgit2/lib/* /usr/local/lib/
41+
RUN ldconfig
42+
43+
# Upgrade packages and install runtime dependencies
44+
RUN echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
45+
&& echo "deb-src http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
46+
&& apt update \
47+
&& apt install --no-install-recommends -y zlib1g/sid libssl1.1/sid libssh2-1/sid \
48+
&& apt install --no-install-recommends -y ca-certificates \
49+
&& apt clean \
50+
&& apt autoremove --purge -y \
51+
&& rm -rf /var/lib/apt/lists/*
52+
53+
# Copy over binary from build
54+
COPY --from=build /workspace/source-controller /usr/local/bin/
55+
6856
USER controller
6957
ENTRYPOINT [ "source-controller" ]

Makefile

Lines changed: 92 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
# Image URL to use all building/pushing image targets
22
IMG ?= fluxcd/source-controller:latest
3+
4+
# Base image used to build the Go binary
5+
BASE_IMG ?= ghcr.io/hiddeco/golang-with-libgit2
6+
BASE_TAG ?= dev
7+
38
# Produce CRDs that work back to Kubernetes 1.16
49
CRD_OPTIONS ?= crd:crdVersions=v1
510

6-
ENVTEST_BIN_VERSION?=1.19.2
7-
KUBEBUILDER_ASSETS?=$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
11+
# Repository root based on Git metadata
12+
REPOSITORY_ROOT := $(shell git rev-parse --show-toplevel)
13+
14+
# Dependency versions
15+
LIBGIT2_VERSION ?= 1.2.0
16+
ENVTEST_BIN_VERSION ?= 1.19.2
17+
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
18+
19+
# libgit2 related magical paths
20+
# These are used to determine if the target libgit2 version is already available on
21+
# the system, or where they should be installed to
22+
SYSTEM_LIBGIT2_VERSION := $(shell pkg-config --modversion libgit2 2>/dev/null)
23+
LIBGIT2_PATH := $(REPOSITORY_ROOT)/hack/libgit2
24+
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib
25+
LIBGIT2 := $(LIBGIT2_LIB_PATH)/libgit2.so.$(LIBGIT2_VERSION)
26+
27+
# API (doc) generation utilities
28+
CONTROLLER_GEN_VERSION ?= v0.5.0
29+
GEN_API_REF_DOCS_VERSION ?= 0.3.0
830

931
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1032
ifeq (,$(shell go env GOBIN))
@@ -13,121 +35,130 @@ else
1335
GOBIN=$(shell go env GOBIN)
1436
endif
1537

16-
all: manager
38+
all: build
1739

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-
23-
# Build manager binary
24-
manager: generate fmt vet
40+
build: $(LIBGIT2) ## Build manager binary
41+
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \
2542
go build -o bin/manager main.go
2643

27-
# Run against the configured Kubernetes cluster in ~/.kube/config
28-
run: generate fmt vet manifests
44+
test: $(LIBGIT2) test-api ## Run tests
45+
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
46+
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig/ \
47+
go test ./... -coverprofile cover.out
48+
49+
test-api: ## Run api tests
50+
cd api; go test ./... -coverprofile cover.out
51+
52+
run: $(LIBGIT2) generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
53+
LD_LIBRARY_PATH=$(LIBGIT2_LIB_PATH) \
2954
go run ./main.go
3055

31-
# Install CRDs into a cluster
32-
install: manifests
56+
install: manifests ## Install CRDs into a cluster
3357
kustomize build config/crd | kubectl apply -f -
3458

35-
# Uninstall CRDs from a cluster
36-
uninstall: manifests
59+
uninstall: manifests ## Uninstall CRDs from a cluster
3760
kustomize build config/crd | kubectl delete -f -
3861

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

44-
# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
45-
dev-deploy:
66+
dev-deploy: ## Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
4667
mkdir -p config/dev && cp config/default/* config/dev
4768
cd config/dev && kustomize edit set image fluxcd/source-controller=${IMG}
4869
kustomize build config/dev | kubectl apply -f -
4970
rm -rf config/dev
5071

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

56-
# Generate API reference documentation
57-
api-docs: gen-crd-api-reference-docs
76+
api-docs: gen-crd-api-reference-docs ## Generate API reference documentation
5877
$(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
5978

60-
# Run go mod tidy
61-
tidy:
79+
tidy: ## Run go mod tidy
6280
go mod tidy
6381
cd api; go mod tidy
6482

65-
# Run go fmt against code
66-
fmt:
83+
fmt: ## Run go fmt against code
6784
go fmt ./...
6885
cd api; go fmt ./...
6986

70-
# Run go vet against code
71-
vet:
87+
vet: ## Run go vet against code
88+
PKG_CONFIG_PATH=$(LIBGIT2_LIB_PATH)/pkgconfig \
7289
go vet ./...
7390
cd api; go vet ./...
7491

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

79-
# Build the docker image
80-
docker-build:
81-
docker build . -t ${IMG}
95+
docker-build: ## Build the docker image
96+
docker build \
97+
--build-arg BASE_IMG=$(BASE_IMG) \
98+
--build-arg BASE_TAG=$(BASE_TAG) \
99+
-t ${IMG} .
82100

83-
# Push the docker image
84-
docker-push:
101+
docker-push: ## Push docker image
85102
docker push ${IMG}
86103

87-
# Find or download controller-gen
88-
controller-gen:
104+
controller-gen: ## Find or download controller-gen
89105
ifeq (, $(shell which controller-gen))
90106
@{ \
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 ;\
107+
set -e; \
108+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d); \
109+
cd $$CONTROLLER_GEN_TMP_DIR; \
110+
go mod init tmp; \
111+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION); \
112+
rm -rf $$CONTROLLER_GEN_TMP_DIR; \
97113
}
98114
CONTROLLER_GEN=$(GOBIN)/controller-gen
99115
else
100116
CONTROLLER_GEN=$(shell which controller-gen)
101117
endif
102118

103-
# Find or download gen-crd-api-reference-docs
104-
gen-crd-api-reference-docs:
119+
gen-crd-api-reference-docs: ## Find or download gen-crd-api-reference-docs
105120
ifeq (, $(shell which gen-crd-api-reference-docs))
106121
@{ \
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 ;\
122+
set -e; \
123+
API_REF_GEN_TMP_DIR=$$(mktemp -d); \
124+
cd $$API_REF_GEN_TMP_DIR; \
125+
go mod init tmp; \
126+
go get github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_API_REF_DOCS_VERSION); \
127+
rm -rf $$API_REF_GEN_TMP_DIR; \
113128
}
114129
API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs
115130
else
116131
API_REF_GEN=$(shell which gen-crd-api-reference-docs)
117132
endif
118133

119-
# Find or download setup-envtest
120-
setup-envtest:
134+
setup-envtest: ## Find or download setup-envtest
121135
ifeq (, $(shell which setup-envtest))
122136
@{ \
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 ;\
137+
set -e; \
138+
SETUP_ENVTEST_TMP_DIR=$$(mktemp -d); \
139+
cd $$SETUP_ENVTEST_TMP_DIR; \
140+
go mod init tmp; \
141+
go get sigs.k8s.io/controller-runtime/tools/setup-envtest@latest; \
142+
rm -rf $$SETUP_ENVTEST_TMP_DIR; \
129143
}
130144
SETUP_ENVTEST=$(GOBIN)/setup-envtest
131145
else
132146
SETUP_ENVTEST=$(shell which setup-envtest)
133147
endif
148+
149+
libgit2: $(LIBGIT2) ## Detect or download libgit2 library
150+
151+
$(LIBGIT2):
152+
ifeq ($(LIBGIT2_VERSION),$(SYSTEM_LIBGIT2_VERSION))
153+
else
154+
@{ \
155+
set -e; \
156+
mkdir -p $(LIBGIT2_PATH); \
157+
docker cp $(shell docker create --rm $(BASE_IMG):$(BASE_TAG)):/libgit2/Makefile $(LIBGIT2_PATH); \
158+
INSTALL_PREFIX=$(LIBGIT2_PATH) make -C $(LIBGIT2_PATH); \
159+
}
160+
endif
161+
162+
.PHONY: help
163+
help: ## Display this help menu
164+
@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=

internal/fs/rename.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !windows
56
// +build !windows
67

78
package fs

internal/fs/rename_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build windows
56
// +build windows
67

78
package fs

pkg/git/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/go-git/go-git/v5/plumbing/transport"
23-
git2go "github.com/libgit2/git2go/v31"
23+
git2go "github.com/libgit2/git2go/v32"
2424
corev1 "k8s.io/api/core/v1"
2525
)
2626

0 commit comments

Comments
 (0)