forked from everx-labs/ever-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
75 lines (64 loc) · 2.52 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1.4.2
# Base builder ---------------------------
FROM --platform=$BUILDPLATFORM rust:1.65-bullseye as rust-builder
WORKDIR /build
# NOTE:
# We can use APT cache here because it's just a builder container
# Don't use cache in the result container
RUN <<EOF
set -e
rm -f /etc/apt/apt.conf.d/docker-clean
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
EOF
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get install -yq \
build-essential \
protobuf-compiler \
cmake \
pkg-config \
libssl-dev \
g++-x86-64-linux-gnu libc6-dev-amd64-cross \
g++-aarch64-linux-gnu libc6-dev-arm64-cross
RUN rustup target add \
x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc \
CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \
CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
# amd64 build ----------------------------
FROM --platform=$BUILDPLATFORM rust-builder AS build-amd64
RUN \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/target,id=target_amd64 \
--mount=type=bind,target=./ \
cargo install \
--path ./ \
--target x86_64-unknown-linux-gnu \
--target-dir=/target
# arm64 build ----------------------------
FROM --platform=$BUILDPLATFORM rust-builder AS build-arm64
RUN \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/target,id=target_arm64 \
--mount=type=bind,target=./ \
cargo install \
--path ./ \
--target aarch64-unknown-linux-gnu \
--target-dir=/target
FROM debian:bullseye-slim as final-base
RUN apt-get update && apt-get install -yq --no-install-recommends git libssl1.1 libc6 ca-certificates
FROM --platform=amd64 final-base as final-amd64
COPY --from=build-amd64 --link /usr/local/cargo/bin/gosh-cli /usr/local/bin/gosh-cli
FROM --platform=arm64 final-base as final-arm64
COPY --from=build-arm64 --link /usr/local/cargo/bin/gosh-cli /usr/local/bin/gosh-cli
FROM final-${TARGETARCH}
ENV GOSH_TRACE=1
WORKDIR /workdir
ENTRYPOINT [ "gosh-cli" ]
CMD [ "help" ]