-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (67 loc) · 2.31 KB
/
Dockerfile
File metadata and controls
84 lines (67 loc) · 2.31 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
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
#######################
# Build Server and WASM
FROM rust:1.70 AS server_and_wasm
WORKDIR /usr/src
# Install a few base tools first so they're cached
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/target \
cargo install sqlx-cli
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build a sqlite DB so the sqlx macros have something to look at
ENV DATABASE_URL="sqlite:///usr/src/db.sqlite"
COPY migrations ./migrations
RUN sqlx database create && sqlx migrate run
# Copy all of our source files
COPY Cargo.toml Cargo.lock ./
COPY lib ./lib
COPY lib_wasm ./lib_wasm
COPY server ./server
# Build the server/wasm targets
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/target \
cargo install --locked --path ./server
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/target \
wasm-pack build --target web lib_wasm --profile release
#######################
# Build Svelte frontend
FROM node:18 AS frontend
WORKDIR /usr/src
RUN npm install -g pnpm@8.6.3
COPY --from=server_and_wasm /usr/src/lib_wasm/pkg ./lib_wasm/pkg
COPY pnpm-*.yaml ./
COPY ui ./ui
WORKDIR /usr/src/ui
RUN --mount=type=cache,target=/usr/src/ui/node_modules \
--mount=type=cache,target=/usr/src/ui/.svelte-kit \
--mount=type=cache,target=/usr/src/node_modules/.pnpm \
--mount=type=cache,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile && \
pnpm build
######################
# Build final container
FROM ubuntu:latest AS app
RUN apt update -y && apt install ca-certificates -y && apt clean -y
WORKDIR /app
COPY --from=litestream/litestream:0.3.7 /usr/local/bin/litestream /app/litestream
# Copy server binary
COPY --from=server_and_wasm /usr/local/cargo/bin/podreplay ./
# Copy the transpiled frontend
COPY --from=frontend /usr/src/ui/build ./ui
COPY litestream.yml /etc/
# or "yes"
ENV CREATE_LOCAL_DB="no"
COPY <<EOF run.sh
#!/usr/bin/env bash
set -euxo pipefail
if [ "\$CREATE_LOCAL_DB" = "yes" ]; then
echo "Using local DB"
CREATE_LOCAL_DB=yes ./podreplay
else
echo "Restoring DB from backup"
./litestream restore -v -if-db-not-exists db.sqlite && \
./litestream replicate -exec "./podreplay"
fi
EOF
RUN chmod +x run.sh
CMD ["./run.sh"]