|
| 1 | +FROM rust:latest AS build |
| 2 | + |
| 3 | +WORKDIR /usr/src/qcext-server |
| 4 | + |
| 5 | +# Run SQLX in offline mode |
| 6 | +ENV SQLX_OFFLINE=true |
| 7 | + |
| 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 | + |
| 14 | +# Build the dependencies in a separate step to avoid rebuilding all of them |
| 15 | +# every time the source code changes. This takes advantage of Docker's layer |
| 16 | +# caching, and it works by doing a build using the Cargo.{toml,lock} files with |
| 17 | +# dummy source code. |
| 18 | +COPY Cargo.lock Cargo.toml /usr/src/qcext-server/ |
| 19 | +RUN mkdir -p /usr/src/qcext-server/database |
| 20 | +COPY database/Cargo.toml database/sqlx-data.json /usr/src/qcext-server/database/ |
| 21 | +RUN mkdir -p /usr/src/qcext-server/shared |
| 22 | +COPY shared/Cargo.toml /usr/src/qcext-server/shared/ |
| 23 | +RUN mkdir -p /usr/src/qcext-server/src && \ |
| 24 | + echo "fn main() {}" > /usr/src/qcext-server/src/main.rs |
| 25 | +RUN mkdir -p /usr/src/qcext-server/database/src && \ |
| 26 | + touch /usr/src/qcext-server/database/src/lib.rs |
| 27 | +RUN mkdir -p /usr/src/qcext-server/shared/src && \ |
| 28 | + touch /usr/src/qcext-server/shared/src/lib.rs |
| 29 | +RUN cargo fetch |
| 30 | +RUN cargo build --release |
| 31 | + |
| 32 | +# Next, let's run npm install |
| 33 | +COPY package.json .npmrc /usr/src/qcext-server/ |
| 34 | +RUN npm install |
| 35 | + |
| 36 | +# Dependencies are now cached, copy the actual source code and do another full |
| 37 | +# build. The touch on all the .rs files is needed, otherwise cargo assumes the |
| 38 | +# source code didn't change thanks to mtime weirdness. |
| 39 | +RUN rm -rf /usr/src/qcext-server/src /usr/src/qcext-server/database/src /usr/src/qcext-server/shared/src |
| 40 | +COPY src /usr/src/qcext-server/src |
| 41 | +COPY database/src /usr/src/qcext-server/database/src |
| 42 | +COPY shared/src /usr/src/qcext-server/shared/src |
| 43 | +RUN find src -name "*.rs" -exec touch {} \; && \ |
| 44 | + find database/src -name "*.rs" -exec touch {} \; && \ |
| 45 | + find shared/src -name "*.rs" -exec touch {} \; && \ |
| 46 | + cargo build --release |
| 47 | + |
| 48 | +COPY public /usr/src/qcext-server/public |
| 49 | +RUN npm run build |
| 50 | + |
| 51 | +################## |
| 52 | +# Output image # |
| 53 | +################## |
| 54 | + |
| 55 | +FROM debian:bullseye-slim AS binary |
| 56 | + |
| 57 | +# RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ |
| 58 | +# libpq-dev \ |
| 59 | +# ca-certificates |
| 60 | + |
| 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 |
| 63 | + |
| 64 | +ENV RUST_LOG=info |
| 65 | +CMD qcext-server |
0 commit comments