1
+ # This Dockerfile tests the hack/Makefile output against git2go.
1
2
ARG BASE_VARIANT=alpine
2
3
ARG GO_VERSION=1.17
3
4
ARG XX_VERSION=1.1.0
4
5
5
- ARG LIBGIT2_IMG
6
- ARG LIBGIT2_TAG
6
+ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
7
7
8
- FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} AS build-deps
8
+ FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-base
9
+
10
+ RUN apk add --no-cache \
11
+ bash \
12
+ curl \
13
+ build-base \
14
+ linux-headers \
15
+ perl \
16
+ cmake \
17
+ pkgconfig \
18
+ gcc \
19
+ musl-dev \
20
+ clang \
21
+ lld
9
22
10
- FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
23
+ COPY --from=xx / /
24
+
25
+ FROM build-base AS build-cross
26
+
27
+ ARG TARGETPLATFORM
28
+
29
+ RUN xx-apk add --no-cache \
30
+ build-base \
31
+ pkgconfig \
32
+ gcc \
33
+ musl-dev \
34
+ clang \
35
+ lld \
36
+ llvm \
37
+ linux-headers
38
+
39
+ WORKDIR /build
40
+ COPY hack/static.sh .
41
+
42
+ ENV CC=xx-clang
43
+ ENV CXX=xx-clang++
44
+
45
+ RUN CHOST=$(xx-clang --print-target-triple) \
46
+ ./static.sh build_libz
47
+
48
+ RUN CHOST=$(xx-clang --print-target-triple) \
49
+ ./static.sh build_openssl
50
+
51
+ RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)/lib:/usr/local/$(xx-info triple)/lib64:${LIBRARY_PATH}" && \
52
+ export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
53
+ export OPENSSL_ROOT_DIR="/usr/local/$(xx-info triple)" && \
54
+ export OPENSSL_CRYPTO_LIBRARY="/usr/local/$(xx-info triple)/lib64" && \
55
+ export OPENSSL_INCLUDE_DIR="/usr/local/$(xx-info triple)/include/openssl"
56
+
57
+ RUN ./static.sh build_libssh2
58
+ RUN ./static.sh build_libgit2
59
+
60
+
61
+ # trimmed removes all non necessary files (i.e. openssl binary).
62
+ FROM build-cross AS trimmed
63
+
64
+ ARG TARGETPLATFORM
65
+ RUN mkdir -p /trimmed/usr/local/$(xx-info triple)/ && \
66
+ mkdir -p /trimmed/usr/local/$(xx-info triple)/share
67
+
68
+ RUN cp -r /usr/local/$(xx-info triple)/lib/ /trimmed/usr/local/$(xx-info triple)/ && \
69
+ cp -r /usr/local/$(xx-info triple)/lib64/ /trimmed/usr/local/$(xx-info triple)/ | true && \
70
+ cp -r /usr/local/$(xx-info triple)/include/ /trimmed/usr/local/$(xx-info triple)/ && \
71
+ cp -r /usr/local/$(xx-info triple)/share/doc/ /trimmed/usr/local/$(xx-info triple)/share/
72
+
73
+ FROM scratch as libs-arm64
74
+ COPY --from=trimmed /trimmed/ /
75
+
76
+ FROM scratch as libs-amd64
77
+ COPY --from=trimmed /trimmed/ /
78
+
79
+ FROM scratch as libs-armv7
80
+ COPY --from=trimmed /trimmed/ /
81
+
82
+ FROM libs-$TARGETARCH$TARGETVARIANT as libs
83
+
84
+ # Everything above this line is a copy from Dockefile.
11
85
12
86
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
13
87
14
88
FROM gostable AS go-linux
15
89
16
90
# Build-base consists of build platform dependencies and xx.
17
91
# These will be used at current arch to yield execute the cross compilations.
18
- FROM go-${TARGETOS} AS build -base
92
+ FROM go-${TARGETOS} AS go -base
19
93
20
94
RUN apk add clang lld pkgconfig
21
95
22
96
COPY --from=xx / /
23
97
24
98
# build-go-mod can still be cached at build platform architecture.
25
- FROM build -base as build-go-mod
99
+ FROM go -base as build-go-mod
26
100
27
101
WORKDIR /root/smoketest
28
102
COPY tests/smoketest/go.mod .
@@ -42,7 +116,7 @@ RUN xx-apk add musl-dev gcc clang lld
42
116
WORKDIR /root/smoketest
43
117
44
118
COPY tests/smoketest/main.go .
45
- COPY --from=build-deps /usr/local/ /usr/local/
119
+ COPY --from=libs /usr/local/ /usr/local/
46
120
47
121
ENV CGO_ENABLED=1
48
122
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" && \
0 commit comments