|
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/ |
0 commit comments