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

Commit 0ce1e0f

Browse files
author
Paulo Gomes
committed
Add static libraries to final image
Signed-off-by: Paulo Gomes <[email protected]>
1 parent 6f7fdeb commit 0ce1e0f

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
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

+4-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" && \
@@ -112,7 +114,6 @@ FROM ${BASE_VARIANT}
112114
RUN apk add git
113115

114116
WORKDIR /root/smoketest
115-
COPY tests/smoketest/keys /root/smoketest/keys
116117
COPY --from=build \
117118
/root/smoketest/static-test-runner .
118119

0 commit comments

Comments
 (0)