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

Commit 187e12a

Browse files
authored
Merge pull request #11 from pjbgf/static
Expose static libraries on the final image and remove dependencies to github during tests
2 parents ae85456 + d53f227 commit 187e12a

File tree

11 files changed

+570
-132
lines changed

11 files changed

+570
-132
lines changed

Dockerfile

+76-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,79 @@
1-
FROM scratch
1+
# This Dockerfile tests the hack/Makefile output against git2go.
2+
ARG BASE_VARIANT=alpine
3+
ARG GO_VERSION=1.17.6
4+
ARG XX_VERSION=1.1.0
5+
6+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
7+
8+
FROM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
9+
10+
FROM gostable AS go-linux
11+
12+
FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-deps
13+
14+
RUN apk add --no-cache \
15+
bash \
16+
curl \
17+
build-base \
18+
linux-headers \
19+
perl \
20+
cmake \
21+
pkgconfig \
22+
gcc \
23+
musl-dev \
24+
clang \
25+
lld
26+
27+
COPY --from=xx / /
28+
29+
ARG TARGETPLATFORM
30+
31+
RUN xx-apk add --no-cache \
32+
xx-c-essentials
33+
34+
RUN xx-apk add --no-cache \
35+
xx-cxx-essentials
36+
37+
ARG TARGETPLATFORM
38+
RUN xx-apk add --no-cache \
39+
build-base \
40+
pkgconfig \
41+
gcc \
42+
musl-dev \
43+
clang \
44+
lld \
45+
llvm \
46+
linux-headers
47+
48+
WORKDIR /build
49+
COPY hack/static.sh .
50+
51+
ARG TARGETPLATFORM
52+
ENV CC=xx-clang
53+
ENV CXX=xx-clang++
54+
55+
RUN CHOST=$(xx-clang --print-target-triple) \
56+
./static.sh build_libz
57+
58+
RUN CHOST=$(xx-clang --print-target-triple) \
59+
./static.sh build_openssl
60+
61+
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)/lib:/usr/local/$(xx-info triple)/lib64:${LIBRARY_PATH}" && \
62+
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
63+
export OPENSSL_ROOT_DIR="/usr/local/$(xx-info triple)" && \
64+
export OPENSSL_CRYPTO_LIBRARY="/usr/local/$(xx-info triple)/lib64" && \
65+
export OPENSSL_INCLUDE_DIR="/usr/local/$(xx-info triple)/include/openssl"
66+
67+
RUN ./static.sh build_libssh2
68+
RUN ./static.sh build_libgit2
69+
70+
71+
FROM go-${TARGETOS} AS build
72+
73+
# Copy cross-compilation tools
74+
COPY --from=xx / /
75+
# Copy compiled libraries
76+
COPY --from=build-deps /usr/local/ /usr/local/
277

378
COPY ./hack/Makefile /Makefile
479
COPY ./hack/static.sh /static.sh

Dockerfile.test

+6-3
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ COPY tests/smoketest/go.mod .
8282
COPY tests/smoketest/go.sum .
8383
RUN go mod download
8484

85-
COPY tests/smoketest/main.go .
86-
8785
ARG TARGETPLATFORM
86+
8887
# Some dependencies have to installed
8988
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
9089
RUN xx-apk add --no-cache \
9190
musl-dev \
9291
gcc
9392

93+
94+
COPY tests/smoketest/main.go .
95+
9496
ENV CGO_ENABLED=1
9597
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)/lib:/usr/local/$(xx-info triple)/lib64:${LIBRARY_PATH}" && \
9698
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
@@ -109,8 +111,9 @@ RUN xx-verify --static static-test-runner
109111
# using the `RUN` statement.
110112
FROM ${BASE_VARIANT}
111113

114+
RUN apk add git
115+
112116
WORKDIR /root/smoketest
113-
COPY tests/smoketest/keys /root/smoketest/keys
114117
COPY --from=build \
115118
/root/smoketest/static-test-runner .
116119

hack/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BUILD_SHARED_LIBS ?= ON
2424
CMAKE_VERSION ?= 3.21.3
2525

2626
# Libgit2 version to be compiled and installed.
27-
LIBGIT2_VERSION ?= 1.1.1
27+
LIBGIT2_VERSION ?= 1.3.0
2828
# In some scenarios libgit2 needs to be checked out to a specific commit.
2929
# This takes precedence over LIBGIT_VERSION if defined.
3030
# Ref: https://github.com/libgit2/git2go/issues/834

hack/static.sh

+42-16
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,24 @@ LIBSSH2_URL="${LIBSSH2_URL:-https://github.com/libssh2/libssh2/archive/refs/tags
1010
# provide better performance (i.e. intel/cloudflare) or that are better maintained.
1111
LIBZ_URL="${LIBZ_URL:-https://github.com/madler/zlib/archive/refs/tags/v1.2.11.tar.gz}"
1212

13-
BUILD_ROOT_DIR="/build"
13+
TARGET_DIR="${TARGET_DIR:-/usr/local/$(xx-info triple)}"
14+
BUILD_ROOT_DIR="${BUILD_ROOT_DIR:-/build}"
1415
SRC_DIR="${BUILD_ROOT_DIR}/src"
1516

17+
18+
TARGET_ARCH="$(uname -m)"
19+
if command -v xx-info; then
20+
TARGET_ARCH="$(xx-info march)"
21+
fi
22+
23+
C_COMPILER="/usr/bin/gcc"
24+
CMAKE_PARAMS=""
25+
if command -v xx-clang; then
26+
C_COMPILER="/usr/bin/xx-clang"
27+
CMAKE_PARAMS="$(xx-clang --print-cmake-defines)"
28+
fi
29+
30+
1631
function download_source(){
1732
mkdir -p "$2"
1833

@@ -25,9 +40,12 @@ function build_libz(){
2540
download_source "${LIBZ_URL}" "${SRC_DIR}/libz"
2641
pushd "${SRC_DIR}/libz"
2742

28-
./configure --static \
29-
--archs="-arch $(xx-info march)" \
30-
--prefix="/usr/local/$(xx-info triple)"
43+
if [ "${TARGET_ARCH}" = "$(uname -m)" ]; then
44+
./configure --static --prefix="${TARGET_DIR}"
45+
else
46+
./configure --static --prefix="${TARGET_DIR}" \
47+
--archs="-arch ${TARGET_ARCH}"
48+
fi
3149

3250
make install
3351

@@ -38,17 +56,17 @@ function build_openssl(){
3856
download_source "${OPENSSL_URL}" "${SRC_DIR}/openssl"
3957
pushd "${SRC_DIR}/openssl"
4058

41-
target_name="$(xx-info march)"
59+
target_name="${TARGET_ARCH}"
4260
if [ "${target_name}" = "armv7l" ]; then
4361
# openssl does not have a specific armv7l
4462
# using generic32 instead.
4563
target_name=generic32
4664
fi
4765

4866
./Configure "linux-${target_name}" threads no-shared zlib -fPIC -DOPENSSL_PIC \
49-
--prefix="/usr/local/$(xx-info triple)" \
50-
--with-zlib-include="/usr/local/$(xx-info triple)/include" \
51-
--with-zlib-lib="/usr/local/$(xx-info triple)/lib" \
67+
--prefix="${TARGET_DIR}" \
68+
--with-zlib-include="${TARGET_DIR}/include" \
69+
--with-zlib-lib="${TARGET_DIR}/lib" \
5270
--openssldir=/etc/ssl
5371

5472
make
@@ -65,9 +83,9 @@ function build_libssh2(){
6583
mkdir -p build
6684
pushd build
6785

68-
cmake "$(xx-clang --print-cmake-defines)" \
69-
-DCMAKE_C_COMPILER="/usr/bin/xx-clang" \
70-
-DCMAKE_INSTALL_PREFIX="/usr/local/$(xx-info triple)" \
86+
cmake "${CMAKE_PARAMS}" \
87+
-DCMAKE_C_COMPILER="${C_COMPILER}" \
88+
-DCMAKE_INSTALL_PREFIX="${TARGET_DIR}" \
7189
-DBUILD_SHARED_LIBS=OFF \
7290
-DCMAKE_C_FLAGS=-fPIC \
7391
-DCRYPTO_BACKEND=OpenSSL \
@@ -90,21 +108,22 @@ function build_libgit2(){
90108

91109
pushd build
92110

93-
cmake "$(xx-clang --print-cmake-defines)" \
94-
-DCMAKE_C_COMPILER="/usr/bin/xx-clang" \
95-
-DCMAKE_INSTALL_PREFIX="/usr/local/$(xx-info triple)" \
111+
cmake "${CMAKE_PARAMS}" \
112+
-DCMAKE_C_COMPILER="${C_COMPILER}" \
113+
-DCMAKE_INSTALL_PREFIX="${TARGET_DIR}" \
96114
-DTHREADSAFE:BOOL=ON \
97115
-DBUILD_CLAR:BOOL:BOOL=OFF \
98116
-DBUILD_SHARED_LIBS=OFF \
99117
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON \
100118
-DCMAKE_C_FLAGS=-fPIC \
101119
-DUSE_SSH:BOOL=ON \
120+
-DHAVE_LIBSSH2_MEMORY_CREDENTIALS:BOOL=ON \
102121
-DDEPRECATE_HARD:BOOL=ON \
103122
-DUSE_BUNDLED_ZLIB:BOOL=ON \
104123
-DUSE_HTTPS:STRING=OpenSSL \
105124
-DREGEX_BACKEND:STRING=builtin \
106-
-DCMAKE_INCLUDE_PATH="/usr/local/$(xx-info triple)/include" \
107-
-DCMAKE_LIBRARY_PATH="/usr/local/$(xx-info triple)/lib" \
125+
-DCMAKE_INCLUDE_PATH="${TARGET_DIR}/include" \
126+
-DCMAKE_LIBRARY_PATH="${TARGET_DIR}/lib" \
108127
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
109128
..
110129

@@ -114,4 +133,11 @@ function build_libgit2(){
114133
popd
115134
}
116135

136+
function all(){
137+
build_libz
138+
build_openssl
139+
build_libssh2
140+
build_libgit2
141+
}
142+
117143
"$@"

tests/smoketest/go.mod

+38-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ go 1.17
55
require github.com/libgit2/git2go/v33 v33.0.6
66

77
require (
8-
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect
9-
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
8+
github.com/Microsoft/go-winio v0.4.17 // indirect
9+
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
10+
github.com/acomagu/bufpipe v1.0.3 // indirect
11+
github.com/emirpasic/gods v1.12.0 // indirect
12+
github.com/fluxcd/pkg/gittestserver v0.5.0 // indirect
13+
github.com/fluxcd/pkg/ssh v0.3.1 // indirect
14+
github.com/fluxcd/source-controller v0.20.1 // indirect
15+
github.com/go-git/gcfg v1.5.0 // indirect
16+
github.com/go-git/go-billy/v5 v5.3.1 // indirect
17+
github.com/go-git/go-git/v5 v5.4.2 // indirect
18+
github.com/go-logr/logr v1.2.2 // indirect
19+
github.com/gogo/protobuf v1.3.2 // indirect
20+
github.com/google/go-cmp v0.5.6 // indirect
21+
github.com/google/gofuzz v1.2.0 // indirect
22+
github.com/imdario/mergo v0.3.12 // indirect
23+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
24+
github.com/json-iterator/go v1.1.12 // indirect
25+
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
26+
github.com/mitchellh/go-homedir v1.1.0 // indirect
27+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
28+
github.com/modern-go/reflect2 v1.0.2 // indirect
29+
github.com/satori/go.uuid v1.2.0 // indirect
30+
github.com/sergi/go-diff v1.1.0 // indirect
31+
github.com/sosedoff/gitkit v0.2.1-0.20200818155723-72ebbcf5056d // indirect
32+
github.com/xanzy/ssh-agent v0.3.0 // indirect
33+
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
34+
golang.org/x/net v0.0.0-20211215060638-4ddde0e984e9 // indirect
35+
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8 // indirect
36+
golang.org/x/text v0.3.7 // indirect
37+
gopkg.in/inf.v0 v0.9.1 // indirect
38+
gopkg.in/warnings.v0 v0.1.2 // indirect
39+
gopkg.in/yaml.v2 v2.4.0 // indirect
40+
k8s.io/api v0.23.1 // indirect
41+
k8s.io/apimachinery v0.23.1 // indirect
42+
k8s.io/klog/v2 v2.30.0 // indirect
43+
k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 // indirect
44+
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
45+
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
1046
)

0 commit comments

Comments
 (0)