74 lines
1.8 KiB
Docker
74 lines
1.8 KiB
Docker
##################
|
|
### BASE STAGE ###
|
|
##################
|
|
FROM rust:1.72.1 as base
|
|
|
|
# Install build dependencies
|
|
RUN cargo install --locked cargo-make trunk strip_cargo_version
|
|
RUN rustup target add wasm32-unknown-unknown
|
|
RUN rustup target add x86_64-unknown-linux-musl
|
|
|
|
# required by "ring"
|
|
RUN apt-get update && apt-get install -y musl-tools
|
|
|
|
WORKDIR /app
|
|
RUN mkdir frontend backend common
|
|
|
|
###########################
|
|
### STRIP-VERSION STAGE ###
|
|
###########################
|
|
FROM base AS strip-version
|
|
|
|
COPY Cargo.lock Cargo.toml ./
|
|
COPY frontend/Cargo.toml ./frontend/
|
|
COPY backend/Cargo.toml ./backend/
|
|
COPY common/Cargo.toml ./common/
|
|
RUN strip_cargo_version
|
|
|
|
###################
|
|
### BUILD STAGE ###
|
|
###################
|
|
FROM base AS build
|
|
|
|
RUN cargo init --lib frontend
|
|
RUN cargo init --bin backend
|
|
RUN cargo init --lib common
|
|
|
|
COPY --from=strip-version /app/frontend/Cargo.toml /app/frontend/
|
|
COPY --from=strip-version /app/backend/Cargo.toml /app/backend/
|
|
COPY --from=strip-version /app/common/Cargo.toml /app/common/
|
|
COPY --from=strip-version /app/Cargo.toml /app/Cargo.lock /app/
|
|
|
|
WORKDIR /app/backend
|
|
RUN cargo build --release --target x86_64-unknown-linux-musl
|
|
|
|
WORKDIR /app/frontend
|
|
RUN cargo build --release --target wasm32-unknown-unknown
|
|
|
|
WORKDIR /app
|
|
COPY . .
|
|
|
|
WORKDIR /app/backend
|
|
RUN cargo build --release --target x86_64-unknown-linux-musl
|
|
RUN strip /app/target/x86_64-unknown-linux-musl/release/hemma
|
|
|
|
WORKDIR /app/frontend
|
|
RUN trunk build --release
|
|
|
|
########################
|
|
### PRODUCTION STAGE ###
|
|
########################
|
|
FROM scratch
|
|
|
|
ENV RUST_LOG="info"
|
|
|
|
WORKDIR /
|
|
|
|
# Copy application binary
|
|
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/hemma /
|
|
|
|
# Copy static web files
|
|
COPY --from=build /app/frontend/dist /www
|
|
|
|
CMD ["/hemma", "--bind", "0.0.0.0:8000", "--frontend", "/www/"]
|