Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 4826f8e

Browse files
committed
Refactor to make use of tonistiigi/xx
Signed-off-by: Hidde Beydals <hello@hidde.co>
1 parent 58c2307 commit 4826f8e

File tree

8 files changed

+250
-256
lines changed

8 files changed

+250
-256
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
**/**
2-
!CMakeLists.txt
2+
!hack/

.github/workflows/build-multi-platform.yaml renamed to .github/workflows/build.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
fail-fast: false
14-
matrix:
15-
platforms:
16-
- linux/amd64
17-
- linux/amd64,linux/arm/v7,linux/arm64
12+
env:
13+
PLATFORMS: linux/amd64,linux/arm/v7,linux/arm64
1814
services:
1915
registry:
2016
image: registry:2
@@ -29,7 +25,7 @@ jobs:
2925
uses: docker/setup-qemu-action@v1
3026
with:
3127
image: tonistiigi/binfmt:latest
32-
platforms: ${{ matrix.platforms }}
28+
platforms: ${{ env.PLATFORMS }}
3329
- name: Set up Docker Buildx
3430
id: buildx
3531
uses: docker/setup-buildx-action@v1
@@ -51,15 +47,13 @@ jobs:
5147
with:
5248
context: .
5349
file: Dockerfile
54-
platforms: ${{ matrix.platforms }}
50+
platforms: ${{ env.PLATFORMS }}
5551
push: true
5652
tags: localhost:5000/golang-with-libgit2:latest
5753
- name: Inspect candidate
5854
run: |
5955
docker buildx imagetools inspect localhost:5000/golang-with-libgit2:latest
6056
- name: Test candidate
57+
id: test_candidate
6158
run: |
62-
for digest in $(docker buildx imagetools inspect localhost:5000/golang-with-libgit2:latest --raw | jq -rc '.manifests[] | .digest')
63-
do
64-
IMG=localhost:5000/golang-with-libgit2 TAG=latest@$digest make test
65-
done
59+
IMG=localhost:5000/golang-with-libgit2 make test

CMakeLists.txt

Lines changed: 0 additions & 158 deletions
This file was deleted.

Dockerfile

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
1-
FROM golang:1.16.8-bullseye as base
2-
3-
# Install depedencies required to build
4-
RUN set -eux; \
5-
apt-get update \
6-
&& apt-get install -y --no-install-recommends \
7-
cmake \
8-
python3 \
9-
&& apt-get clean \
10-
&& apt-get autoremove --purge -y \
11-
&& rm -rf /var/lib/apt/lists/*
12-
13-
# Copy libgit2 build directives and instructions into container
14-
ARG LIBGIT2_SRC_DIR
15-
ENV LIBGIT2_SRC_DIR=${LIBGIT2_SRC_DIR:-/libgit2}
16-
COPY CMakeLists.txt ${LIBGIT2_SRC_DIR}/CMakeLists.txt
17-
18-
# Set right before build time to not invalidate previous cache layers.
19-
ARG LIBGIT2_DYNAMIC_ROOT_DIR
20-
ENV LIBGIT2_DYNAMIC_ROOT_DIR=${LIBGIT2_DYNAMIC_ROOT_DIR:-${LIBGIT2_SRC_DIR}/dynamic}
21-
ARG LIBGIT2_STATIC_ROOT_DIR
22-
ENV LIBGIT2_STATIC_ROOT_DIR=${LIBGIT2_STATIC_ROOT_DIR:-${LIBGIT2_SRC_DIR}/static}
23-
24-
# Set default to single process
25-
ARG NPROC=1
26-
27-
# Run the libgit2 and dependencies build.
28-
# Produce two sets (dynamic and static) of pre-compiled libraries in /libgit2/,
29-
# and remove the build directory itself to minimize image size.
30-
#
31-
# Note: you can still reproduce the build by making use of /libgit2/CMakeLists.txt.
32-
RUN set -eux; \
33-
build_dir=$(mktemp -d) \
34-
&& echo "=> Dynamic build" \
35-
&& cmake -S $LIBGIT2_SRC_DIR -B $build_dir \
36-
-DBUILD_SHARED_LIBS:BOOL=ON \
37-
-DUSE_EXTERNAL_INSTALL:BOOL=ON \
38-
-DCMAKE_INSTALL_PREFIX:PATH=$LIBGIT2_DYNAMIC_ROOT_DIR \
39-
&& cmake --build $build_dir -j $NPROC \
40-
&& echo "=> Static build" \
41-
&& cmake -S $LIBGIT2_SRC_DIR -B $build_dir \
42-
-DBUILD_SHARED_LIBS:BOOL=OFF \
43-
-DUSE_EXTERNAL_INSTALL:BOOL=ON \
44-
-DCMAKE_INSTALL_PREFIX:PATH=$LIBGIT2_STATIC_ROOT_DIR \
45-
&& cmake --build $build_dir -j $NPROC \
46-
&& rm -rf $build_dir
1+
ARG BASE_VARIANT=bullseye
2+
ARG GO_VERSION=1.16.8
3+
ARG XX_VERSION=1.0.0-rc.2
4+
5+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
6+
7+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
8+
FROM --platform=$BUILDPLATFORM golang:1.17rc1-${BASE_VARIANT} AS golatest
9+
10+
FROM gostable AS go-linux
11+
12+
FROM go-${TARGETOS} AS build-base-bullseye
13+
14+
COPY --from=xx / /
15+
16+
RUN apt-get update && apt-get install --no-install-recommends -y clang
17+
ARG CMAKE_VERSION=3.21.3
18+
RUN curl -sL -o cmake-linux.sh "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-$(xx-info march).sh" \
19+
&& sh cmake-linux.sh -- --skip-license --prefix=/usr \
20+
&& rm cmake-linux.sh
21+
22+
FROM build-base-bullseye AS build-bullseye
23+
ARG TARGETPLATFORM
24+
RUN xx-apt install --no-install-recommends -y binutils gcc libc6-dev dpkg-dev
25+
26+
FROM build-${BASE_VARIANT} AS build-dependencies-bullseye
27+
28+
# Install libssh2 for $TARGETPLATFORM from "sid", as the version in "bullseye"
29+
# has been linked against gcrypt, which causes issues with PKCS* formats.
30+
# We pull (sub)dependencies from there as well, to ensure all versions are aligned,
31+
# and not accidentially linked to e.g. mbedTLS (which has limited support for
32+
# certain key formats).
33+
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=668271
34+
# Ref: https://github.com/ARMmbed/mbedtls/issues/2452#issuecomment-802683144
35+
ARG TARGETPLATFORM
36+
RUN echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list \
37+
&& echo "deb-src http://deb.debian.org/debian sid main" >> /etc/apt/sources.list
38+
RUN xx-apt update \
39+
&& xx-apt -t sid install --no-install-recommends -y zlib1g-dev libssl-dev libssh2-1-dev
40+
41+
FROM build-dependencies-${BASE_VARIANT} as build-libgit2-bullseye
42+
43+
# Compile libgit2 as a dynamic build
44+
# We compile it ourselves to ensure they are properly linked with the above packages,
45+
# and to allow room for customizations (or more rapid updates than the OS).
46+
ARG LIBGIT2_PATH=/libgit2
47+
ENV LIBGIT2_PATH=${LIBGIT2_PATH}
48+
COPY hack/Makefile ${LIBGIT2_PATH}/Makefile
49+
RUN set -e; \
50+
echo "/usr/lib/$(xx-info triple)" > ${LIBGIT2_PATH}/INSTALL_LIBDIR \
51+
&& INSTALL_LIBDIR=$(cat ${LIBGIT2_PATH}/INSTALL_LIBDIR) \
52+
FLAGS=$(xx-clang --print-cmake-defines) \
53+
make -C ${LIBGIT2_PATH} \
54+
&& xx-verify $(cat ${LIBGIT2_PATH}/INSTALL_LIBDIR)/libgit2.so \
55+
&& mkdir -p ${LIBGIT2_PATH}/lib/ \
56+
&& cp -d $(cat ${LIBGIT2_PATH}/INSTALL_LIBDIR)/libgit2.so* ${LIBGIT2_PATH}/lib/

Dockerfile.test

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
# This Docker image can be used to confirm the sets of dependencies can be used together with git2go.
2-
# Note: this just confirms the C library wiring is working, and no implementation details. It does not tell
3-
# for example, if ED25519 is supported by the underlying set of dependencies.
2+
# Note: this just confirms the C library wiring is working, and no implementation details.
3+
# It does for example not tell you if ED25519 is supported by the underlying set of dependencies, etc.
44
ARG IMG
55
ARG TAG
6-
FROM ${IMG}:${TAG} as base
6+
# NB: because the `Dockerfile` performs a build on the $BUILDPLATFORM and then later pushes it as
7+
# if it were a $TARGETPLATFORM image, we need to inverse this by NOT using --platform.
8+
FROM $IMG:$TAG as source
79

810
# Cache clone
911
ARG GIT2GO_TAG
10-
RUN git clone --depth=1 --branch=${GIT2GO_TAG} https://github.com/libgit2/git2go /git2go \
12+
RUN git config --global advice.detachedHead false \
13+
&& git clone --depth=1 --branch=${GIT2GO_TAG} https://github.com/libgit2/git2go /git2go \
1114
&& cd /git2go \
1215
&& go mod tidy
1316

1417
# Set workdir
1518
WORKDIR /git2go
19+
20+
FROM source as test
21+
22+
# Run tests
23+
ARG TARGETPLATFORM
24+
ARG CACHE_BUST
25+
RUN set -eux; \
26+
echo "=> Dynamic test at $CACHE_BUST for $TARGETPLATFORM" \
27+
&& CGO_ENABLED=1 xx-go run script/check-MakeGitError-thread-lock.go \
28+
&& CGO_ENABLED=1 xx-go test ./...
29+
30+
#RUN set -eux; \
31+
# echo "=> Static test at $CACHE_BUST for $TARGETPLATFORM" \
32+
# && CGO_ENABLED=1 xx-go run -tags "static,system_libgit2" script/check-MakeGitError-thread-lock.go \
33+
# && CGO_ENABLED=1 xx-go test -tags "static,system_libgit2" ./...

0 commit comments

Comments
 (0)