-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (56 loc) · 2.1 KB
/
Dockerfile
File metadata and controls
75 lines (56 loc) · 2.1 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
##################
# Rust image #
##################
FROM rust:1-bookworm AS chef
WORKDIR /usr/src/qcext-server
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall cargo-chef
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS rust
# Run SQLX in offline mode
ENV SQLX_OFFLINE=true
# Build dependencies - this is the caching Docker layer!
COPY --from=planner /usr/src/qcext-server/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# Dependencies are now cached, build for real.
COPY . .
RUN cargo build --release
##################
# NodeJS image #
##################
FROM debian:bookworm AS nodejs
WORKDIR /usr/src/qcext-server
# Download and import the Nodesource GPG key
RUN apt-get update && \
apt-get install -y ca-certificates curl gnupg && \
apt-get clean
RUN mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | \
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
# Make sure we have npm and nodejs
ENV NODE_MAJOR=18
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install nodejs -y && \
apt-get clean
# Next, let's run npm install
COPY package.json package-lock.json /usr/src/qcext-server/
RUN npm install
# Copy only files relevant for Node (i.e. no Rust files)
RUN mkdir /usr/src/qcext-server/src
COPY src/client /usr/src/qcext-server/src/client
COPY src/index.js /usr/src/qcext-server/src
RUN npx update-browserslist-db@latest
COPY public /usr/src/qcext-server/public
RUN npm run build
##################
# Output image #
##################
FROM gcr.io/distroless/cc-debian12
COPY --from=rust /usr/src/qcext-server/target/release/qcext-server /usr/local/bin/
COPY --from=nodejs /usr/src/qcext-server/build /build
ENV RUST_LOG=info
CMD ["/usr/local/bin/qcext-server"]