37 lines
959 B
Docker
37 lines
959 B
Docker
FROM rust:1.85-slim-bookworm AS build
|
|
|
|
# get x86_64-unknown-linux-musl as a build target
|
|
RUN rustup target add x86_64-unknown-linux-musl
|
|
|
|
# create a new empty shell project
|
|
RUN USER=root cargo new --bin http_server
|
|
WORKDIR /http_server
|
|
|
|
# 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 as a static-pie linked binary
|
|
RUN rm ./target/release/deps/http_server*
|
|
ENV RUSTFLAGS='-C target-feature=+crt-static'
|
|
RUN cargo build --release --target x86_64-unknown-linux-musl
|
|
RUN strip /http_server/target/x86_64-unknown-linux-musl/release/http_server
|
|
|
|
FROM scratch
|
|
|
|
# copy the build artifact from the build stage
|
|
COPY --from=build /http_server/target/x86_64-unknown-linux-musl/release/http_server /
|
|
COPY ./www /www
|
|
COPY ./internal /internal
|
|
|
|
EXPOSE 8080
|
|
|
|
CMD ["/http_server"]
|