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

Commit 58c2307

Browse files
committed
Init
Signed-off-by: Hidde Beydals <hello@hidde.co>
0 parents  commit 58c2307

File tree

9 files changed

+557
-0
lines changed

9 files changed

+557
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/**
2+
!CMakeLists.txt
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
name: 'Container image'
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
pull_request:
9+
jobs:
10+
build:
11+
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
18+
services:
19+
registry:
20+
image: registry:2
21+
ports:
22+
- 5000:5000
23+
steps:
24+
- name: Checkout
25+
id: checkout
26+
uses: actions/checkout@v2
27+
- name: Set up QEMU
28+
id: qemu
29+
uses: docker/setup-qemu-action@v1
30+
with:
31+
image: tonistiigi/binfmt:latest
32+
platforms: ${{ matrix.platforms }}
33+
- name: Set up Docker Buildx
34+
id: buildx
35+
uses: docker/setup-buildx-action@v1
36+
with:
37+
config-inline: |
38+
[worker.oci]
39+
max-parallelism = 4
40+
driver-opts: network=host
41+
- name: Inspect builder
42+
run: |
43+
echo "Name: ${{ steps.buildx.outputs.name }}"
44+
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
45+
echo "Status: ${{ steps.buildx.outputs.status }}"
46+
echo "Flags: ${{ steps.buildx.outputs.flags }}"
47+
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
48+
- name: Build candidate
49+
id: build_candidate
50+
uses: docker/build-push-action@v2
51+
with:
52+
context: .
53+
file: Dockerfile
54+
platforms: ${{ matrix.platforms }}
55+
push: true
56+
tags: localhost:5000/golang-with-libgit2:latest
57+
- name: Inspect candidate
58+
run: |
59+
docker buildx imagetools inspect localhost:5000/golang-with-libgit2:latest
60+
- name: Test candidate
61+
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

.gitignore

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

CMakeLists.txt

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
cmake_minimum_required(VERSION 3.5.1)
2+
3+
project(Superbuild)
4+
5+
# Set a default build type if none was specified
6+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
7+
message(STATUS "Setting build type to 'Release' as none was specified.")
8+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
9+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
10+
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
11+
endif()
12+
13+
option(BUILD_SHARED_LIBS "Build with shared libs." ON)
14+
option(USE_EXTERNAL_INSTALL "If enabled, install dependencies to CMAKE_INSTALL_PREFIX." OFF)
15+
mark_as_advanced(USE_EXTERNAL_INSTALL)
16+
17+
include(ExternalProject)
18+
19+
set_property(DIRECTORY PROPERTY EP_PREFIX ${Superbuild_BINARY_DIR})
20+
set(install_prefix ${Superbuild_BINARY_DIR}/install)
21+
if (USE_EXTERNAL_INSTALL)
22+
set(install_prefix ${CMAKE_INSTALL_PREFIX})
23+
else()
24+
mark_as_advanced(CMAKE_INSTALL_PREFIX)
25+
endif()
26+
27+
#[[
28+
Default Cmake configuration flags.
29+
Ref: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html
30+
]]
31+
set(default_cmake_args
32+
"-DCMAKE_PREFIX_PATH:PATH=${install_prefix};${DRAKE_SUPERBUILD_PREFIX_PATH};${CMAKE_PREFIX_PATH}"
33+
"-DCMAKE_INSTALL_PREFIX:PATH=${install_prefix}"
34+
"-DCMAKE_FIND_ROOT_PATH:PATH=${install_prefix}"
35+
"-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
36+
"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON"
37+
"-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}"
38+
"-DENABLE_TESTING:BOOL=OFF"
39+
"-DENABLE_PROGRAMS:BOOL=OFF"
40+
"-DBUILD_DOCUMENTATION:BOOL=OFF"
41+
"-DBUILD_EXAMPLES:BOOL=OFF"
42+
"-DBUILD_TESTING:BOOL=OFF"
43+
"-DCMAKE_C_FLAGS:STRING=-fPIC"
44+
)
45+
46+
#[[
47+
Build zlib-ng with zlib compatible API enabled.
48+
]]
49+
ExternalProject_Add(zlib
50+
URL https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.5.tar.gz
51+
URL_HASH SHA256=eca3fe72aea7036c31d00ca120493923c4d5b99fe02e6d3322f7c88dbdcd0085
52+
CMAKE_ARGS
53+
${default_cmake_args}
54+
#[[ Build with ZLIB compatible API ]]
55+
-DZLIB_COMPAT:BOOL=ON
56+
-DZLIB_ENABLE_TESTS:BOOL=OFF
57+
#[[ Required to ensure the current ${install_prefix} is always taken into account,
58+
as ${CMAKE_INSTALL_PREFIX} is cached persistently.
59+
Ref: https://github.com/zlib-ng/zlib-ng/blob/2.0.5/cmake/detect-install-dirs.cmake ]]
60+
-DBIN_INSTALL_DIR:PATH=${install_prefix}/bin
61+
-DLIB_INSTALL_DIR:PATH=${install_prefix}/lib
62+
-DINC_INSTALL_DIR:PATH=${install_prefix}/include
63+
-DPKGCONFIG_INSTALL_DIR:PATH=${install_prefix}/lib/pkgconfig
64+
)
65+
66+
#[[
67+
mbedTLS does at present not support https://github.com/zlib-ng/zlib-ng/blob/2.0.5/cmake/detect-install-dirs.cmakeED25519, making it unsuitable for some SSH setups, and at present not a decent
68+
dependency option for libssh2.
69+
70+
Target review of ED25519 support is Q3 2021.
71+
Ref: https://github.com/ARMmbed/mbedtls/issues/2452#issuecomment-802683144
72+
Ref: https://github.com/ARMmbed/mbedtls/pull/3245
73+
74+
ExternalProject_Add(mbedtls
75+
URL https://github.com/ARMmbed/mbedtls/archive/refs/tags/v2.27.0.tar.gz
76+
URL_HASH SHA256=2a07856e541f0e5f6eaee4f78018c52f25bd244ed76f9020dea54a8b02cac6ea
77+
PATCH_COMMAND
78+
./scripts/config.pl set MBEDTLS_THREADING_C &&
79+
./scripts/config.pl set MBEDTLS_THREADING_PTHREAD &&
80+
./scripts/config.pl set MBEDTLS_MD4_C
81+
CMAKE_ARGS
82+
${default_cmake_args}
83+
-DUSE_SHARED_MBEDTLS_LIBRARY:BOOL=${BUILD_SHARED_LIBS}
84+
)
85+
]]
86+
87+
#[[
88+
Build OpenSSL.
89+
OpenSSL does not publish any cmake directives, and we have to configure everything ourselves.
90+
Ref: https://github.com/openssl/openssl/blob/openssl-3.0.0/INSTALL.md
91+
]]
92+
set(default_openssl_args
93+
"--prefix=${install_prefix}"
94+
#[[ Path on the TARGET system where we expect the (certificate) configuration to live.
95+
The current allows to piggy back off Debian's ca-certificate package while maintaining our own OpenSSL version. ]]
96+
"--openssldir=/etc/ssl"
97+
#[[ Enforce the directory to ${install_prefix}/lib. As depending on the build system, Configure may otherwise choose
98+
to use /lib64. Which makes locating the libraries more difficult. ]]
99+
"--libdir=lib"
100+
"--with-zlib-include=${install_prefix}/include"
101+
"--with-zlib-lib=${install_prefix}/lib"
102+
"--release"
103+
"--banner=Configured"
104+
)
105+
if(NOT BUILD_SHARED_LIBS)
106+
list(APPEND default_openssl_args "no-shared")
107+
list(APPEND default_openssl_args "-static")
108+
endif()
109+
ExternalProject_Add(openssl
110+
DEPENDS zlib
111+
URL https://www.openssl.org/source/openssl-3.0.0.tar.gz
112+
URL_HASH SHA256=59eedfcb46c25214c9bd37ed6078297b4df01d012267fe9e9eee31f61bc70536
113+
CONFIGURE_COMMAND <SOURCE_DIR>/Configure ${default_openssl_args}
114+
BUILD_COMMAND make build_sw
115+
INSTALL_COMMAND make install_sw
116+
)
117+
118+
#[[
119+
Build libssh2.
120+
At present with OpenSSL as a backend, see mbedTLS doc block for reasoning.
121+
]]
122+
set(default_libssh2_args
123+
"-DENABLE_ZLIB_COMPRESSION:BOOL=ON"
124+
"-DCRYPTO_BACKEND:STRING=OpenSSL"
125+
#[[ -DCRYPTO_BACKEND:STRING=mbedTLS ]]
126+
)
127+
if(NOT BUILD_SHARED_LIBS)
128+
list(APPEND default_libssh2_args "-DOPENSSL_USE_STATIC_LIBS:BOOL=TRUE")
129+
endif()
130+
ExternalProject_Add(libssh2
131+
DEPENDS zlib
132+
DEPENDS openssl
133+
URL https://github.com/libssh2/libssh2/archive/refs/tags/libssh2-1.10.0.tar.gz
134+
URL_HASH SHA256=31469ccfc71a5247c926e3f0938e122cbb7a7a4a1bdf1cf2d3121f78b558d261
135+
CMAKE_ARGS
136+
${default_cmake_args}
137+
${default_libssh2_args}
138+
)
139+
140+
#[[
141+
Build libgit2 with the above dependencies, or explicit defined builtins.
142+
]]
143+
ExternalProject_Add(libgit2
144+
DEPENDS zlib
145+
DEPENDS openssl
146+
DEPENDS libssh2
147+
URL https://github.com/libgit2/libgit2/archive/109b4c887ffb63962c7017a66fc4a1f48becb48e.tar.gz
148+
URL_HASH SHA256=bc4ef7d6628d2248995bbd86ad77eb96376d683e7121779c7abde480928ae21a
149+
CMAKE_ARGS
150+
${default_cmake_args}
151+
-DBUILD_CLAR:BOOL:BOOL=OFF
152+
-DTHREADSAFE:BOOL=ON
153+
-DUSE_BUNDLED_ZLIB:BOOL=OFF
154+
-DUSE_HTTP_PARSER:STRING=builtin
155+
-DREGEX_BACKEND:STRING=builtin
156+
-DUSE_HTTPS:STRING=OpenSSL
157+
#[[ -DUSE_HTTPS:STRING=mbedTLS ]]
158+
)

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Dockerfile.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 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.
4+
ARG IMG
5+
ARG TAG
6+
FROM ${IMG}:${TAG} as base
7+
8+
# Cache clone
9+
ARG GIT2GO_TAG
10+
RUN git clone --depth=1 --branch=${GIT2GO_TAG} https://github.com/libgit2/git2go /git2go \
11+
&& cd /git2go \
12+
&& go mod tidy
13+
14+
# Set workdir
15+
WORKDIR /git2go

0 commit comments

Comments
 (0)