generated from benzlokzik/rust-codespace-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from benzlokzik/dev
Added dockerfile
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters