Skip to content

Commit 077d675

Browse files
committed
Prepare for moving off Heroku
Switching to Docker-based build and run
1 parent 0aeb7f0 commit 077d675

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121
},
2222
"scripts": {
2323
"start": "react-scripts start",
24-
"build": "react-scripts build"
24+
"build": "react-scripts build",
25+
"docker:build": "docker build -t qcext-server ."
2526
},
2627
"proxy": {
2728
"/api": {
2829
"target": "http://localhost:5000"
2930
}
30-
},
31-
"heroku-run-build-script": true,
32-
"engines": {
33-
"node": "12.x",
34-
"npm": "6.x"
3531
}
3632
}

0 commit comments

Comments
 (0)