1- FROM rust:latest AS build
1+ # #################
2+ # Rust image #
3+ # #################
4+
5+ FROM rust:latest AS rust
26
37WORKDIR /usr/src/qcext-server
48
59# Run SQLX in offline mode
610ENV SQLX_OFFLINE=true
711
8- # Make sure we have npm and nodejs
9- RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
10- nodejs npm
11- RUN nodejs --version
12- RUN npm --version
13-
1412# Build the dependencies in a separate step to avoid rebuilding all of them
1513# every time the source code changes. This takes advantage of Docker's layer
1614# caching, and it works by doing a build using the Cargo.{toml,lock} files with
@@ -29,22 +27,46 @@ RUN mkdir -p /usr/src/qcext-server/shared/src && \
2927RUN cargo fetch
3028RUN cargo build --release
3129
32- # Next, let's run npm install
33- COPY package.json .npmrc /usr/src/qcext-server/
34- RUN npm install
35-
3630# Dependencies are now cached, copy the actual source code and do another full
3731# build. The touch on all the .rs files is needed, otherwise cargo assumes the
3832# source code didn't change thanks to mtime weirdness.
3933RUN rm -rf /usr/src/qcext-server/src /usr/src/qcext-server/database/src /usr/src/qcext-server/shared/src
4034COPY src /usr/src/qcext-server/src
35+ RUN rm -rf /usr/src/qcext-server/src/client
4136COPY database/src /usr/src/qcext-server/database/src
4237COPY shared/src /usr/src/qcext-server/shared/src
4338RUN find src -name "*.rs" -exec touch {} \; && \
4439 find database/src -name "*.rs" -exec touch {} \; && \
4540 find shared/src -name "*.rs" -exec touch {} \; && \
4641 cargo build --release
4742
43+ # #################
44+ # NodeJS image #
45+ # #################
46+
47+ FROM debian:bullseye AS nodejs
48+
49+ WORKDIR /usr/src/qcext-server
50+
51+ # Make sure we have npm and nodejs
52+ RUN apt-get update
53+ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y curl
54+ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
55+ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
56+ RUN node --version
57+ RUN npm --version
58+
59+ # Next, let's run npm install
60+ COPY package.json package-lock.json /usr/src/qcext-server/
61+ RUN npm install
62+
63+ # Copy only files relevant for Node (i.e. no Rust files)
64+ RUN mkdir /usr/src/qcext-server/src
65+ COPY src/client /usr/src/qcext-server/src/client
66+ COPY src/index.js /usr/src/qcext-server/src
67+
68+ RUN npx browserslist@latest --update-db
69+
4870COPY public /usr/src/qcext-server/public
4971RUN npm run build
5072
@@ -55,11 +77,11 @@ RUN npm run build
5577FROM debian:bullseye-slim AS binary
5678
5779RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
58- ca-certificates
80+ ca-certificates rsync
5981RUN apt-get clean
6082
61- COPY --from=build /usr/src/qcext-server/target/release/qcext-server /usr/local/bin/
62- COPY --from=build /usr/src/qcext-server/build /build
83+ COPY --from=rust /usr/src/qcext-server/target/release/qcext-server /usr/local/bin/
84+ COPY --from=nodejs /usr/src/qcext-server/build /build
6385
6486ENV RUST_LOG=info
6587CMD ["/usr/local/bin/qcext-server" ]
0 commit comments