Commit Graph

48 Commits

Author SHA1 Message Date
XPS\Micro
eca7beefbd fix: add backwards compatibility properties for container_id/container_port
User model now provides container_id and container_port as properties that
work with the new UserContainer relationship. This allows legacy code in
api.py to continue working without modifications. The properties automatically:
- Read from the primary (first) container
- Create a primary container on first write
- Maintain backwards compatibility with single-container API
2026-02-01 16:40:20 +01:00
XPS\Micro
7b0d48ca32 feat: configure Flask file-based logging for debug API
- Add rotating file handler to app.py for logging to /app/logs/spawner.log
- Configure max 10MB per file with 5 backup files
- Update admin_api.py debug endpoint to read from Flask log file
- Implement clear-logs functionality to truncate log file
- Update documentation with Flask log file details
- Creates log directory automatically if missing
2026-02-01 15:51:24 +01:00
XPS\Micro
5dcc731d7c - Changed view-logs to read docker container logs (docker logs spawner)
- Updated clear-logs to inform that docker logs cannot be deleted
  - Updated documentation to reflect docker-based log reading
  - No log file needed anymore"
2026-02-01 15:36:52 +01:00
XPS\Micro
cbc60a08e4 fix: use docker logs instead of log file for debug API 2026-02-01 15:29:03 +01:00
XPS\Micro
ba20630033 Merge branch 'main' of https://gitea.iotxs.de/RainerWieland/spawner 2026-02-01 13:42:21 +01:00
XPS\Micro
95960ab7a9 add debug admin API for logs and database management 2026-02-01 13:41:28 +01:00
XPS\Micro
ed36e39e29 fix: fix template initialization order in Config class
- Move template loading after class definition to avoid NameError
- Initialize TEMPLATE_IMAGES, TEMPLATES_CONFIG, and CONTAINER_TEMPLATES after Config class
- Use simple loop instead of calling static methods during class init
- Prevents 'Config is not defined' errors during import

This fixes the circular dependency issue where _build_container_templates()
was trying to reference Config.TEMPLATE_IMAGES while the class was still
being defined.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-01 11:45:40 +01:00
XPS\Micro
b41fd980ce fix: add SMTP and missing environment variables to docker-compose.yml
- Fix USER_TEMPLATE_IMAGES quoting in .env.example (prevent bash metacharacter issues)
- Add all SMTP configuration variables to docker-compose environment
- Add EMAIL service variables (FRONTEND_URL, MAGIC_LINK_EXPIRY, RATE_LIMIT)
- Add JWT and resource limit variables
- Improve environment variable organization with comments

SMTP variables were defined in .env but not passed to container, causing
email service configuration issues.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-01 10:24:51 +01:00
XPS\Micro
10b28179fc feat: implement dynamic template system with auto-detection
**Backend (config.py):**
- Add dynamic template loading from USER_TEMPLATE_IMAGES (.env)
- Add template metadata loading from templates.json
- Implement automatic type extraction from image names
- Remove hardcoded template definitions (dev/prod)
- Maintain legacy USER_TEMPLATE_IMAGE for backward compatibility

**Configuration:**
- Add templates.json with metadata for template-01, template-02, template-next
- Update .env.example with new USER_TEMPLATE_IMAGES variable (semicolon-separated)
- Document automatic template type extraction

**Installation (install.sh):**
- Implement auto-detection for all user-template-* directories
- Replace hardcoded template builds with dynamic loop
- Calculate TOTAL_BUILDS dynamically
- Add special handling for Next.js templates

**Documentation:**
- Move MVP_DEPLOYMENT_GUIDE.md to docs/install/DEPLOYMENT_GUIDE.md
- Add "Dynamic Template System" section to CLAUDE.md
- Update docs/install/README.md with Quick Links and dynamic system info
- Add references to deployment guide in CLAUDE.md

**Templates:**
- Reorganize user-template/ → user-template-01/ (Nginx Basic)
- Add user-template-02/ (Nginx Advanced)
- Keep user-template-next/ unchanged

**Benefits:**
- Unlimited number of templates (no longer hardcoded to 2)
- Metadata-driven display in dashboard
- Automatic image discovery and building
- Extensible without code changes

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-01 09:04:59 +01:00
XPS\Micro
5cfad38b3c fix: ensure user-template-next is always built for multi-container MVP
The install.sh script was only building user-template-next when
USER_TEMPLATE_IMAGE=user-template-next:latest was set in .env, which
was an old single-container configuration.

Changes:
- Remove dependency on USER_TEMPLATE_IMAGE for building user-template-next
- Always build user-template-next when directory exists
- Add user-template-next to TOTAL_BUILDS count automatically
- Change user-template-next build from optional warning to required
- Update build output to clearly show multi-container template building
- Update final installation summary to show template configuration

This ensures both dev and prod templates are always built for the
Multi-Container MVP, regardless of legacy .env settings.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-31 21:22:09 +01:00
XPS\Micro
2bcb7b97a4 docs: add comprehensive MVP deployment guide
Add step-by-step deployment instructions covering:
- Phase 1: Preparation (clean slate, build templates, configure env)
- Phase 2: Start services (docker-compose up, health checks)
- Phase 3: First registration (test user creation)
- Phase 4: Test both containers (dev and prod)

Includes:
- Verification checklist for backend, frontend, docker, traefik
- Detailed troubleshooting guide for common issues
- Monitoring and status commands
- Security checklist for production
- Performance scaling recommendations
- Next phase features for enhancement

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-31 20:33:57 +01:00
XPS\Micro
79cf304ccf feat: implement multi-container MVP with dev and prod templates
Add full support for 2 container types (development and production):

Backend Changes:
- New UserContainer model with unique constraint on (user_id, container_type)
- Removed single-container fields from User model (container_id, container_port)
- Added CONTAINER_TEMPLATES config with dev and prod templates
- Implemented spawn_multi_container() method in ContainerManager
- Added 2 new API endpoints:
  * GET /api/user/containers - list all containers with status
  * POST /api/container/launch/<type> - on-demand container creation
- Multi-container container names and Traefik routing with type suffix

Frontend Changes:
- New Container, ContainersResponse, LaunchResponse types
- Implemented getUserContainers() and launchContainer() API functions
- Completely redesigned dashboard with 2 container cards
- Status display with icons for each container type
- "Create & Open" and "Open Service" buttons based on container status
- Responsive grid layout

Templates:
- user-template-next already configured with Tailwind CSS and Shadcn/UI

Documentation:
- Added IMPLEMENTATION_SUMMARY.md with complete feature list
- Added TEST_VERIFICATION.md with detailed testing guide
- Updated .env.example with USER_TEMPLATE_IMAGE_DEV/PROD variables

This MVP allows each user to manage 2 distinct containers with:
- On-demand lazy creation
- Status tracking per container
- Unique URLs: /{slug}-dev and /{slug}-prod
- Proper Traefik routing with StripPrefix middleware

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-31 20:33:07 +01:00
XPS\Micro
cd91992333 fix: add fallback to npm install for user-template-next
- Use npm ci only if package-lock.json exists
- Falls back to npm install if not present
- Allows flexible package installation without strict lockfile requirement
2026-01-31 18:34:06 +01:00
XPS\Micro
814d4d2959 modified 2026-01-31 18:30:00 +01:00
XPS\Micro
fab346801d feat: auto-recreate user container on login if missing
Changes:
- If container exists but is not running: restart it
- If container_id exists but container was deleted: spawn new container
- If no container_id at all: spawn new container
- Adds detailed logging for container lifecycle

This ensures users always have a working container after login, even if the old one was deleted or didn't exist yet.
2026-01-31 18:16:47 +01:00
XPS\Micro
ff22add424 fix: wrap useSearchParams in Suspense boundary for verify pages
- Extract VerifySignupContent and VerifyLoginContent components
- Wrap components in Suspense boundary to avoid static generation errors
- Add loading spinner fallback during hydration
- Fixes 'useSearchParams() should be wrapped in a suspense boundary' error in Next.js 14
2026-01-31 17:44:51 +01:00
XPS\Micro
13082f97b1 fix: handle undefined last_used in formatDate
- Update formatDate() to accept string | null | undefined
- Fixes TypeScript error for optional last_used field in AdminUser
- Returns '-' if date is not available (null or undefined)
2026-01-31 17:31:13 +01:00
XPS\Micro
016ec933e6 fix: update legacy web routes to use slug instead of username
- Fix /dashboard route to use current_user.slug for service_url
- Fix /container/restart route to pass current_user.slug to spawn_container()
- Ensures legacy Flask-Login routes work with passwordless authentication
2026-01-31 17:05:45 +01:00
XPS\Micro
b116d74f84 fix: remove username references from admin page
- Replace u.username with u.slug in search filter
- Replace user display names from username to email (primary identifier in passwordless auth)
- Update avatar fallbacks to use email initials
- Update handleDeleteUser parameter from username to userEmail
- Align admin page with new user identification scheme
2026-01-31 17:00:40 +01:00
XPS\Micro
fe4907ee46 fix: update admin page for passwordless authentication
- Remove handleResetPassword function (no longer needed with Magic Links)
- Change password reset button to send Magic Link instead
- Update button icon from KeyRound to Mail
- Update button tooltip to reflect new Magic Link flow
- Remove unused KeyRound import
2026-01-31 16:46:45 +01:00
XPS\Micro
2016767dcb perf: make user-template-next optional and optimize build process
Changes:
- install.sh: user-template-next is now only built if USER_TEMPLATE_IMAGE=user-template-next:latest is set in .env
  * Defaults to user-service-template (nginx) to save 4-5 minutes per install
  * Dynamic build step counting based on configured templates
  * Shows helpful message when template is skipped
  * Build numbering adapts automatically ([1/3] vs [1/4])

- user-template-next/Dockerfile: Optimize build performance
  * Pin Node version to 20.11-alpine for reproducibility
  * Use npm ci instead of npm install for faster, reproducible builds
  * Separate package.json copy for better layer caching
  * Add --prefer-offline and --no-audit flags to npm ci
  * Clean npm cache to reduce image size
  * Add clear comments for multi-stage build steps

Impact:
- Default installations: 2-3 minutes faster
- Reduced build time for Next.js template (when enabled) via layer caching
- Better reproducibility and predictable builds
2026-01-31 16:43:10 +01:00
XPS\Micro
20a0f3d6af feat: Implement passwordless authentication with Magic Links
Major changes:
- Remove username and password_hash from User model
- Add MagicLinkToken table for one-time-use email authentication
- Implement Magic Link email sending with 15-minute expiration
- Update all auth endpoints (/login, /signup) to use email only
- Create verify-signup and verify-login pages for token verification
- Container URLs now use slug instead of username (e.g., /u-a3f9c2d1)
- Add rate limiting: max 3 Magic Links per email per hour
- Remove password reset functionality (no passwords to reset)

Backend changes:
- api.py: Complete rewrite of auth routes (magic link based)
- models.py: Remove username/password, add slug and MagicLinkToken
- email_service.py: Add Magic Link generation and email sending
- admin_api.py: Remove password reset, update to use email identifiers
- container_manager.py: Use slug instead of username for routing
- config.py: Add MAGIC_LINK_TOKEN_EXPIRY and MAGIC_LINK_RATE_LIMIT

Frontend changes:
- src/lib/api.ts: Update auth functions and User interface
- src/hooks/use-auth.tsx: Implement verifySignup/verifyLogin
- src/app/login/page.tsx: Email-only login form
- src/app/signup/page.tsx: Email-only signup form
- src/app/verify-signup/page.tsx: NEW - Signup token verification
- src/app/verify-login/page.tsx: NEW - Login token verification
- src/app/dashboard/page.tsx: Display slug instead of username

Infrastructure:
- install.sh: Simplified, no migration needed (db.create_all handles it)
- .env.example: Add MAGIC_LINK_TOKEN_EXPIRY and MAGIC_LINK_RATE_LIMIT
- Add IMPLEMENTATION-GUIDE.md with detailed setup instructions

Security improvements:
- No password storage = no password breaches
- One-time-use tokens prevent replay attacks
- 15-minute token expiration limits attack window
- Rate limiting prevents email flooding

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-31 16:19:22 +01:00
XPS\Micro
67149e1544 fix: install curl in frontend Dockerfile for healthcheck compatibility
- Added curl installation in Debian slim runner stage
- curl is required for healthcheck in docker-compose.yml
- curl is pre-installed in node:20-slim base image was incorrect assumption
- Healthcheck uses: curl -f http://localhost:3000/
- Cleaned up apt cache to keep image size minimal
2026-01-31 13:34:51 +01:00
XPS\Micro
e0bafb142f fix: change frontend healthcheck from wget to curl for Debian slim compatibility
- Switched from wget to curl for frontend healthcheck
- wget is not installed in node:20-slim (Debian-based)
- curl is pre-installed and compatible with Debian slim images
- Consistent with spawner API healthcheck (also uses curl)
2026-01-31 13:14:50 +01:00
XPS\Micro
676fcea493 fix: correct indentation in spawner-api error handling
- Fixed indentation mismatch in error handling block
- Consistent with other build error blocks
2026-01-31 12:49:31 +01:00
XPS\Micro
29145dde84 fix: switch from Alpine to Debian slim Node.js image to resolve SWC binary loading issue
- Changed FROM node:20-alpine to node:20-slim for both builder and runner stages
- Alpine (musl) is incompatible with Next.js SWC binary (glibc)
- Debian slim provides 80% smaller image compared to full node:20 (~180MB vs ~900MB)
- Fully compatible with Next.js and SWC without any patches
- Better performance and stability on Synology NAS
2026-01-31 12:39:31 +01:00
XPS\Micro
912904802c chore: unified logging in install.sh
- All build logs now written to spawner-install.log
- Added clear section headers for each build
- Replaced separate temp log files with single log file
- Added log file path hint at end of installation
2026-01-31 12:30:16 +01:00
XPS\Micro
4b8cd3eb4a fix: email verification improvements
- FRONTEND_URL now generates correct URL from BASE_DOMAIN and SPAWNER_SUBDOMAIN
- Fixed German umlaut in email button: 'bestaetigen' → 'bestätigen'
- Added 'verified=true' parameter to backend redirect for hybrid approach
- Frontend now checks 'verified' parameter and shows error if not set
- Removed unused token logic from verify-success page (backend handles verification)
- Added warning UI for unverified emails with resend link
2026-01-31 11:57:52 +01:00
XPS\Micro
63a396955e fix: wrap useSearchParams in Suspense boundary for Next.js 14 compatibility
- Added Suspense boundary to verify-success/page.tsx
- Added Suspense boundary to verify-error/page.tsx
- Fixes build error: useSearchParams() should be wrapped in a suspense boundary
- Added Loader2 fallback UI for both pages
2026-01-31 10:46:58 +01:00
XPS\Micro
1b44bb3d10 Update documentation for v0.3.0 (admin features)
- CHANGELOG.md: Add v0.3.0 with admin dashboard, email verification,
  user states, and all new features
- install/README.md: Add SMTP configuration variables
- README.md: Update version to 0.3.0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 07:06:13 +01:00
XPS\Micro
99d7ed1e82 picture added 2026-01-31 07:03:14 +01:00
XPS\Micro
d188115db4 Add admin features and email verification
Backend:
- First registered user becomes admin automatically
- Email verification required before login
- Admin API with user management endpoints:
  - Block/unblock users
  - Reset passwords (sends email)
  - Delete user containers
  - Delete users
  - Resend verification emails
  - Takeover sessions (Phase 2 dummy)
- New decorators: @admin_required, @verified_required
- SMTP configuration for email sending
- UserState enum (registered/verified/active)
- Activity tracking (last_used field)

Frontend:
- Admin dashboard with color-coded user list
  - Green: active, recently used
  - Yellow: warning (unverified/inactive)
  - Red: critical (long unverified/very long inactive)
- Email verification flow (verify-success/verify-error pages)
- Signup shows verification instructions
- Login handles unverified accounts with resend option
- Admin link in dashboard header for admins

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 07:01:51 +01:00
XPS\Micro
b6fd832311 Update documentation: CHANGELOG v0.2.0, Synology compatibility guide 2026-01-31 00:01:32 +01:00
XPS\Micro
fa03fb0f3d Fix user-template-next: add baseUrl and include lib/utils.ts 2026-01-30 23:28:11 +01:00
XPS\Micro
d4af469207 Fix Dockerfiles: use npm install if package-lock.json missing 2026-01-30 23:14:30 +01:00
XPS\Micro
9e352f7430 Remove --progress=plain flag for older Docker versions (Synology) 2026-01-30 23:03:40 +01:00
XPS\Micro
e27693a1a2 Fix Docker build verification: check exit code and image existence 2026-01-30 22:58:34 +01:00
XPS\Micro
d2a2905369 Fix git safe.directory for NAS/Synology environments 2026-01-30 22:29:25 +01:00
XPS\Micro
f822b93e2e Fix redirect loop: remove /login /signup from Traefik backend routes 2026-01-30 22:16:52 +01:00
XPS\Micro
616ab44414 Fix auth.py: redirect to frontend instead of rendering templates 2026-01-30 22:08:36 +01:00
XPS\Micro
e17231eb75 Add missing frontend/src/lib files (api.ts, utils.ts) 2026-01-30 22:00:55 +01:00
XPS\Micro
68e1320d20 Add --no-cache to all Docker builds 2026-01-30 21:56:15 +01:00
XPS\Micro
c80d3c0d92 Script modified 2026-01-30 21:45:27 +01:00
XPS\Micro
43c26dc8f8 script optimized for Synology NAS 2026-01-30 21:16:23 +01:00
XPS\Micro
31165c9367 add indicator 2026-01-30 21:09:02 +01:00
XPS\Micro
6664be6149 script modified (add Versionchecks) 2026-01-30 18:06:52 +01:00
XPS\Micro
c363351483 Initial project structure with documentation 2026-01-30 18:00:41 +01:00
XPS\Micro
406ed2c158 Readme added 2026-01-30 16:43:23 +01:00