generated from benzlokzik/rust-codespace-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
35 lines (25 loc) · 870 Bytes
/
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
# official Rust image as a builder
FROM rust:1.70 as builder
# new empty project
RUN USER=root cargo new --bin app
WORKDIR /app
# copy my manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
# build only the dependencies to cache them
RUN cargo build --release
RUN rm src/*.rs
# copy the source code
COPY ./src ./src
# remove the dummy target
RUN rm ./target/release/deps/fahrenheit_celsius_kelvin_converter*
# set the build to be statically linked
RUN RUSTFLAGS='-C target-feature=+crt-static'
# build for release
RUN cargo build --release
# final base image, use the same Debian version as the builder
FROM debian:bullseye-slim
# copy the build artifact from the build stage
COPY --from=builder /app/target/release/fahrenheit_celsius_kelvin_converter .
# set the startup command to run binary
CMD ["./fahrenheit_celsius_kelvin_converter"]