51 lines
1.5 KiB
Docker
51 lines
1.5 KiB
Docker
FROM rust:slim AS 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
|
|
|
|
WORKDIR /app
|
|
|
|
# 1. Kopioi vain Cargo-tiedostot → riippuvuudet cacheen
|
|
COPY Cargo.toml ./
|
|
COPY Cargo.lock* ./
|
|
COPY hub/Cargo.toml hub/Cargo.toml
|
|
COPY node/Cargo.toml node/Cargo.toml
|
|
COPY native-node/Cargo.toml native-node/Cargo.toml
|
|
|
|
# Tyhjät lähteet riippuvuuksien esikääntämistä varten
|
|
RUN mkdir -p hub/src node/src native-node/src \
|
|
&& echo "fn main(){}" > hub/src/main.rs \
|
|
&& echo "" > node/src/lib.rs \
|
|
&& mkdir -p node/src && touch node/src/storage.rs \
|
|
&& echo "fn main(){}" > native-node/src/main.rs \
|
|
&& cargo build --release -p hub 2>/dev/null || true \
|
|
&& wasm-pack build node --target web --out-dir ../static/pkg 2>/dev/null || true
|
|
|
|
# 2. Kopioi oikea lähdekoodi → vain src käännetään uudelleen
|
|
COPY hub/src hub/src
|
|
COPY node/src node/src
|
|
COPY static static
|
|
|
|
# Pakota uudelleenkäännös
|
|
RUN touch hub/src/main.rs node/src/lib.rs
|
|
|
|
# Rakenna Wasm-paketti
|
|
RUN cd node && wasm-pack build --target web --out-dir ../static/pkg
|
|
|
|
# Rakenna Hub release-binääri
|
|
RUN cargo build --release -p hub
|
|
|
|
FROM debian:bookworm-slim
|
|
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY --from=builder /app/target/release/hub /usr/local/bin/hub
|
|
COPY --from=builder /app/static /app/static
|
|
|
|
WORKDIR /app
|
|
ENV STATIC_DIR=/app/static
|
|
EXPOSE 3000
|
|
CMD ["hub"]
|