From 81b7bfb6fad9bd1d1e52eb1112ca114e536691f0 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 3 Nov 2025 17:44:26 -0800 Subject: [PATCH] Deploy --- .env_dist | 8 +++++ .gitignore | 1 + Dockerfile | 30 +++++++++++++++++++ docker-compose.yml | 12 ++++++++ rust/runner/src/lib.rs | 4 +-- .../src/{gamestate.rs => minmaxgame.rs} | 0 .../{gamestatehuman.rs => minmaxgamehuman.rs} | 6 ++-- webui/src/lib/saveConfig.ts | 8 ++--- webui/src/lib/worker_human.ts | 6 ++-- 9 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 .env_dist create mode 100644 Dockerfile create mode 100644 docker-compose.yml rename rust/runner/src/{gamestate.rs => minmaxgame.rs} (100%) rename rust/runner/src/{gamestatehuman.rs => minmaxgamehuman.rs} (98%) diff --git a/.env_dist b/.env_dist new file mode 100644 index 0000000..6cb3083 --- /dev/null +++ b/.env_dist @@ -0,0 +1,8 @@ +# Script saving configuration +ENABLE_SAVE=true +SAVE_SECRET=save +SAVE_DIRECTORY=./data/scripts +MAX_FILENAME_LENGTH=32 + +# Next.js environment +NODE_ENV=production \ No newline at end of file diff --git a/.gitignore b/.gitignore index e3a85a3..38ba468 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ target .DS_Store webui/src/wasm webui/data +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..30d69c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM rust:1.91 AS rust-builder + +WORKDIR /app +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + +COPY rust/ ./rust/ +WORKDIR /app/rust/rhai-codemirror +RUN wasm-pack build --target web --out-dir "../../webui/src/wasm/rhai-codemirror" + +WORKDIR /app/rust/runner +RUN wasm-pack build --target web --out-dir "../../webui/src/wasm/runner" + +FROM node:24-alpine AS app + +WORKDIR /app + +RUN npm install -g bun +COPY webui/package.json webui/bun.lock* ./webui/ + +WORKDIR /app/webui +RUN bun install --frozen-lockfile +COPY webui/ ./ +COPY --from=rust-builder /app/webui/src/wasm/ ./src/wasm/ + +RUN bun run build + +RUN mkdir -p ../data/scripts +EXPOSE 3000 + +CMD ["bun", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..849ba07 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' + +services: + webui: + build: . + ports: + - "3000:3000" + volumes: + - ./data:/app/data + env_file: + - .env + restart: unless-stopped diff --git a/rust/runner/src/lib.rs b/rust/runner/src/lib.rs index a052f19..70a6f7f 100644 --- a/rust/runner/src/lib.rs +++ b/rust/runner/src/lib.rs @@ -1,8 +1,8 @@ use wasm_bindgen::prelude::*; mod ansi; -mod gamestate; -mod gamestatehuman; +mod minmaxgame; +mod minmaxgamehuman; mod terminput; #[global_allocator] diff --git a/rust/runner/src/gamestate.rs b/rust/runner/src/minmaxgame.rs similarity index 100% rename from rust/runner/src/gamestate.rs rename to rust/runner/src/minmaxgame.rs diff --git a/rust/runner/src/gamestatehuman.rs b/rust/runner/src/minmaxgamehuman.rs similarity index 98% rename from rust/runner/src/gamestatehuman.rs rename to rust/runner/src/minmaxgamehuman.rs index 87097d2..094bfa9 100644 --- a/rust/runner/src/gamestatehuman.rs +++ b/rust/runner/src/minmaxgamehuman.rs @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::*; use crate::{ansi, terminput::TermInput}; #[wasm_bindgen] -pub struct GameStateHuman { +pub struct MinMaxGameHuman { /// Red player human: TermInput, @@ -26,7 +26,7 @@ pub struct GameStateHuman { } #[wasm_bindgen] -impl GameStateHuman { +impl MinMaxGameHuman { #[wasm_bindgen(constructor)] pub fn new( max_script: &str, @@ -34,7 +34,7 @@ impl GameStateHuman { max_debug_callback: js_sys::Function, game_state_callback: js_sys::Function, - ) -> Result { + ) -> Result { Self::new_native( max_script, move |s| { diff --git a/webui/src/lib/saveConfig.ts b/webui/src/lib/saveConfig.ts index c238e65..ac51840 100644 --- a/webui/src/lib/saveConfig.ts +++ b/webui/src/lib/saveConfig.ts @@ -1,8 +1,8 @@ export const SAVE_CONFIG = { - ENABLE_SAVE: true, - SAVE_SECRET: "save", + ENABLE_SAVE: process.env.ENABLE_SAVE === 'true' || true, + SAVE_SECRET: process.env.SAVE_SECRET || "save", - SAVE_DIRECTORY: "./data/scripts", - MAX_FILENAME_LENGTH: 32, + SAVE_DIRECTORY: process.env.SAVE_DIRECTORY || "./data/scripts", + MAX_FILENAME_LENGTH: parseInt(process.env.MAX_FILENAME_LENGTH || "32"), FILENAME_REGEX: /^[a-zA-Z0-9_\s-]+$/, } as const; diff --git a/webui/src/lib/worker_human.ts b/webui/src/lib/worker_human.ts index cb552ec..342637c 100644 --- a/webui/src/lib/worker_human.ts +++ b/webui/src/lib/worker_human.ts @@ -1,8 +1,8 @@ -import init, { GameState, GameStateHuman } from "../wasm/runner"; +import init, { MinMaxGameHuman } from "../wasm/runner"; let wasmReady = false; let wasmInitPromise: Promise | null = null; -let currentGame: GameStateHuman | null = null; +let currentGame: MinMaxGameHuman | null = null; async function initWasm(): Promise { if (wasmReady) return; @@ -53,7 +53,7 @@ self.onmessage = async (event) => { self.postMessage({ type: "terminal", line }); }; - currentGame = new GameStateHuman( + currentGame = new MinMaxGameHuman( event_data.script, appendOutput, appendOutput,