Skip to content

Commit eb167bc

Browse files
authored
Merge pull request #437 from fluxcd/update-libgit2
Update github.com/libgit2/git2go to v31.6.1
2 parents d7afc35 + fa9a2d8 commit eb167bc

File tree

14 files changed

+261
-168
lines changed

14 files changed

+261
-168
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: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
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+
ARG BASE_VARIANT=bullseye
2+
ARG GO_VERSION=1.16.8
3+
ARG XX_VERSION=1.0.0-rc.2
4+
5+
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2
6+
ARG LIBGIT2_TAG=libgit2-1.1.1
7+
8+
FROM tonistiigi/xx:${XX_VERSION} AS xx
9+
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} as libgit2
10+
11+
FROM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
12+
13+
# Copy the build utiltiies
14+
COPY --from=xx / /
15+
COPY --from=libgit2 /Makefile /libgit2/
16+
17+
# Install the libgit2 build dependencies
18+
RUN make -C /libgit2 cmake
19+
20+
RUN make -C /libgit2 dependencies
21+
22+
# Compile and install libgit2
23+
RUN FLAGS=$(xx-clang --print-cmake-defines) make -C /libgit2 libgit2
1524

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

.github/workflows/e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ jobs:
4444
exit 1
4545
fi
4646
- name: Build container image
47-
run: make docker-build IMG=test/source-controller:latest
47+
run: make docker-build IMG=test/source-controller TAG=latest BUILD_PLATFORMS=linux/amd64 BUILD_ARGS=--load
4848
- name: Load test image
4949
run: kind load docker-image test/source-controller:latest
5050
- name: Deploy controller
51-
run: make dev-deploy IMG=test/source-controller:latest
51+
run: make dev-deploy IMG=test/source-controller TAG=latest
5252
- name: Run smoke tests
5353
run: |
5454
kubectl -n source-system apply -f ./config/samples

.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/

CONTRIBUTING.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,37 @@ meeting](https://docs.google.com/document/d/1l_M0om0qUEN_NNiGgpqJ2tvsF2iioHkaARD
3030

3131
### Installing required dependencies
3232

33-
The dependency [libgit2](https://libgit2.org/) needs to be installed to be able to run
34-
Source Controller or its test-suite locally (not in a container).
33+
The dependency [libgit2](https://libgit2.org/) needs to be installed to be able
34+
to run source-controller or its test-suite locally (not in a container).
3535

36-
**macOS**
37-
```
38-
brew install libgit2
39-
```
36+
In case this dependency is not present on your system (at the expected
37+
version), the first invocation of a `make` target that requires the
38+
dependency will attempt to compile it locally to `hack/libgit2`. For this build
39+
to succeed; CMake, Docker, OpenSSL 1.1 and LibSSH2 must be present on the system.
4040

41-
**Arch Linux**
42-
```
43-
pacman -S libgit2
44-
```
41+
Triggering a manual build of the dependency is possible as well by running
42+
`make libgit2`. To enforce the build, for example if your system dependencies
43+
match but are not linked in a compatible way, append `LIBGIT2_FORCE=1` to the
44+
`make` command.
4545

46-
**Building from source**
46+
#### macOS
4747

48-
1. Ensure [`cmake`](https://cmake.org) is available on your system.
49-
1. Download and unarchive [the right `libgit2` version](https://github.com/libgit2/git2go#which-go-version-to-use)
50-
for our current `git2go` dependency:
48+
```console
49+
$ # Ensure libgit2 dependencies are available
50+
$ brew install cmake [email protected] libssh2 pkg-config
51+
$ LIBGIT2_FORCE=1 make libgit2
52+
```
53+
54+
#### Linux
5155

52-
```console
53-
$ LIBGIT2_VER=1.1.0
54-
$ curl -L https://github.com/libgit2/libgit2/releases/download/v$LIBGIT2_VER/libgit2-$LIBGIT2_VER.tar.gz -o /tmp/libgit2.tar.gz
55-
$ tar -xvf /tmp/libgit2.tar.gz -C /tmp/libgit2-$LIBGIT2_VER
56-
```
57-
1. Build and install the library on your system:
56+
```console
57+
$ # Ensure libgit2 dependencies are available
58+
$ pacman -S cmake openssl libssh2
59+
$ LIBGIT2_FORCE=1 make libgit2
60+
```
5861

59-
```console
60-
$ mkdir /tmp/libgit2-$LIBGIT2_VER/build && cd /tmp/libgit2-$LIBGIT2_VER/build
61-
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr
62-
$ sudo cmake --build . --target install
63-
```
62+
**Note:** Example shown is for Arch Linux, but likewise procedure can be
63+
followed using any other package manager, e.g. `apt`.
6464

6565
### How to run the test suite
6666

Dockerfile

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,97 @@
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_VARIANT=bullseye
2+
ARG GO_VERSION=1.16.8
3+
ARG XX_VERSION=1.0.0-rc.2
4+
5+
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2
6+
ARG LIBGIT2_TAG=libgit2-1.1.1
7+
8+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
9+
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} as libgit2
10+
11+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
12+
FROM --platform=$BUILDPLATFORM golang:1.17rc1-${BASE_VARIANT} AS golatest
13+
14+
FROM gostable AS go-linux
15+
16+
FROM go-${TARGETOS} AS build-base-bullseye
17+
18+
# Copy the build utiltiies
19+
COPY --from=xx / /
20+
COPY --from=libgit2 /Makefile /libgit2/
21+
22+
# Install the libgit2 build dependencies
23+
RUN make -C /libgit2 cmake
24+
25+
ARG TARGETPLATFORM
26+
RUN make -C /libgit2 dependencies
27+
28+
FROM build-base-${BASE_VARIANT} as libgit2-bullseye
2129

30+
# Compile and install libgit2
31+
ARG TARGETPLATFORM
32+
RUN FLAGS=$(xx-clang --print-cmake-defines) make -C /libgit2 libgit2
33+
34+
FROM libgit2-${BASE_VARIANT} as build-bullseye
35+
36+
# Configure workspace
2237
WORKDIR /workspace
2338

24-
# copy api submodule
39+
# Copy api submodule
2540
COPY api/ api/
2641

27-
# copy modules manifests
42+
# Copy modules manifests
2843
COPY go.mod go.mod
2944
COPY go.sum go.sum
3045

31-
# cache modules
46+
# Cache modules
3247
RUN go mod download
3348

34-
# copy source code
49+
# Copy source code
3550
COPY main.go main.go
3651
COPY controllers/ controllers/
3752
COPY pkg/ pkg/
3853
COPY internal/ internal/
3954

40-
# build without specifing the arch
41-
RUN CGO_ENABLED=1 go build -o source-controller main.go
55+
# Build the binary
56+
ENV CGO_ENABLED=1
57+
ARG TARGETPLATFORM
58+
RUN xx-go build -o source-controller -trimpath \
59+
main.go
4260

43-
FROM debian:buster-slim as controller
61+
FROM build-${BASE_VARIANT} as prepare-bullseye
4462

45-
# link repo to the GitHub Container Registry image
46-
LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
63+
# Move libgit2 lib to generic and predictable location
64+
ARG TARGETPLATFORM
65+
RUN mkdir -p /libgit2/lib/ \
66+
&& cp -d /usr/lib/$(xx-info triple)/libgit2.so* /libgit2/lib/
4767

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/*
68+
FROM prepare-${BASE_VARIANT} as build
69+
70+
FROM debian:${BASE_VARIANT}-slim as controller
6271

63-
COPY --from=builder /workspace/source-controller /usr/local/bin/
72+
# Link repo to the GitHub Container Registry image
73+
LABEL org.opencontainers.image.source="https://github.com/fluxcd/source-controller"
6474

75+
# Configure user
6576
RUN groupadd controller && \
6677
useradd --gid controller --shell /bin/sh --create-home controller
6778

79+
# Copy libgit2
80+
COPY --from=build /libgit2/lib/ /usr/local/lib/
81+
RUN ldconfig
82+
83+
# Upgrade packages and install runtime dependencies
84+
RUN echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
85+
&& echo "deb-src http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
86+
&& apt update \
87+
&& apt install --no-install-recommends -y zlib1g/sid libssl1.1/sid libssh2-1/sid \
88+
&& apt install --no-install-recommends -y ca-certificates \
89+
&& apt clean \
90+
&& apt autoremove --purge -y \
91+
&& rm -rf /var/lib/apt/lists/*
92+
93+
# Copy over binary from build
94+
COPY --from=build /workspace/source-controller /usr/local/bin/
95+
6896
USER controller
6997
ENTRYPOINT [ "source-controller" ]

0 commit comments

Comments
 (0)