diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5846e21 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# Rust +target/ +Cargo.lock +*.rlib +*.rmeta + +# Node/npm +node_modules/ +package-lock.json +npm-debug.log + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ +.DS_Store + +# Git +.git/ +.gitignore + +# General +*.log +.env +.env.local diff --git a/.env b/.env new file mode 100644 index 0000000..587ab99 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +RUST_LOG=info +LEPTOS_SITE_ADDR=0.0.0.0:8080 +LEPTOS_SITE_ROOT=site diff --git a/Cargo.toml b/Cargo.toml index 9a16b39..9a94fbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,34 +8,28 @@ authors = ["Kristofers Solo "] edition = "2024" [workspace.dependencies] +aes = { path = "aes" } +cipher-core = { path = "cipher-core" } +cipher-factory = { path = "cipher-factory" } claims = "0.8" +clap = { version = "4.5", features = ["derive"] } color-eyre = "0.6" +des = { path = "des" } rand = "0.9" rstest = "0.26" strum = "0.27" thiserror = "2" - -[workspace.dependencies.aes] -path = "aes" - -[workspace.dependencies.cipher-core] -path = "cipher-core" - -[workspace.dependencies.cipher-factory] -path = "cipher-factory" - -[workspace.dependencies.clap] -version = "4.5" -features = ["derive"] - -[workspace.dependencies.des] -path = "des" - -[workspace.dependencies.zeroize] -version = "1.8" -features = ["derive"] +zeroize = { version = "1.8", features = ["derive"] } [workspace.lints.clippy] nursery = "warn" pedantic = "warn" unwarp_used = "warn" + +# Defines a size-optimized profile for the WASM bundle in release mode +[profile.wasm-release] +inherits = "release" +opt-level = 'z' +lto = true +codegen-units = 1 +panic = "abort" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c96f936 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef +WORKDIR /app +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM rustlang/rust:nightly-bookworm AS cacher + +RUN curl -LO https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz +RUN tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz +RUN cp cargo-binstall /usr/local/cargo/bin +RUN cargo binstall cargo-leptos cargo-chef -y +RUN apt-get update -y && apt-get install -y --no-install-recommends clang +RUN rustup target add wasm32-unknown-unknown + +WORKDIR /app +COPY --from=chef /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json + +FROM rustlang/rust:nightly-bookworm AS builder + +RUN wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz +RUN tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz +RUN cp cargo-binstall /usr/local/cargo/bin +RUN cargo binstall cargo-leptos -y +RUN apt-get update -y && apt-get install -y --no-install-recommends clang +RUN rustup target add wasm32-unknown-unknown + +WORKDIR /app +COPY --from=cacher /app/target target +COPY . . +RUN cargo leptos build --release -vv + +FROM debian:bookworm-slim AS runtime + +WORKDIR /app +RUN apt-get update -y \ + && apt-get install -y --no-install-recommends openssl ca-certificates \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /app/target/release/web /app/ +COPY --from=builder /app/target/site /app/site +COPY --from=builder /app/Cargo.toml /app/ + +EXPOSE 8080 + +CMD ["/app/web"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..06773e3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + web: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + env_file: .env + restart: unless-stopped