57 lines
1.9 KiB
Docker

FROM docker.io/library/rust:1-alpine AS chef
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static git pkgconf
RUN cargo install cargo-chef
RUN cargo install trunk
RUN rustup target add wasm32-unknown-unknown
WORKDIR /app
FROM chef AS builder-peazyrsa
RUN cargo install --git https://gitea.b4tman.ru/b4tman/peazyrsa --tag v0.1.0
FROM chef AS planner-peasyweb
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder-peasyweb-backend
COPY --from=planner-peasyweb /app/recipe.json recipe.json
RUN cargo chef cook --release -p peazyweb-backend --recipe-path recipe.json
COPY Cargo.toml Cargo.lock ./
COPY backend/ ./backend/
RUN cargo build -p peazyweb-backend --release
FROM chef AS builder-peasyweb-frontend
ENV API_BASE_URL="/api/v1"
COPY Cargo.toml Cargo.lock ./
COPY frontend/ ./frontend/
RUN mkdir ./backend && echo "[package]" > ./backend/Cargo.toml && \
echo name = "\"peazyweb-backend\"" >> ./backend/Cargo.toml && \
mkdir ./backend/src && echo "pub fn main() {}" > ./backend/src/main.rs
WORKDIR /app/frontend
RUN trunk build --release --public-url "/frontend"
WORKDIR /app
FROM docker.io/library/alpine:3.21 AS runtime
RUN apk add --no-cache openssl libssl3 libcrypto3
RUN mkdir -p /app/frontend
RUN mkdir /data
WORKDIR /app
COPY --from=builder-peazyrsa /usr/local/cargo/bin/peazyrsa /usr/local/bin/peazyrsa
COPY --from=builder-peasyweb-backend /app/target/release/peazyweb-backend /usr/local/bin/peazyweb-backend
COPY --from=builder-peasyweb-frontend /app/frontend/dist/ /app/frontend
VOLUME [ "/data" ]
ENV GENERATION_BASE_DIRECTORY="/data"
ENV GENERATION_BIN="/usr/local/bin/peazyrsa"
ENV USE_OPENSSL="yes"
ENV OPENSSL_BIN="/usr/bin/openssl"
ENV FRONTEND_BASE="/app/frontend"
ENV ROCKET_ADDRESS="0.0.0.0"
ENV ROCKET_PORT=80
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/peazyweb-backend"]