-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDockerfile.cross-compile
94 lines (70 loc) · 2.39 KB
/
Dockerfile.cross-compile
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
# syntax = docker/dockerfile:1.3
# https://hub.docker.com/_/rust
ARG RUST_VERSION=1.81
ARG OS_BASE=bookworm
# rust source compile with cross platform build support
FROM --platform=$BUILDPLATFORM rust:$RUST_VERSION-${OS_BASE} as builder
# Declare to make available
ARG BUILDPLATFORM
ARG BUILDARCH
ARG TARGETPLATFORM
ARG TARGETARCH
ARG RUST_TOOLCHAIN
ARG RUST_TARGET
ARG RUST_VERSION
ARG OS_BASE
ENV CARGO_HTTP_MULTIPLEXING=false
ARG VERSION=0.0.1
ARG TARI_NETWORK
ARG TARI_TARGET_NETWORK
# Build profile, release by default
ARG BUILD_PROFILE=release
ENV BUILD_PROFILE=${BUILD_PROFILE}
# Extra Cargo flags
ARG RUSTFLAGS=""
ENV RUSTFLAGS="${RUSTFLAGS}"
# Extra Cargo features
ARG FEATURES=""
ENV FEATURES=${FEATURES}
# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /tari
COPY . .
RUN apt-get update && \
sh /tari/scripts/install_ubuntu_dependencies.sh
RUN if [ "${BUILDARCH}" != "${TARGETARCH}" ] ; then \
# Run script to help setup cross-compile environment
. /tari/scripts/cross_compile_tooling.sh ; \
fi
RUN if [ -n "${RUST_TOOLCHAIN}" ] ; then \
# Install a non-standard toolchain if it has been requested.
# By default we use the toolchain specified in rust-toolchain.toml
rustup toolchain install ${RUST_TOOLCHAIN} --force-non-host ; \
fi
# Build application
RUN cargo build --profile ${BUILD_PROFILE} \
--features "${FEATURES}" --locked --bin sha_p2pool
# ARG is not resolved in COPY so we have to hack around it by copying the
# binary to a temporary location
RUN cp -v /tari/target/${BUILD_TARGET}${BUILD_PROFILE}/sha_p2pool /tari/sha_p2pool
# Create runtime base minimal image for the target platform executables
FROM --platform=$TARGETPLATFORM bitnami/minideb:${OS_BASE} as runtime
# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y tini curl && \
# Docker image reduction
apt-get clean all && \
apt-get autoremove --assume-yes && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN groupadd --gid 1000 tari && \
useradd --create-home --no-log-init --shell /bin/bash \
--home-dir /var/tari \
--uid 1000 --gid 1000 tari
WORKDIR /tari
# Copy tari over from the build stage
COPY --from=builder /tari/sha_p2pool /usr/local/bin
# Copy licenses
COPY LICENSE-* ./
USER tari
ENTRYPOINT ["tini", "--", "/usr/local/bin/sha_p2pool"]