-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
88 lines (67 loc) · 2.05 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
##################
### BASE STAGE ###
##################
FROM rust:1.83.0 as base
# Install build dependencies
RUN rustup target add wasm32-unknown-unknown
RUN rustup target add x86_64-unknown-linux-musl
RUN cargo install --locked --version 0.0.3 strip_cargo_version
RUN cargo install --locked --version 0.18.7 trunk
RUN apt-get update &&\
apt-get install -y musl-tools &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN mkdir frontend backend lib
###########################
### STRIP-VERSION STAGE ###
###########################
FROM base AS strip-version
# Generate workspace manifest without ultrascroper
RUN tee Cargo.toml <<EOF
[workspace]
members = ["backend", "frontend", "lib"]
resolver = "2"
EOF
COPY Cargo.lock ./
COPY frontend/Cargo.toml ./frontend/
COPY backend/Cargo.toml ./backend/
COPY lib/Cargo.toml ./lib/
RUN strip_cargo_version
###################
### BUILD STAGE ###
###################
FROM base AS build
RUN cargo init --lib frontend
RUN cargo init --bin backend
RUN cargo init --lib lib
COPY --from=strip-version /app/frontend/Cargo.toml /app/frontend/
COPY --from=strip-version /app/backend/Cargo.toml /app/backend/
COPY --from=strip-version /app/lib/Cargo.toml /app/lib/
COPY --from=strip-version /app/Cargo.lock /app/
WORKDIR /app/backend
RUN cargo build --release --target x86_64-unknown-linux-musl
WORKDIR /app/frontend
RUN cargo build --release --target wasm32-unknown-unknown
WORKDIR /app
COPY . .
WORKDIR /app/backend
RUN cargo build --release --target x86_64-unknown-linux-musl
WORKDIR /app/frontend
RUN trunk build --release
########################
### PRODUCTION STAGE ###
########################
FROM scratch
# Default logging level
ENV RUST_LOG="info"
ENV COVERS_DIR="/covers"
VOLUME /covers
WORKDIR /
# Copy application binary
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/singit_srv /usr/local/bin/singit_srv
# Copy static web files
COPY --from=build /app/frontend/dist /dist
# Copy database migrations
COPY backend/migrations /migrations
ENTRYPOINT ["singit_srv"]