-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (69 loc) · 2.86 KB
/
Dockerfile
File metadata and controls
87 lines (69 loc) · 2.86 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
85
86
87
##################
# Rust image #
##################
FROM rust:latest AS rust
WORKDIR /usr/src/qcext-server
# Run SQLX in offline mode
ENV SQLX_OFFLINE=true
# Build the dependencies in a separate step to avoid rebuilding all of them
# every time the source code changes. This takes advantage of Docker's layer
# caching, and it works by doing a build using the Cargo.{toml,lock} files with
# dummy source code.
COPY Cargo.lock Cargo.toml /usr/src/qcext-server/
RUN mkdir -p /usr/src/qcext-server/database
COPY database/Cargo.toml database/sqlx-data.json /usr/src/qcext-server/database/
RUN mkdir -p /usr/src/qcext-server/shared
COPY shared/Cargo.toml /usr/src/qcext-server/shared/
RUN mkdir -p /usr/src/qcext-server/src && \
echo "fn main() {}" > /usr/src/qcext-server/src/main.rs
RUN mkdir -p /usr/src/qcext-server/database/src && \
touch /usr/src/qcext-server/database/src/lib.rs
RUN mkdir -p /usr/src/qcext-server/shared/src && \
touch /usr/src/qcext-server/shared/src/lib.rs
RUN cargo fetch
RUN cargo build --release
# Dependencies are now cached, copy the actual source code and do another full
# build. The touch on all the .rs files is needed, otherwise cargo assumes the
# source code didn't change thanks to mtime weirdness.
RUN rm -rf /usr/src/qcext-server/src /usr/src/qcext-server/database/src /usr/src/qcext-server/shared/src
COPY src /usr/src/qcext-server/src
RUN rm -rf /usr/src/qcext-server/src/client
COPY database/src /usr/src/qcext-server/database/src
COPY shared/src /usr/src/qcext-server/shared/src
RUN find src -name "*.rs" -exec touch {} \; && \
find database/src -name "*.rs" -exec touch {} \; && \
find shared/src -name "*.rs" -exec touch {} \; && \
cargo build --release
##################
# NodeJS image #
##################
FROM debian:bullseye AS nodejs
WORKDIR /usr/src/qcext-server
# Make sure we have npm and nodejs
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
RUN node --version
RUN npm --version
# 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 browserslist@latest --update-db
COPY public /usr/src/qcext-server/public
RUN npm run build
##################
# Output image #
##################
FROM debian:bullseye-slim AS binary
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates rsync
RUN apt-get clean
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"]