Created
June 18, 2021 16:57
-
-
Save digizeph/f252202875fc8cea3aabc1d43106574c to your computer and use it in GitHub Desktop.
Two-stage build for Rust project with need for ssl libraries (such as an web api)
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
LABEL maintainer="YOUR NAME <YOUR@EMAIL>" | |
# select build image | |
FROM rust:1.52 as build | |
# create a new empty shell project | |
RUN USER=root cargo new --bin my_project | |
WORKDIR /my_project | |
# if you need nightly | |
# change toolchain to nightly for rocket | |
# RUN rustup default nightly | |
# build for release | |
COPY ./Cargo.toml ./Cargo.toml | |
COPY ./src ./src | |
RUN cargo build --release | |
# our final base | |
FROM debian:buster-slim | |
RUN DEBIAN=NONINTERACTIVE apt update; apt install -y libssl-dev libpq-dev ca-certificates tzdata; rm -rf /var/lib/apt/lists/* | |
# copy the build artifact from the build stage | |
COPY --from=build /my_project/target/release/YOUR_PROGRAM /usr/local/bin/YOUR_PROGRAM | |
# set the startup command to run your binary | |
CMD ["YOUR_PROGRAM"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment