# Dockerfile for creating a statically-linked Rust application using docker's
# multi-stage build feature. This also leverages the docker build cache to avoid
# re-downloading dependencies if they have not changed.
FROM rust:1.77.2 AS build

# create a new empty shell project
RUN USER=root cargo new --bin stratodyndns
WORKDIR /stratodyndns

# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# this build step will cache your dependencies
RUN cargo build --release
RUN rm src/*.rs

# copy your source tree
COPY ./src ./src

# build for release
RUN rm ./target/release/deps/stratodyndns*
RUN cargo build --release

# Copy the statically-linked binary into a scratch container.
FROM rust:1.77.2

# copy the build artifact from the build stage
COPY --from=build /stratodyndns/target/release/stratodyndns .

# set the startup command to run your binary
CMD ["./stratodyndns"]