-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.musl
30 lines (24 loc) · 1.11 KB
/
Dockerfile.musl
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
FROM rust:latest as cargo-build
RUN apt-get update
RUN apt-get install musl-tools -y
RUN rustup override set nightly
RUN rustup target add x86_64-unknown-linux-musl --toolchain=nightly
WORKDIR /usr/src/rust-api
# This section ensures that changing our source code doesn't cause us to have
# to recompile all of our dependencies by leveraging the Docker layer system
COPY rust-api/Cargo.toml Cargo.toml
RUN mkdir src
RUN echo "fn main() {println!(\"If you see this, the build broke :(\")}" > src/main.rs
RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
RUN rm -f target/x86_64-unknown-linux-musl/release/deps/rust_api*
# This builds any changes to our source code
COPY rust-api/diesel.toml .
ADD rust-api/migrations ./migrations
ADD rust-api/src ./src
RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
# This is our final production image
FROM alpine:latest
RUN apk update
RUN apk add postgresql-dev
COPY --from=cargo-build /usr/src/rust-api/target/x86_64-unknown-linux-musl/release/rust-api /usr/local/bin/rust-api
CMD ["/usr/local/bin/rust-api"]