소스 검색

Added Docker files and updated documentation

Efren Yevale Varela 1 개월 전
부모
커밋
6801063764
4개의 변경된 파일164개의 추가작업 그리고 7개의 파일을 삭제
  1. 31 0
      .dockerignore
  2. 23 7
      AGENTS.md
  3. 17 0
      Dockerfile
  4. 93 0
      README.md

+ 31 - 0
.dockerignore

@@ -0,0 +1,31 @@
+config.json
+node_modules
+
+# Output
+.output
+.vercel
+.netlify
+.wrangler
+/.svelte-kit
+/build
+
+# OS
+.DS_Store
+Thumbs.db
+
+# Env
+.env
+.env.*
+!.env.example
+!.env.test
+
+# Vite
+vite.config.js.timestamp-*
+vite.config.ts.timestamp-*
+
+# Paraglide
+src/lib/paraglide
+project.inlang/cache/
+
+# SQLite3 Databases
+data

+ 23 - 7
AGENTS.md

@@ -4,13 +4,14 @@ A SvelteKit 5 + Tailwind frontend with i18n (Paraglide) and dark mode enabled by
 
 ## Project Overview
 
-- **Framework**: SvelteKit 2.63.0 with Svelte 5 (runes mode, mandatory)
-- **Build Tool**: Vite 8.0.16
+- **Framework**: SvelteKit 2.68.0 with Svelte 5.56.4 (runes mode, mandatory)
+- **Build Tool**: Vite 8.1.2
 - **Styling**: Tailwind CSS 4.3.0 (via `@tailwindcss/vite`, no separate config)
 - **Components**: Flowbite Svelte 1.33.1 + Flowbite Icons
 - **i18n**: Paraglide JS (English + Spanish, auto-localized routes)
 - **Adapter**: `@sveltejs/adapter-node` (Node.js deployments)
-- **Package Manager**: pnpm
+- **Package Manager**: pnpm (>=11.9 required)
+- **Node**: >=24.14 required
 - **Type System**: JavaScript (JSConfig, no TypeScript enforcement)
 
 ## Critical Commands
@@ -128,8 +129,8 @@ runes: ({ filename }) =>
 ## Git & Workflow
 
 - **Branch**: master
-- **Recent commits**: 14 commits total (backend infrastructure: SQLite3, Argon2id, config management, graceful shutdown)
-- **Current state**: 6 files staged for commit (crypto, database setup, config changes)
+- **Recent commits**: 15 commits total (backend infrastructure: SQLite3, Argon2id, config management, graceful shutdown, Docker support)
+- **Current state**: 3 files modified/untracked (Dockerfile, .dockerignore, README.md updates)
 
 **Convention**: Clear, atomic commits. Prefix context: "feat:", "fix:", "docs:", "refactor:" when possible.
 
@@ -143,6 +144,8 @@ runes: ({ filename }) =>
 
 4. **Config must exist**: Application crashes at startup if `config.json` is missing. Always ensure it's copied from `config.json.example` before running dev/build.
 
+5. **pnpm-workspace.yaml native builds**: Specifies which native packages can be built (esbuild, Tailwind Oxide, better-sqlite3 enabled; argon2 disabled). If native deps fail to build, check this file first.
+
 ## Common Agent Tasks & Gotchas
 
 ### Adding Components
@@ -186,7 +189,8 @@ cp config.json.example config.json
 - **Lazy initialization**: Database is created on first `getSqlite3()` call
 - **Schema**: `users` table auto-created with `id`, `email`, `password`, `created_at`, `updated_at`
 - **Admin seeding**: If no users exist, `admin@delete.me` / `deleteme` is inserted (hashed with Argon2id)
-- **Path**: `/data/app.db` (relative to project root, directory auto-created if missing)
+- **Path**: `data/app.db` (relative to project root, constructed from config.json `filename` + `PROJECT_ROOT/data/`, directory auto-created if missing)
+- **WAL Mode**: Enabled by default in config for better concurrency
 
 **Idempotent**: Safe to call multiple times; schema and admin user only created once.
 
@@ -218,6 +222,18 @@ Database connection is properly closed on process termination (SIGTERM, SIGINT)
 - **Tailwind CSS**: https://tailwindcss.com/docs
 - **Svelte 5 Runes**: https://svelte.dev/docs/svelte/what-are-runes
 
+## Docker & Deployment Quirks
+
+### Database Path in Docker
+
+When using `docker run` or `docker-compose`, the config is mounted at `/opt/app/server/config.json`. The database path `data/app.db` is then resolved **relative to the working directory inside the container**, which is typically `/opt/app/`. Ensure volume mounts for `./data` are in place to persist the database across restarts.
+
+### Native Dependencies in Docker
+
+The Dockerfile uses Node.js 24 Alpine. Native packages (better-sqlite3, argon2) must build in the Alpine environment. If builds fail, check:
+- Alpine headers are installed (usually handled in Dockerfile)
+- `pnpm-workspace.yaml` allowlist is current
+
 ---
 
-**Last Updated**: Verified against current project state (14 commits, backend infrastructure added, i18n enabled, clean build)
+**Last Updated**: Verified against current project state (15 commits, Docker support added, SvelteKit 2.68.0, Vite 8.1.2, pnpm-workspace.yaml quirks documented)

+ 17 - 0
Dockerfile

@@ -0,0 +1,17 @@
+FROM node:24-alpine AS build
+
+RUN corepack enable
+
+WORKDIR /opt/app
+
+COPY . ./
+
+RUN pnpm build
+
+FROM node:24-alpine
+COPY --from=build /opt/app/build /opt/app
+COPY --from=build /opt/app/node_modules /opt/app/node_modules
+
+EXPOSE 3000
+WORKDIR /opt/app
+CMD [ "node", "index"]

+ 93 - 0
README.md

@@ -49,6 +49,99 @@ npm run preview
 
 Production output goes to `/build/` (configured for Node.js via `@sveltejs/adapter-node`).
 
+## Docker
+
+The application includes a multi-stage Dockerfile for production deployments using Node.js 24 Alpine.
+
+### Docker Run
+
+Build the Docker image:
+
+```sh
+docker build -t testing-proxy .
+```
+
+Run the container with a mounted configuration file:
+
+```sh
+docker run -d \
+  --name testing-proxy \
+  -p 3000:3000 \
+  --volume ./config.json:/opt/app/server/config.json:ro \
+  --volume ./data:/opt/app/data \
+  testing-proxy
+```
+
+The flags:
+- `--volume ./config.json:/opt/app/server/config.json:ro` — Mounts your local `config.json` as read-only inside the container
+- `--volume ./data:/opt/app/data` — Persists the SQLite database across container restarts
+
+Ensure `config.json` exists before running:
+
+```sh
+cp config.json.example config.json
+mkdir -p data
+```
+
+### Docker Compose
+
+Use Docker Compose for orchestrated deployments with secrets management:
+
+```yaml
+version: '3.8'
+
+services:
+  app:
+    image: testing-proxy:latest
+    container_name: testing-proxy
+    ports:
+      - "3000:3000"
+    secrets:
+      - source: config_secret
+        target: /opt/app/server/config.json
+        uid: "1000"
+        gid: "1000"
+        mode: 0400
+    volumes:
+      - ./data:/opt/app/data  # Persist SQLite database
+    restart: unless-stopped
+
+secrets:
+  config_secret:
+    file: ./config.json
+```
+
+Save as `docker-compose.yml` and run:
+
+```sh
+docker-compose up -d
+```
+
+The `secrets` section:
+- **`source`** — Named secret reference (`config_secret`)
+- **`target`** — Container path where the config is mounted (`/opt/app/server/config.json`)
+- **`uid` / `gid`** — User/group IDs inside the container (1000 for app user)
+- **`mode`** — File permissions (`0400` = read-only for owner)
+
+### Configuration
+
+Before running Docker containers, create your configuration file:
+
+```sh
+cp config.json.example config.json
+```
+
+Both `docker run` and `docker-compose` methods expect `config.json` to exist on your host machine and mount it into the container.
+
+### Data Persistence
+
+For Docker Compose deployments, the `./data` volume persists the SQLite database across container restarts. Ensure the `data/` directory is writable:
+
+```sh
+mkdir -p data
+chmod 755 data
+```
+
 ## Project Structure
 
 - `src/routes/` — SvelteKit filesystem routes