-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
78 lines (56 loc) · 1.89 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
69
70
71
72
73
74
75
76
77
78
#################
# Build
#################
## Node
FROM node:18-alpine3.18 AS frontend
RUN npm install -g pnpm
WORKDIR /app
COPY ./frontend/package.json ./frontend/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY ./frontend .
RUN pnpm build
## Rust
# Start with a rust alpine image
FROM rust:1.78.0-alpine3.18 AS build
# This is important, see https://github.com/rust-lang/docker-rust/issues/85
ENV RUSTFLAGS="-C target-feature=-crt-static"
# avoid checking the queries
ENV SQLX_OFFLINE=true
# install the build dependencies
RUN apk add --no-cache musl-dev pkgconfig openssl-dev
# set the workdir
WORKDIR /app
# do a release build
# make sure to use cache to avoid unnecessary rebuild
# use a bind mount to avoid copying the whole source into the container
RUN --mount=type=bind,source=crates,target=crates \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
--mount=type=cache,target=/usr/local/cargo/git/ \
cargo build --locked --release --package server && \
cp ./target/release/server /bin/server
#################
# Runtime
################
# use a plain alpine image for runtime
# the alpine version needs to match the builder
FROM alpine:3.18
# set assets path
ENV ASSETS_PATH="/assets/"
# set data path
ENV DATA_PATH="/app/data"
# Create a volume for persistent data storage
VOLUME /app/data
# install the runtime dependencies
RUN apk add --no-cache libgcc
# copy the binary from the build stage
COPY --from=build /bin/server /bin/
# copy frontend assets
COPY --from=frontend /app/build /assets
# set the entrypoint
ENTRYPOINT ["/bin/server"]
# Document that the container listens on port 3000
# Note: This doesn't actually publish the port. Use -p flag with docker run or ports in docker-compose.yml
EXPOSE 3000