-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
68 lines (53 loc) · 2.13 KB
/
Dockerfile
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
# This file modified from
# https://github.com/fly-apps/hello-rust/blob/70afce57cfd27e636c849860f0a4f7be76127049/Dockerfile
FROM rust:latest as builder
# Make a fake Rust app to keep a cached layer of compiled crates
RUN USER=root cargo new app
WORKDIR /usr/src/app
COPY Cargo.toml Cargo.lock ./
RUN mkdir frontend server common
COPY frontend/Cargo.toml frontend/
COPY server/Cargo.toml server/
COPY common/Cargo.toml common/
# Needs at least a main.rs file with a main function
RUN mkdir frontend/src && echo "fn main(){}" > frontend/src/main.rs
RUN mkdir server/src && echo "fn main(){}" > server/src/main.rs
RUN mkdir common/src && echo "fn main(){}" > common/src/main.rs
# Will build all dependent crates in release mode
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/src/app/target \
cargo build --release
# Will install the tools needed to build the webapp
RUN rustup target add wasm32-unknown-unknown
RUN cargo install --locked trunk
RUN cargo install -f --git "https://github.com/rustwasm/wasm-bindgen.git" --rev "e47dda5" wasm-bindgen-cli
# Copy the rest.
COPY . .
# Build (install) the actual binaries
RUN RUSTFLAGS=--cfg=web_sys_unstable_apis ./scripts/prodbuild.sh
# Runtime image
FROM debian:bullseye-slim
# Need certs for talking to Google Cloud, and python3 for doing article extraction
RUN \
apt-get update && \
apt-get install -y ca-certificates python3-pip && \
apt-get clean
# Run as "app" user
RUN useradd -ms /bin/bash app
USER app
WORKDIR /app
# The binary and the blobs dir need to be in server/
RUN mkdir server
RUN mkdir server/audio_blobs
# Install trafilatura
RUN pip3 install trafilatura -t python_deps
# Get compiled binaries and assets from the builder's cargo install directory
COPY --from=builder /usr/src/app/dist /app/dist
COPY --from=builder /usr/src/app/server/audio_blobs /app/server/audio_blobs
COPY --from=builder /usr/local/cargo/bin/readtomyshoe-server /app/server/readtomyshoe-server
# Copy the API key
# NOTE: This is a secret value!
COPY ./server/gcp_api.key ./server/
# Go to where the binary is
WORKDIR /app/server
CMD ./readtomyshoe-server --port 9382 --addr 0.0.0.0