From 947d244326fe3ff1acfa5e899f4c42bcfa0ac724 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 13 Mar 2025 18:04:34 +0300 Subject: [PATCH 1/2] build(docker): dockerize compareware --- .dockerignore | 5 +++++ docker-compose.yml | 11 +++++++++++ dockerfile | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 .dockerignore create mode 100644 docker-compose.yml create mode 100644 dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4eaf472 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +target/ +**/*.rs.bk +node_modules/ +Dockerfile +docker-compose.yml \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..87d62e3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + app: + build: . + ports: + - "3000:3000" + volumes: + - ./compareware.db:/app/compareware.db + environment: + - RUST_LOG=info + - LEPTOS_ENV=production + restart: unless-stopped \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..357cc9b --- /dev/null +++ b/dockerfile @@ -0,0 +1,47 @@ +# Build stage +FROM rust:1.82-alpine AS builder + +# Install essential build tools +RUN apk add --no-cache \ + musl-dev \ + openssl-dev \ + openssl \ + curl \ + build-base \ + g++ \ + libc6-compat \ + pkgconfig + +# Install build dependencies +RUN apk add --no-cache musl-dev openssl-dev openssl + +# Install Rust toolchain +RUN rustup install stable +RUN rustup component add rust-src + +# Install cargo-leptos +RUN cargo install cargo-leptos --version 0.2.29 --locked + +WORKDIR /app +COPY . . + + +# Build project +ENV LEPTOS_OUTPUT_NAME="compareware" +RUN cargo leptos build --release + +# Runtime stage +FROM alpine:latest + +# Install runtime dependencies +RUN apk add --no-cache openssl + +WORKDIR /app +COPY --from=builder /app/target/release/compareware /app/compareware +COPY assets /app/assets + +# Expose port and set entrypoint +EXPOSE 3000 +ENV LEPTOS_SITE_ADDR=0.0.0.0:3000 +ENV LEPTOS_SITE_ROOT="site" +CMD ["/app/compareware"] \ No newline at end of file From f87f88db2daf523ded050ea7b950fb14ad3950ea Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 14 Mar 2025 17:35:12 +0300 Subject: [PATCH 2/2] build(docker): update Dockerfile to use Debian Bullseye and Rust 1.83.0. -switch from Alpine to Debian for runtime -add wasm-bindgen-cli -update cargo-leptos version --- dockerfile | 57 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/dockerfile b/dockerfile index 357cc9b..b61ad15 100644 --- a/dockerfile +++ b/dockerfile @@ -1,47 +1,56 @@ # Build stage -FROM rust:1.82-alpine AS builder +FROM rust:1.83.0-slim-bullseye as builder # Install essential build tools -RUN apk add --no-cache \ - musl-dev \ - openssl-dev \ - openssl \ +RUN apt-get update && \ + apt-get install -y \ + libsqlite3-dev \ + build-essential \ + clang \ + libssl-dev \ + pkg-config \ curl \ - build-base \ - g++ \ - libc6-compat \ - pkgconfig - -# Install build dependencies -RUN apk add --no-cache musl-dev openssl-dev openssl + cmake \ + protobuf-compiler \ + && rm -rf /var/lib/apt/lists/* # Install Rust toolchain -RUN rustup install stable RUN rustup component add rust-src -# Install cargo-leptos -RUN cargo install cargo-leptos --version 0.2.29 --locked +# Install cargo-leptos & wasm-bindgen-cli +RUN cargo install cargo-leptos --version 0.2.24 --locked +RUN cargo install wasm-bindgen-cli --version 0.2.99 --locked +# Build application WORKDIR /app COPY . . - - +# Explicitly set WASM target +RUN rustup target add wasm32-unknown-unknown # Build project ENV LEPTOS_OUTPUT_NAME="compareware" + +# Build with release profile RUN cargo leptos build --release # Runtime stage -FROM alpine:latest +FROM debian:bullseye-slim -# Install runtime dependencies -RUN apk add --no-cache openssl +# Install runtime dependencies in Debian +RUN apt-get update && \ + apt-get install -y \ + libssl-dev \ + libsqlite3-0 \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* -WORKDIR /app -COPY --from=builder /app/target/release/compareware /app/compareware +# Copy build artifacts +COPY --from=builder /app/target/release/compareware /app/ +COPY --from=builder /app/target/site /app/site COPY assets /app/assets -# Expose port and set entrypoint +# Configure container, expose port and set entrypoint +WORKDIR /app EXPOSE 3000 ENV LEPTOS_SITE_ADDR=0.0.0.0:3000 ENV LEPTOS_SITE_ROOT="site" -CMD ["/app/compareware"] \ No newline at end of file +CMD ["./compareware"] \ No newline at end of file