summary refs log tree commit diff
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2025-03-21 23:15:01 -0600
committerAshelyn Rose <git@ashen.earth>2025-03-21 23:15:01 -0600
commitb18f08e8899b5a98dd3e1f8439ad812951a04cd9 (patch)
tree613dac28974eee66b193f48402c3ecb9b0663c88
parent2683366e92676abf687c37f4afea4d4d721cb059 (diff)
Container
-rw-r--r--.dockerignore2
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml6
-rw-r--r--docker/app.Dockerfile32
-rw-r--r--docker/builder.Dockerfile14
-rw-r--r--rust-toolchain.toml2
-rw-r--r--src/main.rs28
7 files changed, 89 insertions, 5 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..71f6a79
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,2 @@
+target/
+docker/
diff --git a/Cargo.lock b/Cargo.lock
index bc4c6ea..ed903de 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1793,6 +1793,15 @@ dependencies = [
 ]
 
 [[package]]
+name = "signal-hook-registry"
+version = "1.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
+dependencies = [
+ "libc",
+]
+
+[[package]]
 name = "slab"
 version = "0.4.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1996,6 +2005,7 @@ dependencies = [
  "libc",
  "mio",
  "pin-project-lite",
+ "signal-hook-registry",
  "socket2",
  "tokio-macros",
  "windows-sys 0.52.0",
diff --git a/Cargo.toml b/Cargo.toml
index 2fa7fd9..df8d2a2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,13 +7,13 @@ edition = "2021"
 crate-type = ["cdylib", "rlib"]
 
 [dependencies]
-leptos = { version = "0.7.0", features = ["nightly", "islands"] }
-leptos_router = { version = "0.7.0", features = ["nightly"] }
+leptos = { version = "0.7.0", features = ["islands"] }
+leptos_router = { version = "0.7.0" }
 axum = { version = "0.7", optional = true }
 console_error_panic_hook = { version = "0.1", optional = true}
 leptos_axum = { version = "0.7.0", optional = true }
 leptos_meta = { version = "0.7.0" }
-tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
+tokio = { version = "1", features = ["rt-multi-thread", "signal"], optional = true }
 wasm-bindgen = { version = "=0.2.100", optional = true }
 
 [features]
diff --git a/docker/app.Dockerfile b/docker/app.Dockerfile
new file mode 100644
index 0000000..66c2fe4
--- /dev/null
+++ b/docker/app.Dockerfile
@@ -0,0 +1,32 @@
+FROM leptos-builder-musl AS builder
+
+WORKDIR /build
+COPY . .
+
+# needs to exist for clippy
+RUN mkdir -p target/stormscribe
+RUN cargo clippy -- -D warnings
+
+# RUN cargo leptos test
+RUN cargo leptos build --release
+
+
+# --------- #
+
+
+FROM scratch AS app
+
+ENV LEPTOS_OUTPUT_NAME=stormscribe
+ENV LEPTOS_SITE_ROOT=files
+ENV LEPTOS_SITE_PKG_DIR=pkg
+ENV LEPTOS_SITE_ADDR="0.0.0.0:3000"
+ENV LEPTOS_RELOAD_PORT=3001
+
+USER 10001
+WORKDIR /app
+COPY --chown=10001:10001 --from=builder /build/target/stormscribe/ ./files/
+COPY --chown=10001:10001 --from=builder /build/target/release/stormscribe .
+EXPOSE 3000
+
+ENTRYPOINT ["/app/stormscribe"]
+
diff --git a/docker/builder.Dockerfile b/docker/builder.Dockerfile
new file mode 100644
index 0000000..1df5c3e
--- /dev/null
+++ b/docker/builder.Dockerfile
@@ -0,0 +1,14 @@
+FROM rust:1.85-alpine3.20
+
+RUN apk update && \
+    apk add --no-cache bash binaryen gcc git g++ libc-dev make npm openssl-dev openssl-libs-static zlib-static zlib-dev protobuf-dev protoc perl
+
+RUN rustup target add wasm32-unknown-unknown
+RUN rustup component add clippy
+
+RUN cargo install cargo-generate
+RUN cargo install cargo-leptos
+
+WORKDIR /build
+
+CMD /bin/bash
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
deleted file mode 100644
index 5d56faf..0000000
--- a/rust-toolchain.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-[toolchain]
-channel = "nightly"
diff --git a/src/main.rs b/src/main.rs
index 51b2531..ea22824 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+use tokio::signal;
+
 #[cfg(feature = "ssr")]
 #[tokio::main]
 async fn main() {
@@ -26,10 +28,36 @@ async fn main() {
     log!("listening on http://{}", &addr);
     let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
     axum::serve(listener, app.into_make_service())
+        .with_graceful_shutdown(shutdown_signal())
         .await
         .unwrap();
 }
 
+#[cfg(feature = "ssr")]
+async fn shutdown_signal() {
+    let ctrl_c = async {
+        signal::ctrl_c()
+            .await
+            .expect("could not install SIGINT handler")
+    };
+
+    #[cfg(unix)]
+    let terminate = async {
+        signal::unix::signal(signal::unix::SignalKind::terminate())
+            .expect("could not install SIGTERM handler")
+            .recv()
+            .await;
+    };
+
+    #[cfg(not(unix))]
+    let terminate = std::future::pending::<()>();
+
+    tokio::select! {
+        _ = ctrl_c => {},
+        _ = terminate => {},
+    }
+}
+
 #[cfg(not(feature = "ssr"))]
 pub fn main() {
     // no client-side main function