···1717- `CONTEXT=production`
1818- `DEPLOY_SECRET=...`
19192020+Optional deploy keys:
2121+- `DEPLOY_BRANCH=master` or `DEPLOY_BRANCH=main`
2222+- `DEPLOY_BRANCHES=master,main` to allow multiple webhook refs
2323+2024Recommended workflow:
21251. Copy `.env.example` to `.env`
22262. Fill in the real production values
23273. Re-run `fish vault-tool.fish status` to confirm `lith/.env` is tracked
2424-4. Deploy with `fish /workspaces/aesthetic-computer/lith/deploy.fish`
2828+4. Push the deploy branch to GitHub. The webhook deploys pushed commits only.
2929+5. Or deploy manually with `fish /workspaces/aesthetic-computer/lith/deploy.fish`
3030+3131+Notes:
3232+- `lith/deploy.fish` no longer rsyncs local working-tree files into production.
3333+- Manual deploys now reset the host to the pushed git branch state, then refresh `.commit-ref`.
+41-27
lith/deploy.fish
···1818set DEFAULT_LITH_DROPLET_NAME "ac-lith"
1919set TARGET_HOST $DEFAULT_LITH_HOST
2020set TARGET_DROPLET_NAME $DEFAULT_LITH_DROPLET_NAME
2121+set LOCAL_BRANCH (git -C $REPO_ROOT branch --show-current 2>/dev/null)
2222+set TARGET_BRANCH $LOCAL_BRANCH
21232224if set -q LITH_HOST
2325 set TARGET_HOST $LITH_HOST
···25272628if set -q LITH_DROPLET_NAME
2729 set TARGET_DROPLET_NAME $LITH_DROPLET_NAME
3030+end
3131+3232+if set -q DEPLOY_BRANCH
3333+ set TARGET_BRANCH $DEPLOY_BRANCH
3434+end
3535+3636+if test -z "$TARGET_BRANCH"
3737+ set TARGET_BRANCH main
2838end
29393040function ssh_ok --argument host
···124134125135echo -e "$GREEN-> Connected to $TARGET_HOST.$NC"
126136127127-# Sync repo (git pull on remote)
128128-echo -e "$GREEN-> Pulling latest code...$NC"
129129-ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "cd $REMOTE_DIR && git pull origin main"
137137+# Deploy from pushed git state only. This avoids production drift from local rsync overlays.
138138+echo -e "$GREEN-> Verifying origin/$TARGET_BRANCH...$NC"
139139+git -C $REPO_ROOT fetch origin $TARGET_BRANCH --quiet
140140+set ORIGIN_HEAD (git -C $REPO_ROOT rev-parse origin/$TARGET_BRANCH)
130141131131-# Overlay local working tree changes so deploys include uncommitted routing/frontend edits.
132132-echo -e "$GREEN-> Syncing local lith/ and system/ working tree...$NC"
133133-rsync -az --delete \
134134- --exclude node_modules \
135135- --exclude .env \
136136- --exclude .DS_Store \
137137- "$REPO_ROOT/lith/" \
138138- $LITH_USER@$TARGET_HOST:$REMOTE_DIR/lith/
139139-rsync -az --delete \
140140- --exclude node_modules \
141141- --exclude .env \
142142- --exclude .DS_Store \
143143- --exclude .netlify \
144144- --exclude .commit-ref \
145145- "$REPO_ROOT/system/" \
146146- $LITH_USER@$TARGET_HOST:$REMOTE_DIR/system/
142142+if test "$LOCAL_BRANCH" = "$TARGET_BRANCH"
143143+ set LOCAL_HEAD (git -C $REPO_ROOT rev-parse HEAD)
144144+ if test "$LOCAL_HEAD" != "$ORIGIN_HEAD"
145145+ echo -e "$RED x Local $TARGET_BRANCH is ahead of origin/$TARGET_BRANCH.$NC"
146146+ echo -e "$YELLOW Push first. This deploy script no longer rsyncs uncommitted or unpushed code into production.$NC"
147147+ exit 1
148148+ end
149149+end
147150148148-# Write .commit-ref AFTER rsync so it reflects the actual deployed state
149149-echo -e "$GREEN-> Writing commit ref...$NC"
150150-ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "cd $REMOTE_DIR && git rev-parse HEAD > system/public/.commit-ref"
151151+echo -e "$GREEN-> Deploying branch $TARGET_BRANCH at $ORIGIN_HEAD...$NC"
152152+ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "\
153153+cd $REMOTE_DIR && \
154154+git fetch origin $TARGET_BRANCH --quiet && \
155155+if git show-ref --verify --quiet refs/heads/$TARGET_BRANCH; then \
156156+ git checkout $TARGET_BRANCH --quiet; \
157157+else \
158158+ git checkout -B $TARGET_BRANCH origin/$TARGET_BRANCH --quiet; \
159159+fi && \
160160+git reset --hard origin/$TARGET_BRANCH --quiet && \
161161+git rev-parse HEAD > system/public/.commit-ref"
151162152163# Upload env
153164echo -e "$GREEN-> Uploading environment...$NC"
···158169159170# Install deps
160171echo -e "$GREEN-> Installing dependencies...$NC"
161161-ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "cd $REMOTE_DIR/lith && npm install && cd $REMOTE_DIR/system && npm install"
172172+ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "cd $REMOTE_DIR/lith && npm install --omit=dev && cd $REMOTE_DIR/system && npm install --omit=dev"
162173163163-# Upload Caddyfile
164164-echo -e "$GREEN-> Updating Caddy config...$NC"
165165-scp -i $SSH_KEY $SCRIPT_DIR/Caddyfile $LITH_USER@$TARGET_HOST:/etc/caddy/Caddyfile
166166-ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "systemctl reload caddy"
174174+# Install service file + Caddy config from the deployed checkout
175175+echo -e "$GREEN-> Updating service + Caddy config...$NC"
176176+ssh -i $SSH_KEY $LITH_USER@$TARGET_HOST "\
177177+cp $REMOTE_DIR/lith/lith.service /etc/systemd/system/lith.service && \
178178+cp $REMOTE_DIR/lith/Caddyfile /etc/caddy/Caddyfile && \
179179+systemctl daemon-reload && \
180180+systemctl reload caddy"
167181168182# Restart lith service
169183echo -e "$GREEN-> Restarting lith...$NC"