-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathDockerfile
More file actions
155 lines (117 loc) · 4.32 KB
/
Copy pathDockerfile
File metadata and controls
155 lines (117 loc) · 4.32 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
# Build container
FROM --platform=${BUILDPLATFORM} rust:1.95-slim-bookworm AS rust
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
ARG TARGETARCH
RUN <<EOF
case ${TARGETARCH} in
"amd64")
PACKAGES="gcc-x86-64-linux-gnu g++-x86-64-linux-gnu"
;;
"arm64")
PACKAGES="gcc-aarch64-linux-gnu g++-aarch64-linux-gnu"
;;
*)
echo "Unsupported platform: ${TARGETPLATFORM}"
exit 1
;;
esac
DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install --no-install-recommends -y \
cmake \
ninja-build \
curl \
file \
make \
unzip \
git \
lsb-release \
software-properties-common \
gnupg \
pkg-config \
${PACKAGES}
curl -L -o /tmp/llvm.sh https://apt.llvm.org/llvm.sh
chmod +x /tmp/llvm.sh
/tmp/llvm.sh 19
curl -1sLf 'https://dl.cloudsmith.io/public/task/task/setup.deb.sh' | bash
apt-get install -y task
EOF
# Copy source code
COPY . /app
WORKDIR /app
RUN --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
--mount=type=cache,target=/usr/local/cargo/git,sharing=locked \
--mount=type=cache,target=/app/target,sharing=locked \
<<EOF
case ${TARGETARCH} in
"amd64")
RUSTARCH=x86_64-unknown-linux-gnu
;;
"arm64")
RUSTARCH=aarch64-unknown-linux-gnu
;;
*)
echo "Unsupported platform: ${TARGETPLATFORM}"
exit 1
;;
esac
# Fetch rust packages
task -v fetch TARGET=${RUSTARCH}
# Build application
task -v build:strip TARGET=${RUSTARCH} PROFILE=release ARGS="--locked --bin slim --bin slim-control-plane --bin channel-manager"
mv target/${RUSTARCH}/release/slim /slim
mv target/${RUSTARCH}/release/slim.dbg /slim.dbg
# Strip and export control plane binary
task -v strip TARGET_BIN=target/${RUSTARCH}/release/slim-control-plane
mv target/${RUSTARCH}/release/slim-control-plane /slim-control-plane
mv target/${RUSTARCH}/release/slim-control-plane.dbg /slim-control-plane.dbg
# Strip and export channel manager binary
task -v strip TARGET_BIN=target/${RUSTARCH}/release/channel-manager
mv target/${RUSTARCH}/release/channel-manager /channel-manager
mv target/${RUSTARCH}/release/channel-manager.dbg /channel-manager.dbg
EOF
# Grab libgcc from the CC image
FROM gcr.io/distroless/cc-debian12 AS libgcc-provider
# Runtime images - debug executable, debug symbols and, most importantly, a shell :)
FROM debian:bookworm-slim AS slim-debug
ARG TARGETARCH
# copy the build artifacts from the build stage
COPY --from=rust /slim /slim
COPY --from=rust /slim.dbg /slim.dbg
# Runtime images - release executable
FROM gcr.io/distroless/base-nossl-debian12:nonroot AS slim-release
ARG TARGETARCH
# Copy libgcc from the libgcc-provider image
COPY --from=libgcc-provider /lib/*-linux-gnu/libgcc_s.so.1 /lib/
# copy the artifacts from the build stage
COPY --from=rust /slim /slim
# Runtime image - control plane debug executable, debug symbols and a shell
FROM debian:bookworm-slim AS control-plane-debug
ARG TARGETARCH
# copy the build artifacts from the build stage
COPY --from=rust /slim-control-plane /slim-control-plane
COPY --from=rust /slim-control-plane.dbg /slim-control-plane.dbg
# Runtime image - control plane release executable
FROM gcr.io/distroless/base-nossl-debian12:nonroot AS control-plane-release
ARG TARGETARCH
# Copy libgcc from the libgcc-provider image
COPY --from=libgcc-provider /lib/*-linux-gnu/libgcc_s.so.1 /lib/
# copy the artifacts from the build stage
COPY --from=rust /slim-control-plane /slim-control-plane
ENTRYPOINT ["/slim-control-plane"]
# Runtime image - channel manager debug executable, debug symbols and a shell
FROM debian:bookworm-slim AS channel-manager-debug
ARG TARGETARCH
# copy the build artifacts from the build stage
COPY --from=rust /channel-manager /channel-manager
COPY --from=rust /channel-manager.dbg /channel-manager.dbg
# Runtime image - channel manager release executable
FROM gcr.io/distroless/base-nossl-debian12:nonroot AS channel-manager-release
ARG TARGETARCH
# Copy libgcc from the libgcc-provider image
COPY --from=libgcc-provider /lib/*-linux-gnu/libgcc_s.so.1 /lib/
# copy the artifacts from the build stage
COPY --from=rust /channel-manager /channel-manager
ENTRYPOINT ["/channel-manager"]