Dockerfile.prod päivitetty Astro-frontendille
Muutokset: - Vaihe 1: Node.js buildaa Astro-frontendin (frontend/dist/) - Vaihe 2: wasm-pack buildaa Wasm-moduulin erikseen - Vaihe 3: Hub rakennetaan Rustilla - Vaihe 4: Yhdistetään dist/ + pkg/ + avatars/ + templates/ + GUIDE.md STATIC_DIR=/app/frontend/dist (ei enää /app/static) Avatarit, templates ja GUIDE.md kopioidaan erikseen koska Astro ei kopioi public/-tiedostoja dist/:iin buildin yhteydessä. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,47 +1,57 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
FROM rust:slim AS builder
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
# --- Vaihe 1: Frontend (Astro) ---
|
||||||
curl pkg-config libssl-dev g++ \
|
FROM node:22-slim AS frontend
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
WORKDIR /app/frontend
|
||||||
|
COPY frontend/package.json frontend/package-lock.json* ./
|
||||||
|
RUN npm install --silent
|
||||||
|
COPY frontend/ .
|
||||||
|
COPY frontend/public/pkg public/pkg
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# --- Vaihe 2: Wasm (wasm-pack) ---
|
||||||
|
FROM rust:slim AS wasm-builder
|
||||||
|
RUN apt-get update && apt-get install -y curl pkg-config libssl-dev g++ && rm -rf /var/lib/apt/lists/*
|
||||||
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
COPY Cargo.toml Cargo.lock* ./
|
||||||
|
COPY node/Cargo.toml node/Cargo.toml
|
||||||
|
COPY node/src node/src
|
||||||
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
--mount=type=cache,target=/app/target \
|
||||||
|
cd node && wasm-pack build --target web --out-dir /app/wasm-pkg
|
||||||
|
|
||||||
# Kopioi kaikki Cargo-tiedostot
|
# --- Vaihe 3: Hub (Rust) ---
|
||||||
COPY Cargo.toml ./
|
FROM rust:slim AS hub-builder
|
||||||
COPY Cargo.lock* ./
|
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
|
||||||
|
WORKDIR /app
|
||||||
|
COPY Cargo.toml Cargo.lock* ./
|
||||||
COPY hub/Cargo.toml hub/Cargo.toml
|
COPY hub/Cargo.toml hub/Cargo.toml
|
||||||
|
COPY hub/src hub/src
|
||||||
|
# Tarvitaan dummy-cratet jotta workspace kompiloi
|
||||||
COPY node/Cargo.toml node/Cargo.toml
|
COPY node/Cargo.toml node/Cargo.toml
|
||||||
COPY native-node/Cargo.toml native-node/Cargo.toml
|
COPY native-node/Cargo.toml native-node/Cargo.toml
|
||||||
COPY cli/Cargo.toml cli/Cargo.toml
|
COPY cli/Cargo.toml cli/Cargo.toml
|
||||||
|
RUN mkdir -p node/src native-node/src cli/src && touch node/src/lib.rs native-node/src/main.rs cli/src/main.rs
|
||||||
# Kopioi lähdekoodi
|
|
||||||
COPY hub/src hub/src
|
|
||||||
COPY node/src node/src
|
|
||||||
COPY native-node/src native-node/src
|
|
||||||
COPY cli/src cli/src
|
|
||||||
COPY static static
|
|
||||||
|
|
||||||
# Rakenna Wasm — cache mount pitää Cargo-rekisterin ja target-kansion buildien välillä
|
|
||||||
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
|
||||||
--mount=type=cache,target=/app/target \
|
|
||||||
cd node && wasm-pack build --target web --out-dir ../static/pkg
|
|
||||||
|
|
||||||
# Rakenna Hub
|
|
||||||
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
--mount=type=cache,target=/app/target \
|
--mount=type=cache,target=/app/target \
|
||||||
cargo build --release -p hub \
|
cargo build --release -p hub \
|
||||||
&& cp /app/target/release/hub /usr/local/bin/hub
|
&& cp /app/target/release/hub /usr/local/bin/hub
|
||||||
|
|
||||||
|
# --- Vaihe 4: Tuotantoimage ---
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY --from=builder /usr/local/bin/hub /usr/local/bin/hub
|
COPY --from=hub-builder /usr/local/bin/hub /usr/local/bin/hub
|
||||||
COPY --from=builder /app/static /app/static
|
COPY --from=frontend /app/frontend/dist /app/frontend/dist
|
||||||
|
COPY --from=wasm-builder /app/wasm-pkg /app/frontend/dist/pkg
|
||||||
|
|
||||||
|
# Kopioidaan GUIDE.md ja templates
|
||||||
|
COPY frontend/public/GUIDE.md /app/frontend/dist/GUIDE.md
|
||||||
|
COPY frontend/public/templates /app/frontend/dist/templates
|
||||||
|
COPY frontend/public/avatars /app/frontend/dist/avatars
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV STATIC_DIR=/app/static
|
ENV STATIC_DIR=/app/frontend/dist
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["hub"]
|
CMD ["hub"]
|
||||||
|
|||||||
Reference in New Issue
Block a user