forked from cilium/proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.tests
120 lines (107 loc) · 5.73 KB
/
Dockerfile.tests
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
#
# BUILDER_BASE is a multi-platform image with all the build tools
#
ARG BUILDER_BASE=quay.io/cilium/cilium-envoy-builder:test-6.1.0-latest
# Common Builder image used in cilium/cilium
ARG PROXYLIB_BUILDER=quay.io/cilium/cilium-builder:767c4152bb156a879fca4c5b76f445de4b4cdaa9@sha256:26392846fa25ab2607c120ece242d61365724a5f21e85f5733f72221637b70fa
#
# ARCHIVE_IMAGE defaults to the result of the first stage below,
# refreshing the build caches from Envoy dependencies before the final
# build stage. This can be overridden on docker build command line to
# use pre-built dependencies. Note that if cross-compiling, these
# pre-built dependencies will include BUILDPLATFORM build tools and
# TARGETPLATFORM build artifacts, and thus can only be reused when
# building on the same BUILDPLATFORM.
#
ARG ARCHIVE_IMAGE=builder-fresh
FROM --platform=$BUILDPLATFORM $PROXYLIB_BUILDER AS proxylib
WORKDIR /go/src/github.com/cilium/proxy
ARG TARGETARCH
RUN --mount=type=bind,readwrite,target=/go/src/github.com/cilium/proxy --mount=mode=0777,target=/cilium/proxy/.cache,type=cache --mount=mode=0777,target=/go/pkg,type=cache \
GOARCH=${TARGETARCH} make -C proxylib all && mv proxylib/libcilium.so /tmp/libcilium.so
FROM --platform=$BUILDPLATFORM $BUILDER_BASE AS builder-fresh
LABEL maintainer="[email protected]"
WORKDIR /cilium/proxy
COPY . ./
ARG V
ARG BAZEL_BUILD_OPTS
ARG DEBUG
ARG BUILDARCH
ARG TARGETARCH
ARG NO_CACHE
ENV TARGETARCH=$TARGETARCH
#
# Build dependencies
#
# Make proxylib available for building the test dependencies by copying it before running the tests
COPY --from=proxylib /tmp/libcilium.so proxylib/libcilium.so
RUN BAZEL_BUILD_OPTS="${BAZEL_BUILD_OPTS} --disk_cache=/tmp/bazel-cache" PKG_BUILD=1 V=$V DEBUG=$DEBUG make envoy-test-deps
# By default this stage picks up the result of the build above, but ARCHIVE_IMAGE can be
# overridden to point to a saved image of an earlier run of that stage.
FROM $ARCHIVE_IMAGE AS archive-cache
FROM --platform=$BUILDPLATFORM $BUILDER_BASE AS builder
LABEL maintainer="[email protected]"
WORKDIR /cilium/proxy
COPY . ./
ARG V
ARG COPY_CACHE_EXT
ARG BAZEL_BUILD_OPTS
ARG DEBUG
ARG TARGETARCH
ENV TARGETARCH=$TARGETARCH
# Clear runner's cache when building deps
RUN --mount=mode=0777,uid=1337,gid=1337,target=/cilium/proxy/.cache,type=cache,id=$TARGETARCH,sharing=private rm -rf /cilium/proxy/.cache/*
# Make proxylib available for building the test dependencies by copying it before running the tests
COPY --from=proxylib /tmp/libcilium.so proxylib/libcilium.so
RUN --mount=target=/tmp/bazel-cache,source=/tmp/bazel-cache,from=archive-cache,rw \
if [ -f /tmp/bazel-cache/ENVOY_VERSION ]; then CACHE_ENVOY_VERSION=`cat /tmp/bazel-cache/ENVOY_VERSION`; ENVOY_VERSION=`cat ENVOY_VERSION`; if [ "${CACHE_ENVOY_VERSION}" != "${ENVOY_VERSION}" ]; then echo "Testing Envoy ${ENVOY_VERSION} with bazel archive from different Envoy version (${CACHE_ENVOY_VERSION})"; else echo "Testing Envoy ${ENVOY_VERSION} with bazel cache of the same version"; fi; else echo "Bazel cache has no ENVOY_VERSION, it may be empty."; fi && \
touch /tmp/bazel-cache/permissions-check && \
if [ -n "${COPY_CACHE_EXT}" ]; then PKG_BUILD=1 make BUILD_DEP_HASHES; if [ -f /tmp/bazel-cache/BUILD_DEP_HASHES ] && ! diff BUILD_DEP_HASHES /tmp/bazel-cache/BUILD_DEP_HASHES; then echo "Build dependencies have changed, clearing bazel cache"; rm -rf /tmp/bazel-cache/*; rm -rf /cilium/proxy/.cache/*; fi ; cp BUILD_DEP_HASHES ENVOY_VERSION /tmp/bazel-cache; fi && \
BAZEL_BUILD_OPTS="${BAZEL_BUILD_OPTS} --disk_cache=/tmp/bazel-cache" PKG_BUILD=1 V=$V DEBUG=$DEBUG make envoy-test-deps && \
if [ -n "${COPY_CACHE_EXT}" ]; then cp -ra /tmp/bazel-cache /tmp/bazel-cache${COPY_CACHE_EXT}; fi
FROM --platform=$BUILDPLATFORM $BUILDER_BASE AS runner
LABEL maintainer="[email protected]"
WORKDIR /cilium/proxy
COPY . ./
ARG V
ARG BAZEL_BUILD_OPTS
ARG BAZEL_TEST_OPTS
ARG DEBUG
ARG BUILDARCH
ARG TARGETARCH
ARG NO_CACHE
ENV TARGETARCH=$TARGETARCH
RUN --mount=mode=0777,uid=1337,gid=1337,target=/cilium/proxy/.cache,type=cache,id=$TARGETARCH,sharing=private if [ -n "$NO_CACHE" ]; then rm -rf /cilium/proxy/.cache/*; fi
# Make proxylib available for the tests by copying it before running the tests
COPY --from=proxylib /tmp/libcilium.so proxylib/libcilium.so
RUN --mount=mode=0777,uid=1337,gid=1337,target=/cilium/proxy/.cache,type=cache,id=$TARGETARCH,sharing=private \
--mount=target=/tmp/bazel-cache,source=/tmp/bazel-cache,from=archive-cache,rw \
if [ "$TARGETARCH" != "$BUILDARCH" ]; then \
if [ "$TARGETARCH" = "amd64" ]; then \
# Allow running x86_64 test binaries via qemu \
ln -s /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.* /lib; \
ln -s /lib /lib64; \
ln -s /usr/x86_64-linux-gnu/lib /usr/cilium-cross-compat/lib; \
elif [ "$TARGETARCH" = "arm64" ]; then \
# Allow running aarch64 test binaries via qemu \
ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.* /lib; \
ln -s /usr/aarch64-linux-gnu/lib /usr/cilium-cross-compat/lib; \
fi; \
fi && \
BAZEL_BUILD_OPTS="${BAZEL_BUILD_OPTS} --disk_cache=/tmp/bazel-cache" BAZEL_TEST_OPTS="${BAZEL_TEST_OPTS}" PKG_BUILD=1 V=$V DEBUG=$DEBUG make envoy-tests && \
cp -Lr /cilium/proxy/bazel-testlogs testlogs
FROM scratch AS empty-builder-archive
LABEL maintainer="[email protected]"
USER 1337:1337
WORKDIR /tmp/bazel-cache
# This stage retains only the build caches from the builder stage.
# This is used as the target for persisting Bazel build caches for later re-use.
FROM empty-builder-archive AS builder-archive
ARG COPY_CACHE_EXT
COPY --from=builder /tmp/bazel-cache${COPY_CACHE_EXT}/ /tmp/bazel-cache/
#
# Keep only the test logs
#
FROM scratch AS testlogs
LABEL maintainer="[email protected]"
COPY --from=runner /cilium/proxy/testlogs testlogs