-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
78 lines (55 loc) · 2.09 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
# Dockerfile for running Formicaio app
# We first just install tailwindcss from a nodejs slim image
FROM node:23.6.1-alpine AS tailwindcss-builder
WORKDIR /app
COPY package.json package-lock.json ./
# Install tailwindcss modules
RUN npm install tailwindcss
# Now let's use a build env with Rust for the app
FROM rust:1-alpine AS builder
RUN apk update && \
apk add --no-cache bash curl npm libc-dev binaryen
# Install cargo-binstall, which makes it easier to install other
# cargo extensions like cargo-leptos
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
# Install cargo-leptos
RUN cargo binstall [email protected] -y
# Add the WASM target
RUN rustup target add wasm32-unknown-unknown
WORKDIR /work
# Copy tailwindcss modules, and nodejs binary, to the /app directory
# since they are required for building the app
COPY --from=tailwindcss-builder /app/node_modules /work/node_modules
COPY --from=tailwindcss-builder /usr/local/bin/node /usr/local/bin/node
# Now we can copy the source files to build them
COPY . .
# Define build args argument
ARG BUILD_ARGS
ENV BUILD_ARGS=${BUILD_ARGS}
# Define build args argument
ARG BUILD_ARGS
ENV BUILD_ARGS=${BUILD_ARGS}
# Build the app
RUN cargo leptos build --release $BUILD_ARGS -vv
# Finally use an Alpine image to build the final runtime image
# which contains only the built app and required resource files.
FROM alpine AS runtime
WORKDIR /app
RUN apk update \
&& apk cache purge \
&& rm -rf /var/lib/apt/lists/*
# Copy the server binary to the /app directory
COPY --from=builder /work/target/release/formicaio /app/
# Copy Sqlite migrations files
COPY --from=builder /work/migrations /app/migrations
# /target/site contains our JS/WASM/CSS, etc.
COPY --from=builder /work/target/site /app/site
# Copy Cargo.toml if it’s needed at runtime
COPY --from=builder /work/Cargo.toml /app/
# Set any required env variables and
ENV RUST_LOG="info"
ENV LEPTOS_SITE_ADDR="0.0.0.0:52100"
ENV LEPTOS_SITE_ROOT="site"
EXPOSE 52100
# Run the server
CMD ["/app/formicaio"]