From 7a55e0defdedf897759c7dc5469f15f2995a61ed Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Tue, 26 Aug 2025 17:33:42 +0100 Subject: [PATCH] build(docker): finalize dockerization * Fix broken build process * Remove unneeded separate install phase * Include dockerignore * Actually build the website in the image separately thank you @lukadev-0 for help :D --- .dockerignore | 4 ++++ Dockerfile | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..48daf3a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +Dockerfile +target/ +node_modules/ +/www/build diff --git a/Dockerfile b/Dockerfile index 45ce501..0a97b76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,39 @@ -FROM rust:1.87-alpine3.21 AS base +FROM oven/bun:1.2-alpine AS www +WORKDIR /usr/src/www +COPY www/package.json www/bun.lock . +RUN bun install +COPY www . +RUN bun run build + +FROM rust:1.87-alpine3.21 AS builder +RUN apk add --no-cache \ + build-base \ + git \ + pkgconfig \ + openssl-dev \ + openssl-libs-static \ + zlib-dev \ + zlib-static +RUN cargo install patch-crate --locked ARG CARGO_FEATURES="blog" -FROM base AS install -WORKDIR /temp/dev -COPY patches/ rust-toolchain Cargo.toml Cargo.lock . -RUN cargo install patch-crate --locked && cargo patch-crate -RUN mkdir src && touch src/lib.rs -RUN mkdir .cargo && cargo vendor --locked >> .cargo/config.toml - -FROM base AS builder WORKDIR /usr/src/app -COPY --from=install /temp/dev/vendor /temp/dev/.cargo . +COPY rust-toolchain Cargo.toml Cargo.lock . +COPY patches patches +RUN mkdir src \ + && touch src/lib.rs \ + && echo "fn main() {}" > build.rs \ + && cargo patch-crate \ + && cargo build --locked --release --no-default-features --features $CARGO_FEATURES + COPY . . -RUN cargo build --release --no-default-features --features $CARGO_FEATURES +COPY --from=www /usr/src/www/build www/build +RUN touch build.rs \ + && SKIP_PATCH_CRATE=1 cargo build --locked --release --no-default-features --features $CARGO_FEATURES FROM scratch AS runner -USER runner EXPOSE 80/tcp 22/tcp COPY --from=builder /usr/src/app/target/release/ssh-portfolio /usr/local/bin/ssh-portfolio -CMD ["/usr/local/bin/ssh-portfolio"] +CMD ["/usr/local/bin/ssh-portfolio", "--host", "0.0.0.0"]