-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile.server
42 lines (31 loc) · 1.18 KB
/
Dockerfile.server
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
41
42
FROM rustlang/rust:nightly-buster-slim as builder
ARG SIMDIR=red-simulation
ARG SRVDIR=red-server
RUN apt-get update && apt-get install -y libpq-dev
RUN cargo install diesel_cli --no-default-features --features postgres
# Instal&cache cargo dependencies
RUN cargo new --lib /app/$SIMDIR
COPY ./$SIMDIR/Cargo.toml ./$SIMDIR/Cargo.lock /app/$SIMDIR/
RUN cargo new --lib /app/$SRVDIR
COPY ./$SRVDIR/diesel.toml ./$SRVDIR/Cargo.toml $SRVDIR/Cargo.lock /app/$SRVDIR/
WORKDIR /app
RUN (cd $SIMDIR && cargo fetch) \
&& (cd $SRVDIR && cargo fetch) \
&& rm -rf $SIMDIR/src && rm -rf $SRVDIR/src
COPY ./$SIMDIR/ . /app/$SIMDIR/
COPY ./$SRVDIR/ . /app/$SRVDIR/
RUN cd $SRVDIR && cargo +nightly build --release --target-dir /build
FROM debian:buster-slim
WORKDIR /app
ARG SRVDIR=red-server
RUN apt-get update \
&& apt-get install -y libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Add diesel from database maintenance
COPY --from=builder /usr/local/cargo/bin/diesel /bin/
COPY --from=builder /app/$SRVDIR/Cargo.toml /app/$SRVDIR/diesel.toml /app/
COPY --from=builder /app/$SRVDIR/migrations /app/migrations
# Server itself
COPY --from=builder /build/release/red-server /app/
EXPOSE 8000
CMD ["./red-server"]