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
This commit is contained in:
Erica Marigold 2025-08-26 17:33:42 +01:00
parent 49941da089
commit 7a55e0defd
Signed by: DevComp
SSH key fingerprint: SHA256:jD3oMT4WL3WHPJQbrjC3l5feNCnkv7ndW8nYaHX5wFw
2 changed files with 33 additions and 13 deletions

4
.dockerignore Normal file
View file

@ -0,0 +1,4 @@
Dockerfile
target/
node_modules/
/www/build

View file

@ -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" 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 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 . . 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 FROM scratch AS runner
USER runner
EXPOSE 80/tcp 22/tcp EXPOSE 80/tcp 22/tcp
COPY --from=builder /usr/src/app/target/release/ssh-portfolio /usr/local/bin/ssh-portfolio 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"]