This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile.test-libgit2-only
134 lines (95 loc) · 3.36 KB
/
Dockerfile.test-libgit2-only
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This Dockerfile builds and packages libgit2 only (not linked with openssl and libssh2); and tests it against git2go.
ARG BASE_VARIANT=alpine
ARG GO_VERSION=1.19
ARG XX_VERSION=1.1.2
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-base
RUN apk add --no-cache \
bash \
curl \
build-base \
linux-headers \
perl \
cmake \
python3-dev \
pkgconfig \
gcc \
musl-dev \
clang \
lld
COPY --from=xx / /
FROM build-base AS build-cross
ARG TARGETPLATFORM
RUN xx-apk add --no-cache \
build-base \
pkgconfig \
gcc \
musl-dev \
clang \
lld \
llvm \
linux-headers
WORKDIR /build
COPY hack/static.sh .
ENV CC=xx-clang
ENV CXX=xx-clang++
RUN ./static.sh build_libgit2_only
# trimmed removes all non necessary files (i.e. openssl binary).
FROM build-cross AS trimmed
ARG TARGETPLATFORM
RUN mkdir -p /trimmed/usr/local/$(xx-info triple)/ && \
mkdir -p /trimmed/usr/local/$(xx-info triple)/share
RUN cp -r /usr/local/$(xx-info triple)/lib/ /trimmed/usr/local/$(xx-info triple)/ && \
cp -r /usr/local/$(xx-info triple)/include/ /trimmed/usr/local/$(xx-info triple)/
FROM scratch as libs-arm64
COPY --from=trimmed /trimmed/ /
FROM scratch as libs-amd64
COPY --from=trimmed /trimmed/ /
FROM scratch as libs-armv7
COPY --from=trimmed /trimmed/ /
FROM libs-$TARGETARCH$TARGETVARIANT as libs
# Everything above this line is a copy from Dockefile.
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
FROM gostable AS go-linux
# Build-base consists of build platform dependencies and xx.
# These will be used at current arch to yield execute the cross compilations.
FROM go-${TARGETOS} AS go-base
RUN apk add clang lld pkgconfig
COPY --from=xx / /
# build-go-mod can still be cached at build platform architecture.
FROM go-base as build-go-mod
WORKDIR /root/smoketest
COPY tests/smoketest/go.mod .
COPY tests/smoketest/go.sum .
RUN go mod download
# Build stage install per target platform
# dependency and effectively cross compile the application.
FROM build-go-mod as build
ARG TARGETPLATFORM
# Some dependencies have to installed
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
RUN xx-apk add musl-dev gcc clang lld
WORKDIR /root/smoketest
COPY tests/smoketest/main.go .
COPY --from=libs /usr/local/ /usr/local/
ENV CGO_ENABLED=1
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)" && \
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig" && \
export FLAGS="$(pkg-config --static --libs --cflags libgit2)" && \
export CGO_LDFLAGS="${FLAGS} -static" && \
xx-go build \
-ldflags "-s -w" \
-tags 'netgo,osusergo,static_build' \
-o static-test-runner -trimpath main.go
# Ensure that the generated binary is valid for the target platform
RUN xx-verify --static static-test-runner
# This can be deployed into a gcr.io/distroless/static, however
# the alpine has been chosen so it can run the static application
# using the `RUN` statement.
FROM ${BASE_VARIANT}
RUN apk add git
WORKDIR /root/smoketest
COPY --from=build \
/root/smoketest/static-test-runner .
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
RUN /root/smoketest/static-test-runner