-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
52 lines (37 loc) · 1.54 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
################
##### Builder
FROM rust:slim as builder
WORKDIR /usr/src
# Create blank project
RUN USER=root cargo new medium-rust-dockerize
# Set the working directory
WORKDIR /usr/src/medium-rust-dockerize
# We want dependencies cached, so copy those first.
COPY Cargo.toml Cargo.lock /usr/src/medium-rust-dockerize/
## Install target platform (Cross-Compilation) --> Needed for Alpine
RUN apt update && apt upgrade -y
RUN apt install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross
RUN rustup target add aarch64-unknown-linux-musl
RUN rustup toolchain install stable-aarch64-unknown-linux-musl --force-non-host
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc \
CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc \
CXX_aarch64_unknown_linux_musl=aarch64-linux-gnu-g++
# This is a dummy build to get the dependencies cached.
RUN cargo update
RUN cargo build --target aarch64-unknown-linux-musl --release
# Now copy in the rest of the sources
COPY src /usr/src/medium-rust-dockerize/src/
## Touch main.rs to prevent cached release build
RUN touch /usr/src/medium-rust-dockerize/src/main.rs
# This is the actual application build.
RUN cargo build --target aarch64-unknown-linux-musl --release
################
##### Runtime
FROM alpine:latest as runtime
# Copy application binary from builder image
COPY --from=builder /usr/src/medium-rust-dockerize/target/aarch64-unknown-linux-musl/release/vbus2influx /usr/local/bin/
# Run as nonroot
RUN adduser -S vbus2inf -G dialout
USER vbus2inf
# Run the application
CMD ["vbus2influx"]