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..274e195 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# Stage 1: Build Rust WASM components +FROM rust:1.75 AS rust-builder + +WORKDIR /app + +# Install wasm-pack +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + +# Copy Rust source code +COPY rust/ ./rust/ + +# Build WASM components +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" + +# Stage 2: Build and run Next.js application +FROM node:18-alpine AS app + +WORKDIR /app + +# Install Bun +RUN npm install -g bun + +# Copy webui package files +COPY webui/package.json webui/bun.lock* ./webui/ + +# Install dependencies +WORKDIR /app/webui +RUN bun install --frozen-lockfile + +# Copy webui source code +COPY webui/ ./ + +# Copy built WASM files from rust-builder stage +COPY --from=rust-builder /app/webui/src/wasm/ ./src/wasm/ + +# Build the application +RUN bun run build + +# Create data directory for scripts +RUN mkdir -p ../data/scripts + +# Expose port +EXPOSE 3000 + +# Start the application +CMD ["bun", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5061973 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.8' + +services: + webui: + build: . + ports: + - "3000:3000" + volumes: + - ./data/scripts:/app/data/scripts + env_file: + - .env + restart: unless-stopped \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..89b3d83 --- /dev/null +++ b/shell.nix @@ -0,0 +1,31 @@ +{ + pkgs ? import { }, +}: + +let + rust-toolchain = pkgs.rust-bin.stable."1.73.0".default; + + rust-with-wasm-target = rust-toolchain.override { + targets = [ "wasm32-unknown-unknown" ]; + }; + +in +pkgs.mkShell { + buildInputs = with pkgs; [ + rust-with-wasm-target + + wasm-bindgen-cli + wasm-pack + + bun + clang + pkg-config + openssl + ]; + + shellHook = '' + # Set the linker for the wasm target to clang to avoid potential issues + export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER="${pkgs.clang}/bin/clang" + echo "Nix shell is ready with Cargo, wasm-bindgen, and Bun." + ''; +} diff --git a/webui/.env_dist b/webui/.env_dist new file mode 100644 index 0000000..6cb3083 --- /dev/null +++ b/webui/.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/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;