Skip to content
Three ways to deploy a blog

Three blog deployment methods, three types of failure attribution

A cost of static blogs that isn’t often mentioned: publishing.

Writing itself is linear—open the editor, write down the thoughts, close it. Publishing is not. It requires building, uploading, and confirming that what happens on the live machine matches what you see locally. I’ve reworked this pipeline three times, and only the last time did I figure out what I was actually weighing: not which tool is more advanced, but where you’re willing to let failure happen, and who cleans up after it. I’ve used all three approaches; below I break them down by that standard alone.

At first, I handed the build to CI

The initial setup was GitHub Actions. Build automatically after push, then rsync to the server. The benefit is direct: hands-off, and you can publish from any computer. For someone who writes occasionally, the appeal of this setup is that you don’t need to maintain a machine that can build.

Problems showed up in two places. First, feedback was too slow. From commit to seeing the result live, you wait over a minute for a typo. You don’t notice while writing, but it’s painful when editing—especially when all you want is to confirm a punctuation mark was fixed. Second, permissions. The repo stores the deployment private key, which means a copy of the server’s key sits in the cloud. For a personal blog this may not be unacceptable, but I don’t like the feeling.

There’s also a small but frequent friction: to fix a punctuation mark, you still have to write a commit. Over time, the commit log fills with “update post,” and looking back you can’t tell anything apart. The commit history could have served as a writing log, but it got polluted by publishing actions.

If I had to put a deployment key in CI, I’d restrict it to a separate user that can only write to the target directory, rather than giving the repo a general key that can log into the server. This cost is easy to overlook on a personal blog because the probability of something going wrong seems low; but permissions produce no benefit in normal times—they only determine the scope of damage on the day something goes wrong.

So the cost of CI isn’t just “how many manual uploads it saves”—it also includes key rotation, build environment maintenance, failure notifications, and other miscellaneous overhead. The lower your publishing frequency, the less this cost pays off.

CI failures also have their place. The build runs in the cloud, and failures usually stay in the logs; the live site is still the old version, so readers may not notice immediately. The upside is that publishing doesn’t occupy your machine; the downside is that you have to actively go look at that notification. For a blog maintained by one person, notifications are easy to scroll past.

Git Hook: moving the build to the server

Later I tried a more classical approach: a bare repo on the server, with push triggering a post-receive hook that checks out the code, installs dependencies, and runs the build.

BASH5 lines
1
2
3
4
5
# /srv/git/blog.git/hooks/post-receive
GIT_WORK_TREE=/srv/blog git checkout -f
cd /srv/blog
npm ci --omit=dev
npx hexo generate

The most charming part of this setup is “push is publish”—one command and done. You don’t wait for CI, and you don’t run it locally before uploading. Once the code is in the repo, the server does the rest itself.

The cost is also clear: the server needs Node, needs access to npm, and memory and CPU will spike during the build. The trickier part is the failure mode. If the build errors midway, the live directory may be only half updated, and you’re not there. CI at least puts a layer between the build and the live directory; Hook puts the build directly on the machine serving traffic.

I ran into this twice. Once the build failed after a theme dependency upgrade, and the homepage went blank; another time the disk filled up, leaving half-written HTML in the directory. Both times I could only ssh in and roll back manually. After those two times, my romantic feeling about “push is publish” faded a lot. It’s fast, but the price of fast is binding publishing and failure recovery into the same action.

There’s also a more insidious failure: the Node version, npm registry, and system dependencies on the server differ from local. Being able to build locally doesn’t mean the hook can build. This problem doesn’t necessarily appear every time, but once it does, troubleshooting costs far more than locally, because you’re facing a runtime environment with no editor and no local cache.

If I were to use Hook again, I’d write the build output to a temporary directory first, then switch the symlink after success. That way, when the build fails, the live site is still the previous version, and readers won’t see half a homepage. The cost is an extra directory layer and a switch action; what you get is that failures are no longer directly exposed to visitors. Hook itself isn’t bad—what’s bad is putting “build” and “public directory” into the same indivisible action.

Where you put the build is essentially choosing which kind of failure happens where you can see it.

Now I’m back to building locally

Now I run hexo generate locally, check public/ once, then rsync it up.

BASH1 line
1
rsync -az --delete public/ deploy@host:/var/www/blog/

The server does only one thing: serve the files. No Node, no dependencies, no build logs. Publishing is thirty seconds slower, but I can see the generated result before uploading. That “seeing” matters. Many low-level mistakes don’t need a stronger tool—they just need one more look before publishing.

The cost is that the environment is tied to this computer. Switching machines means reinstalling Node and theme dependencies, and publishing from a phone is basically impossible. This is also why I ultimately kept a manual process: it forces me to take a look before publishing.

My checklist is short: open the homepage and any article in local preview, confirm code blocks don’t overflow, confirm dates and titles are correct, then publish. Four steps, under a minute, but it has caught several low-level mistakes. The checklist doesn’t solve build problems; it solves the “I thought I’d already looked” problem.

Local builds aren’t risk-free either. --delete means the remote will strictly follow the local directory, so once the local public/ is incomplete, the remote will be synced to the same incomplete state. So the safer approach is to generate the complete directory first, and if necessary run once without --delete to confirm the file list isn’t missing anything, then restore it. This action is clumsy, but it pushes the irreversible operation one step later.

The hidden cost of local builds is environment maintenance. Node version, theme dependencies, image processing tools—if any one changes, the generated result may change. npm ci and lockfiles reduce part of this but can’t eliminate it. The safer approach is to change it as little as possible; every theme or Node upgrade deserves to be treated as a release—preview locally first, then sync.

rsync’s incremental transfer makes publishing feel fast, but fast doesn’t mean safe. It only transfers the differences; it won’t judge for you whether the differences are correct.

Before choosing an approach, ask three questions

Looking at the three changes together, the difference isn’t just the tools.

CI puts the build in the cloud, failures stay in logs and notifications, and the live site is usually still the old version; the permission risk also expands from the server to the repo and the CI platform. Git Hook puts the build on the server, failures are directly near the live directory, rollback requires ssh, and the build environment easily diverges from local. Local builds move failures to before upload, where you can see them, but the environment is tied to the computer, and the publishing action depends on human discipline.

So when choosing, I’d rather ask three questions first: How high is your publishing frequency? Who discovers failures first? Does rollback require logging into the server? If it’s one person, one machine, publishing several posts a day, Git Hook’s convenience is hard to replace; if publishing is infrequent but you want to confirm the generated result every time, local builds are more suitable; if you switch devices often and don’t want to maintain a build environment, CI is still the most worry-free default—just factor key permissions into the cost.

One more dimension that’s easy to overlook: after publishing, how do you know the live site is correct. CI has logs, Hooks have hook output, and with a local build only you take a look. The three approaches differ in observability, and in how fast you can recover.

There are no uniform answers to these three questions. They simply pull “deployment approach” away from tool preference and back to concrete failure responsibility.

All three approaches assume one premise: the author and the maintainer are the same one or two people, and publishing is not an approval process. With multiple collaborators, the questions become who has the right to trigger a release, who looks at build results, and what process a rollback follows—that’s a different design. The trade-offs in this article apply only to a personal blog or a very small team.

I’ve used this workflow for over half a year

I can’t say which approach is the right answer. Git Hooks suit one person, one machine, frequent publishing; a local build suits people who publish infrequently but want every step under control. I currently fall into the latter camp.

I’ve used this workflow for over half a year, and the only thing I still want to change is build speed. As for the “most elegant approach,” I increasingly think it doesn’t exist—what exists is only the portion of hassle you’re willing to bear long-term.

If publishing frequency picks up someday, I’ll first add build caching and atomic deploys rather than switching straight back to Hooks. Tools can be swapped, but failure responsibility has to be thought through first.

So whenever someone asks which one I recommend, I first ask in return: would you rather wait an extra thirty seconds before publishing, or ssh in afterward to clean up the mess?

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Deployment #Git #Static Blogs

Comments