-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
43 lines (31 loc) · 1.59 KB
/
Dockerfile
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
43
FROM rust:1.81 as build-stage
WORKDIR /vaalikoppi
ARG DATABASE_URL
ARG DEBUG
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && apt-get install musl-tools -y
RUN rustup target add x86_64-unknown-linux-musl
RUN USER=root cargo new --bin vaalikoppi && \
cargo install [email protected] --locked --no-default-features --features native-tls,postgres && cargo install [email protected] --locked
COPY . .
RUN sqlx migrate run
RUN rsass src/static/scss/main.scss --style compressed > src/static/css/main.css
RUN \
--mount=type=cache,target=/usr/local/cargo/registry/index/,from=rust:1.81 \
--mount=type=cache,target=/usr/local/cargo/registry/cache/,from=rust:1.81 \
--mount=type=cache,target=/usr/local/cargo/git/db/,from=rust:1.81 \
--mount=type=cache,target=./target/,from=rust:1.81 \
if [ $DEBUG ]; then \
# Debug for faster build times for running e2e test
echo "Warning: building DEBUG build with performance inferior to release build"; \
cargo build --target x86_64-unknown-linux-musl && cp target/x86_64-unknown-linux-musl/debug/vaalikoppi output_binary; \
else \
# Release build for performance in prod
cargo build --release --target x86_64-unknown-linux-musl && cp target/x86_64-unknown-linux-musl/release/vaalikoppi output_binary; \
fi
FROM scratch
WORKDIR /vaalikoppi
COPY --from=build-stage /vaalikoppi/output_binary /vaalikoppi/output_binary
COPY --from=build-stage /vaalikoppi/src/static /vaalikoppi/src/static
ENTRYPOINT ["/vaalikoppi/output_binary"]