Skip to content

Commit 58e21f3

Browse files
committed
Update github.com/libgit2/git2go to v31.6.1
This commit updates `github.com/libgit2/git2go` to `v31.6.1` (with `libgit2` `1.1.1`), and changes the container image build process so that it makes use of `ghcr.io/hiddeco/golang-with-libgit2`. This image provides a pre-build dynamic `libgit2` dependency linked against OpenSSL and LibSSH2 (without gcrypt), and a set of cross-compile build tools (see [rationale](https://github.com/hiddeco/golang-with-libgit2#rationale) and [usage](https://github.com/hiddeco/golang-with-libgit2#usage) for more detailed information). The linked set of dependency should solve most known issues around unsupport private key types, but does not resolve the issues with ECDSA* and ED25519 hostkeys yet. Solving this requires a newer version of `libgit2` (`>=1.2.0`), which currently does not seem to work properly with `git2go/v32`. Signed-off-by: Hidde Beydals <[email protected]>
1 parent 370f98e commit 58e21f3

File tree

9 files changed

+66
-62
lines changed

9 files changed

+66
-62
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hack/libgit2/
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
FROM golang:1.16-buster as builder
2-
3-
# Up-to-date libgit2 dependencies are only available in sid (unstable).
4-
RUN echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list \
5-
&& echo "deb-src http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list
6-
RUN set -eux; \
7-
apt-get update \
8-
&& apt-get install -y libgit2-dev/unstable zlib1g-dev/unstable libssh2-1-dev/unstable libpcre3-dev/unstable \
9-
&& apt-get clean \
10-
&& apt-get autoremove --purge -y \
11-
&& rm -rf /var/lib/apt/lists/*
1+
FROM ghcr.io/hiddeco/golang-with-libgit2:dev as build
122

3+
# Use the GitHub Actions uid:gid combination for proper fs permissions
134
RUN groupadd -g 116 test && \
145
useradd -u 1001 --gid test --shell /bin/sh --create-home test
156

167
# Run as test user
178
USER test
189

10+
# Set path to envtest binaries.
11+
ENV PATH="/github/workspace/envtest:${PATH}"
12+
1913
ENTRYPOINT ["/bin/sh", "-c"]

.github/workflows/build.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ jobs:
2222
${{ runner.os }}-go-
2323
- name: Set up kubebuilder
2424
uses: fluxcd/pkg/actions/kubebuilder@main
25+
- name: Setup envtest
26+
uses: fluxcd/pkg/actions/envtest@main
27+
with:
28+
version: "1.19.2"
2529
- name: Run tests
2630
uses: ./.github/actions/run-tests
2731
env:
2832
GOPATH: /github/home/go
29-
KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ bin
2727
*.swp
2828
*.swo
2929
*~
30+
31+
# Exclude all libgit2 related files
32+
hack/libgit2/

Dockerfile

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
FROM golang:1.16-buster as builder
2-
3-
# Up-to-date libgit2 dependencies are only available in sid (unstable).
4-
# The libgit2 dependencies must be listed here to be able to build on ARM64.
5-
RUN echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list \
6-
&& echo "deb-src http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list
7-
RUN set -eux; \
8-
apt-get update \
9-
&& apt-get install -y libgit2-dev/unstable zlib1g-dev/unstable libssh2-1-dev/unstable libpcre3-dev/unstable \
10-
&& apt-get clean \
11-
&& apt-get autoremove --purge -y \
12-
&& 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
134

5+
# Configure workspace
146
WORKDIR /workspace
157

16-
# Copy the Go Modules manifests
17-
COPY go.mod go.mod
18-
COPY go.sum go.sum
19-
208
# This has its own go.mod, which needs to be present so go mod
219
# download works.
2210
COPY api/ api/
2311

12+
# Copy modules manifests
13+
COPY go.mod go.mod
14+
COPY go.sum go.sum
15+
2416
# cache deps before building and copying source so that we don't need to re-download as much
2517
# and so that source changes don't invalidate our downloaded layer
2618
RUN go mod download
@@ -30,30 +22,34 @@ COPY main.go main.go
3022
COPY pkg/ pkg/
3123
COPY controllers/ controllers/
3224

33-
# Build
34-
RUN CGO_ENABLED=1 go build -o image-automation-controller main.go
25+
# Build the binary
26+
ENV CGO_ENABLED=1
27+
ARG TARGETPLATFORM
28+
RUN xx-go build -o image-automation-controller -trimpath \
29+
main.go
3530

36-
FROM debian:buster-slim as controller
31+
FROM debian:bullseye-slim as controller
3732

38-
LABEL org.opencontainers.image.source="https://github.com/fluxcd/image-automation-controller"
33+
# Configure user
34+
RUN groupadd controller && \
35+
useradd --gid controller --shell /bin/sh --create-home controller
3936

40-
# Up-to-date libgit2 dependencies are only available in
41-
# unstable, as libssh2 in testing/bullseye has been linked
42-
# against gcrypt which causes issues with PKCS* formats.
43-
RUN echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list \
44-
&& echo "deb-src http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list
45-
RUN set -eux; \
46-
apt-get update \
47-
&& apt-get install -y ca-certificates libgit2-1.1 \
48-
&& apt-get clean \
49-
&& apt-get autoremove --purge -y \
37+
# Copy libgit2
38+
COPY --from=build /libgit2/lib/ /usr/local/lib/
39+
RUN ldconfig
40+
41+
# Upgrade packages and install runtime dependencies
42+
RUN echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
43+
&& echo "deb-src http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
44+
&& apt update \
45+
&& apt install --no-install-recommends -y zlib1g/sid libssl1.1/sid libssh2-1/sid \
46+
&& apt install --no-install-recommends -y ca-certificates \
47+
&& apt clean \
48+
&& apt autoremove --purge -y \
5049
&& rm -rf /var/lib/apt/lists/*
5150

52-
COPY --from=builder /workspace/image-automation-controller /usr/local/bin/
53-
54-
RUN groupadd controller && \
55-
useradd --gid controller --shell /bin/sh --create-home controller
51+
# Copy over binary from build
52+
COPY --from=build /workspace/image-automation-controller /usr/local/bin/
5653

5754
USER controller
58-
5955
ENTRYPOINT [ "image-automation-controller" ]

Makefile

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= fluxcd/image-automation-controller:latest
2+
IMG ?= fluxcd/image-automation-controller
3+
# Image tag to use all building/push image targets
4+
TAG ?= latest
5+
36
# Produce CRDs that work back to Kubernetes 1.16
47
CRD_OPTIONS ?= crd:crdVersions=v1
58

@@ -92,12 +95,12 @@ uninstall: manifests ## Uninstall CRDs from a cluster
9295
kustomize build config/crd | kubectl delete -f -
9396

9497
deploy: manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
95-
cd config/manager && kustomize edit set image fluxcd/image-automation-controller=${IMG}
98+
cd config/manager && kustomize edit set image fluxcd/image-automation-controller=$(IMG):$(TAG)
9699
kustomize build config/default | kubectl apply -f -
97100

98101
dev-deploy: manifests
99102
mkdir -p config/dev && cp config/default/* config/dev
100-
cd config/dev && kustomize edit set image fluxcd/image-automation-controller=${IMG}
103+
cd config/dev && kustomize edit set image fluxcd/image-automation-controller=$(IMG):$(TAG)
101104
kustomize build config/dev | kubectl apply -f -
102105
rm -rf config/dev
103106

@@ -123,14 +126,17 @@ vet: $(LIBGIT2) ## Run go vet against code
123126
generate: controller-gen ## Generate code
124127
cd api; $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..."
125128

126-
docker-build: test ## Build the Docker image
127-
docker build . -t ${IMG}
129+
docker-build: ## Build the Docker image
130+
docker build \
131+
--build-arg BASE_IMG=$(BASE_IMG) \
132+
--build-arg BASE_TAG=$(BASE_TAG) \
133+
-t $(IMG):$(TAG) .
128134

129135
docker-push: ## Push the Docker image
130-
docker push ${IMG}
136+
docker push $(IMG):$(TAG)
131137

132138
docker-deploy: ## Set the Docker image in-cluster
133-
kubectl -n flux-system set image deployment/image-automation-controller manager=${IMG}
139+
kubectl -n flux-system set image deployment/image-automation-controller manager=$(IMG):$(TAG)
134140

135141
controller-gen: ## Find or download controller-gen
136142
ifeq (, $(shell which controller-gen))
@@ -171,7 +177,7 @@ else
171177
set -e; \
172178
mkdir -p $(LIBGIT2_PATH); \
173179
docker cp $(shell docker create --rm $(BASE_IMG):$(BASE_TAG)):/libgit2/Makefile $(LIBGIT2_PATH); \
174-
INSTALL_PREFIX=$(LIBGIT2_PATH) LIGBIT2_VERSION=$(LIBGIT2_VER) LIBGIT2_REVISION= make -C $(LIBGIT2_PATH); \
180+
INSTALL_PREFIX=$(LIBGIT2_PATH) LIGBIT2_VERSION=$(LIBGIT2_VER) make -C $(LIBGIT2_PATH); \
175181
}
176182
endif
177183

controllers/imageupdateautomation_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func push(ctx context.Context, path, branch string, access repoAccess) error {
675675
if status != "" {
676676
callbackErr = fmt.Errorf("ref %s rejected: %s", refname, status)
677677
}
678-
return libgit2.ErrOk
678+
return libgit2.ErrorCodeOK
679679
}
680680
err = origin.Push([]string{fmt.Sprintf("refs/heads/%s:refs/heads/%s", branch, branch)}, &libgit2.PushOptions{
681681
RemoteCallbacks: callbacks,

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ require (
1515
github.com/fluxcd/pkg/runtime v0.12.1
1616
github.com/fluxcd/pkg/ssh v0.1.0
1717
// If you bump this, change SOURCE_VER in the Makefile to match
18-
github.com/fluxcd/source-controller v0.15.4
18+
// TODO(hidde): set to tagged version of release.
19+
github.com/fluxcd/source-controller v0.15.5-0.20210930103634-ac1b95090415
1920
github.com/fluxcd/source-controller/api v0.15.4
2021
github.com/go-git/go-billy/v5 v5.3.1
2122
github.com/go-git/go-git/v5 v5.4.2
2223
github.com/go-logr/logr v0.4.0
2324
github.com/google/go-containerregistry v0.6.0
24-
github.com/libgit2/git2go/v31 v31.4.14
25+
github.com/libgit2/git2go/v31 v31.6.1
2526
github.com/onsi/ginkgo v1.16.4
2627
github.com/onsi/gomega v1.14.0
2728
github.com/otiai10/copy v1.2.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ github.com/fluxcd/pkg/testserver v0.1.0/go.mod h1:fvt8BHhXw6c1+CLw1QFZxcQprlcXzs
358358
github.com/fluxcd/pkg/untar v0.1.0/go.mod h1:aGswNyzB1mlz/T/kpOS58mITBMxMKc9tlJBH037A2HY=
359359
github.com/fluxcd/pkg/version v0.1.0 h1:v+SmCanmCB5Tj2Cx9TXlj+kNRfPGbAvirkeqsp7ZEAQ=
360360
github.com/fluxcd/pkg/version v0.1.0/go.mod h1:V7Z/w8dxLQzv0FHqa5ox5TeyOd2zOd49EeuWFgnwyj4=
361-
github.com/fluxcd/source-controller v0.15.4 h1:FtFkrja75qGRK05CoYf9extdQO5Z3Ts4QloBSiWaHhE=
362-
github.com/fluxcd/source-controller v0.15.4/go.mod h1:yv3qPWT6aNYWYXdmjTjcZmUTfgoC/c7yovcnApnGKYE=
361+
github.com/fluxcd/source-controller v0.15.5-0.20210930103634-ac1b95090415 h1:XrTvVFkWdFQX6GbosGNVtfreqAVqjBtFVk2cqy0uBYk=
362+
github.com/fluxcd/source-controller v0.15.5-0.20210930103634-ac1b95090415/go.mod h1:XPuJVVTs4eYwDWbZjaZY6JLiaNMPti+sl6LpCewEcvc=
363363
github.com/fluxcd/source-controller/api v0.15.4 h1:9aRcH/WKJWt7Bp954K/wzLRuiRiHuD2osvYp74GoP64=
364364
github.com/fluxcd/source-controller/api v0.15.4/go.mod h1:guUCCapjzE2kocwFreQTM/IGvtAglIJc4L97mokairo=
365365
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
@@ -683,8 +683,8 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtB
683683
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
684684
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
685685
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
686-
github.com/libgit2/git2go/v31 v31.4.14 h1:6GOd3965D9e/+gjxCwZF4eQ+vB9kKB4yKFqdQr6XZ2E=
687-
github.com/libgit2/git2go/v31 v31.4.14/go.mod h1:c/rkJcBcUFx6wHaT++UwNpKvIsmPNqCeQ/vzO4DrEec=
686+
github.com/libgit2/git2go/v31 v31.6.1 h1:FnKHHDDBgltSsu9RpKuL4rSR8dQ1JTf9dfvFhZ1y7Aw=
687+
github.com/libgit2/git2go/v31 v31.6.1/go.mod h1:c/rkJcBcUFx6wHaT++UwNpKvIsmPNqCeQ/vzO4DrEec=
688688
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
689689
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
690690
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=

0 commit comments

Comments
 (0)