Skip to content

fix(host): host scripts in the repo; previews as tfmc; init in compose - #248

Merged
ryanbarlow97 merged 3 commits into
mainfrom
site-host-scripts
Oct 16, 2026
Merged

ryanbarlow97 merged 3 commits into
mainfrom
site-host-scripts

Conversation

@ryanbarlow97

@ryanbarlow97 ryanbarlow97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

The preview, compose and image-prune scripts and their timers lived only on the TF server, edited in place. Previews ran as container root, so ps-preview needed an Alpine container to delete root-owned preview files and a chmod to share copied data. The site containers had no init, so the renderer's Chromium processes were left as zombies. Items 7, 8 and 13 from the 2026-10-16 host clean-up.

What changes

  1. First commit: the host's ps-preview, ps-preview-ssh, ps-compose, ps-image-prune, the reap and prune units and timers, and the router's Caddyfile, copied unchanged, so the second commit shows the real diff. The copy includes another session's 15:04 change today, which reserved portainer.
  2. Second commit:
    • Preview backends run as 1001:1001 (tfmc) and both preview containers under init: true; remove_dir is a plain rm -rf, and the copied data is no longer chmodded.
    • docker-compose.yml and docker-compose.staging.yml run both services with init: true.
    • Each script's header says where it is installed and who runs it.
    • preview_slug.py reserves portainer to match the host.

Tested on the host

This branch's preview was taken down with the old script, then brought up, down and up again with a test copy of the new one (/usr/local/sbin/ps-preview-test). The backend runs as 1001:1001 and the frontend as appuser, both with init=true. Every file in the preview folder is tfmc's, down removed the folder with no helper container, / and /api/maps/accessible answer 200, and the log shows no permission errors.

After merge

One-off transition: in the same step as installing ps-preview, run sudo chown -R tfmc:tfmc /home/tfmc/previews, so previews made by the old script (with root-owned folders) can still be stopped and reaped, and their kept data stays writable by the new tfmc backend. Install the scripts from the merge commit (commands in Docs) and remove ps-preview-test. The compose init change rebuilds both sites on their next deploy (docker-compose* changed).

Docs: TF-Minecraft/Docs#284

🤖 Generated with Claude Code

ryanbarlow97 and others added 2 commits October 16, 2026 16:36
Copied unchanged from /usr/local/sbin and /etc/systemd/system on the TF
server, so the next commit shows what changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Preview containers run as tfmc (1001) with init, so tfmc owns every file
  in a preview folder: the Alpine container that deleted root-owned files
  and the chmod of copied data are gone.
- The www and Dev compose files run both services with init, which reaps
  the renderer's Chromium processes (they piled up as zombies).
- Each host script now says where it is installed and who runs it.
- portainer is reserved as a preview name, matching the host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3462ee0a-0927-4dab-a6cb-8466b753eaf8
📥 Commits

Reviewing files that changed from the base of the PR and between bee4aae and baa1c98.

📒 Files selected for processing: 12
  • .github/scripts/preview_slug.py
  • docker-compose.staging.yml
  • docker-compose.yml
  • scripts/ps-compose.sh
  • scripts/ps-image-prune.service
  • scripts/ps-image-prune.sh
  • scripts/ps-image-prune.timer
  • scripts/ps-preview-reap.service
  • scripts/ps-preview-reap.timer
  • scripts/ps-preview-router.Caddyfile
  • scripts/ps-preview-ssh.sh
  • scripts/ps-preview.sh

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Added temporary branch previews with commands to create, stop, list and inspect preview deployments.
    • Preview links now route requests to the matching frontend and backend, and show an expired-preview message when a preview is unavailable.
    • Added scheduled cleanup for expired previews and unused website build images.
    • Added a restricted command-line helper for checking and managing the main and development sites.
  • Bug Fixes
    • Reserved the portainer preview name to prevent naming conflicts.

The changes add branch preview provisioning, deployment, routing and expiry cleanup. They also add a restricted Docker Compose wrapper, scheduled image and build-cache pruning, and init settings for main and staging services.

Changes: Preview Hosting

Layer / File(s) Summary
Preview validation and data setup
.github/scripts/preview_slug.py, scripts/ps-preview.sh
The reserved slug list now includes portainer. The preview manager validates slugs and prepares preview data from staging mounts, including a sanitised SQLite database copy.
Preview services and deployment
scripts/ps-preview.sh, docker-compose.yml, docker-compose.staging.yml
The manager defines per-preview backend and frontend services, pulls their images, starts and stops preview projects, and records SHA and expiry data. The main and staging backend and frontend services enable init.
Preview access and reporting
scripts/ps-preview-ssh.sh, scripts/ps-preview-router.Caddyfile, scripts/ps-preview.sh
The forced-command script permits up, down and list. Caddy routes matching preview hosts to backend or frontend services. The manager reports preview details and retrieves service logs.
Scheduled preview cleanup
scripts/ps-preview.sh, scripts/ps-preview-reap.service, scripts/ps-preview-reap.timer
The reaper removes previews with invalid or elapsed expiry values, cleans up orphaned Compose projects, and prunes matching images. A systemd service runs it every minute.

Site Operations

Layer / File(s) Summary
Restricted Compose commands
scripts/ps-compose.sh
The wrapper maps main and dev to selected Compose projects and files. It permits specified commands and rejects arguments that could override protected Compose settings.
Scheduled image and cache pruning
scripts/ps-image-prune.sh, scripts/ps-image-prune.service, scripts/ps-image-prune.timer
The pruning script removes images for the provincesystem and tfmc-staging projects, then prunes build cache older than 168 hours. A systemd service and weekly timer schedule the script.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  actor Operator
  participant SSH as ps-preview-ssh.sh
  participant Manager as ps-preview.sh
  participant Compose as Docker Compose
  participant Caddy
  participant Backend as Preview backend
  participant Frontend as Preview frontend
  Operator->>SSH: Submit an allowed preview command
  SSH->>Manager: Run command as tfmc
  Manager->>Compose: Start preview project
  Caddy->>Backend: Proxy /api/* for matching preview host
  Caddy->>Frontend: Proxy other requests for matching preview host
Loading
Merge Risk: ⚪ Minimal · up to baa1c

This adds host scripts and enables init for the main and staging services. No concrete merge-blocking problem was identified. Confirm the host permissions on the Compose files and the labels on built images after deployment.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryanbarlow97

Copy link
Copy Markdown
Contributor Author

Reviewed by Muse (muse-wonder-full) over two rounds; round 2 returned VERDICT: OK. CodeRabbit was rate-limited. The host install and the one-off previews chown follow.

@ryanbarlow97
ryanbarlow97 merged commit d5fed58 into main Oct 16, 2026
6 checks passed
@ryanbarlow97
ryanbarlow97 deleted the site-host-scripts branch October 16, 2026 16:55

This branch was successfully deployed

1 active deployment
preview — baa1c980 Deployed Oct 16, 2026 by ryanbarlow97 via deploy #512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant