~/blog/automation-linux/lost-site-source-deploy-pipeline.md

My website's source was gone for two months and nothing broke

// tl;dr

My main site's source was gone for two months and I didn't notice, because a static build copied onto a server just keeps serving. I rebuilt it from the deployed files and gave it a pipeline that deploys on every push, so the repo is now the only way the site can change.

A framed web page labelled web-01 hangs on a dark wall while the easel beside it stands empty, its canvas only a dashed outline.

I went to change one line of copy on my main site and couldn't find its source. It wasn't in my Forgejo, on GitHub, on the web server or on my desktop. I checked all of them. It had been gone for about two months, and the site had worked perfectly the whole time.

That last part is what I keep thinking about. Nothing went wrong, so nothing told me anything was wrong.

forgejo-runner: 13.2.0
node: 22
web server: nginx (alpine image)
build: vite
forgejo docs: 17.0.2 (checked 2026-11-24)

How a site loses its source without breaking

The site is a static Vite build. Back in June someone (me) built it once, copied the dist folder into the directory nginx serves on web-01, and moved on. There was never a deploy pipeline. The build was the deploy.

A static site in that state is very stable. nginx reads files off disk, and that's all it does. It'll serve the same bytes until the disk dies.

So the project folder it came from was dead weight the day after I copied it. I could lose it, wipe the machine it was on or forget which repo it belonged in, and the site wouldn't care. The first time it matters is the day you want to change one line.

That's why I don't think "back up your source better" covers it. A backup only saves what's in the places it looks, and nothing ever forced the source to be in one of them.

Getting it back from the live site

The upside of a static site is that the deployed files are most of the project, just minified.

I pulled the bundle back down and rebuilt it into a fresh Forgejo repo:

  • The minified CSS got prettified and kept verbatim as its own file, values untouched, so it stays diffable against the build it came from. Anything new goes in a separate stylesheet.
  • The markup came from the rendered DOM of the live page. The class names are the real contract, and grepping every selector out of the CSS gave me the full list of what the markup had to provide.

One gotcha worth passing on. My first prettifier just split on semicolons, and that cut the Google Fonts @import in half, because the font weights in that URL are separated by semicolons. Whatever CSS formatter you use for this needs to know what a string is. I ended up dropping that @import anyway, since the page already linked the same fonts.

All of that to get back to where I was before I wanted to change one line.

Making the repo the only way in

If a site can change by someone copying files onto the server, it eventually will, and the repo stops being the truth without anyone saying so. Backing up the repo doesn't help with that. You just end up with a good copy of something stale.

What does help is making the repo the only way the site can change. Push to main, and a runner builds the site and replaces the served files. Nobody copies anything by hand, so there's nothing to forget.

The workflow is short. Trimmed down, it looks like this:

# .forgejo/workflows/deploy.yml
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: site-deploy
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - run: rsync -a --delete dist/ deploy@web-01.example.lab:/srv/www/site/

There's no container restart. nginx serves the directory, so the files are the deploy. rsync --delete keeps old chunks from previous builds from piling up.

How I set up the runner

A few choices I'd make again.

One runner per project. The runner for this site is registered at the repository level, so it only ever picks up this repo's workflows. You can do that from the repo's Actions settings, or get the token from the API like I did on the version I was running:

$ curl -s -H "Authorization: token $FORGEJO_TOKEN" \
    https://git.example.lab/api/v1/repos/example-org/site/actions/runners/registration-token
{"token":"<redacted>"}

It runs as a host runner on ci-01, not in a container. All it needs is node, npm and rsync.

The deploy key lives on the runner, not in Forgejo. Since the runner only ever serves this repo, I saw no reason to put an SSH private key in Forgejo's database as a secret. The private half sits in the runner's own directory on ci-01. The public half is in the deploy account's authorized_keys on web-01 with restrict in front of it, so the key gets no terminal and no forwarding. If I rebuild the runner, I generate a new key and swap the public half.

That setup bit me once. In early November the host keys on web-01 got rotated, and the next deploy failed on a host key mismatch. I went looking for known_hosts in the runner's directory, which is its $HOME, and it wasn't being used. What I found is that OpenSSH took ~ from the account's passwd entry, not from $HOME, and for this runner those point at two different directories. Removing the stale key from the right file and rerunning the workflow fixed it.

That's what I saw on the box. I haven't checked it against the OpenSSH docs.

What a green deploy didn't catch

I got the pipeline's own checks wrong twice.

The first was checking one asset instead of all of them. Vite emits several chunks. My first verify step grabbed one asset reference with head -1, checked it, and passed while the others were stale. I made the same mistake once more in a manual check. Now the check walks every one:

$ grep -o 'assets/[^"]*' dist/index.html | sort -u | while read a; do
    curl -fsS -o /dev/null "https://www.example.lab/$a" || echo "MISSING $a"
  done
$

No output is the good result.

The second was forgetting this site renders in the browser. I shipped a blank page once. A data edit landed in the wrong array, the renderer threw a TypeError, and the main element stayed empty. The build passed. rsync worked. Every asset came back 200, so the asset check passed too. The only symptom was an error in the browser console that nothing in the pipeline could see.

So the build now runs a small script first that checks the shape of the site's data file. Every section has the fields the renderer expects, and every label matches the format it should. npm run build runs that check before vite, and I made sure it fails on the exact bug that blanked the page.

If the page is ever blank again, I'll read the browser console first. curl and the workflow will both say everything is fine.

What I'd tell myself in June

Set up the deploy pipeline before the first copy, while the source is still sitting right there. On a site only I touch, there's nobody else around to notice the source drifting off.

Two months with no source felt like proof the site was fine. All it meant was that nothing was checking. A push is now the only way in, and I'd take one door I trust over a backup of a folder that stopped mattering in June.

$ ./ask --help

Stuck on something similar? Ask below and I'll try to help you work through it. It helps to include:

  • --running hardware, OS, versions
  • --tried what you've already tried
  • --error the exact message, word for word

Comments are public, so leave out passwords, keys and public IP addresses.