-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (30 loc) · 1.01 KB
/
Dockerfile
File metadata and controls
40 lines (30 loc) · 1.01 KB
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
31
32
33
34
35
36
37
38
39
40
FROM messense/rust-musl-cross:x86_64-musl as chef
ENV SQLX_OFFLINE=true
# Create app user
ARG USER=user
ARG GROUP=user
ARG UID=1000
ARG GID=1000
RUN groupadd -g $GID $GROUP && useradd -u $UID -g $GROUP $USER
RUN cargo install cargo-chef
WORKDIR /market
FROM chef AS planner
COPY . .
ARG PGHOST=localhost
ARG PGPORT=5432
ENV RUST_BACKTRACE=full
ENV DATABASE_URL="postgres://market_app@${PGHOST}:${PGPORT}/market_db"
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /market/recipe.json recipe.json
RUN rustup target add x86_64-unknown-linux-musl
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl
# We do not need the Rust toolchain to run the binary!
FROM scratch
COPY --from=builder /market/target/x86_64-unknown-linux-musl/release/market /usr/local/bin/market
EXPOSE 8000
ENTRYPOINT [ "market" ]