I like the idea of reviewing a blog post before it reaches production. Not just reviewing the Markdown in a pull request, but seeing what Hugo actually generates: the links, the layout, the images, and whatever creative interpretation I’ve managed to give the formatting this time.
The blog already had a deployment pipeline: GitHub Actions built the site, sent the generated files to the homelab, and an Nginx container served them through Pangolin. What it didn’t have was a place to look at changes before publishing them.
So I added a beta site.
The objective was straightforward: publish pull request changes to beta.mike.frechtling.net, and publish to mike.frechtling.net after merging to main. I also wanted some evidence that the version being reviewed was the version the pipeline thought it had deployed.
Naturally, the interesting part was everything hiding behind the word publish.
One container, two sites#
I didn’t need a second Nginx container for another static site. The existing container already mounted the parent directory containing the blog releases, so it could serve two separate directory trees.
| Site | Nginx upstream | Active release |
|---|---|---|
| Production | Port 8088 | /srv/blog/current |
| Beta | Port 8089 | /srv/blog/beta/current |
Production keeps its original path. That turned out to be important: an early proposal moved production into a new directory and involved manually copying the existing files. It would have introduced a migration and a possible outage for no real benefit. Keeping production where it was meant the existing site could continue serving while beta was added alongside it.
Each environment has its own releases and current symlink. The publisher stages a complete build and then switches the symlink atomically. Nginx serves the active release without needing to restart for every new post.
The Nginx configuration itself does need to be deployed when it changes. That’s a separate workflow from publishing blog content: uploading the beta files does not magically teach an old Nginx configuration about port 8089. For the initial setup, I ran the existing Apps Hugo Update workflow against the feature branch. After merge, changes to the service configuration on main trigger that workflow automatically.
Getting traffic to beta#
In the Pangolin web dashboard, I created a new private resource for beta.mike.frechtling.net and pointed it at the apps container’s IP address on port 8089. Production continues using its existing resource on port 8088.
That distinction matters. Adding both ports as targets on the same Pangolin resource could cause requests to be load-balanced between production and beta. That’s not quite the exciting preview experience I was looking for.
That was all I needed to change in the dashboard for my setup. Other Pangolin installations may need additional DNS, TLS, or access-policy configuration.
Nginx adds this header to beta responses:
add_header X-Robots-Tag "noindex, nofollow" always;That’s a request to search engines, not an access control mechanism. If the content needs to be private, it needs authentication. The beta build also still uses the blog’s configured analytics, so a preview isn’t completely invisible to the rest of the world.
A pull request becomes a preview#
For pull requests targeting main, the preview workflow checks out the proposed merge, installs Hugo, and builds the site with the beta hostname:
hugo --minify --baseURL https://beta.mike.frechtling.net/ --destination publicThe base URL is important. Hugo generates absolute URLs in places such as canonical links and metadata. A preview built with the production base URL might look convincing, but still direct readers and search engines to the wrong hostname.
After checking that the generated homepage and stylesheet exist, the workflow connects to the private network through Pangolin and uploads the build over SSH. The publisher creates the beta directory if necessary and switches the active release.
There are also GitHub environments named beta and production. They provide deployment history, links to the sites, and a place to add protection rules or environment-specific secrets. At the moment, they don’t automatically provide credential isolation: if both workflows use the same repository secrets, they can still have access to the same infrastructure. Environment secrets take precedence over repository secrets with the same name.
The preview workflow is limited to pull requests from branches in the repository; fork and Dependabot runs don’t deploy. The current deployment key has broad access to the apps container, so this is not a pipeline to run against untrusted pull request code. An approval-gated environment and a restricted deployment account would reduce that risk.
Did the right version actually arrive?#
Uploading files is a useful start. It isn’t the same as confirming that Nginx is serving them.
Each beta build includes a version.json containing:
- The pull request number and head commit.
- The merge commit and Git tree used for the preview build.
- The GitHub Actions run ID and attempt.
- Hashes of the generated homepage and CSS.
The workflow fetches the version file, homepage, and stylesheet from Nginx and compares them with the build it just uploaded. If the files can’t be fetched or don’t match, the preview job fails instead of reporting a successful deployment.
The version file is also available on the beta site, subject to its access policy. That gives me a way to compare the live preview with the pull request I’m reviewing.
There is a catch: this is one shared beta site, not a separate site per pull request. A later successful deployment replaces the previous preview. Deployments are serialized, but GitHub can replace a pending run with a newer pending run and doesn’t guarantee ordering. A green check tells me what passed at the time; it doesn’t guarantee that the same preview is still live later.
The production gate#
My first thought was to take the verified beta files and promote them directly to production. That would be lovely, except those files were built with the beta base URL. Copying them unchanged would bring beta canonical URLs and metadata along for the ride.
Instead, the production workflow verifies beta first and then builds the merged commit with the production base URL.
Before building, it checks that:
- The live beta version identifies a pull request merged into
mainat the production commit. - The PR head and successful preview workflow run match the recorded version.
- The tested Git tree matches the merged commit’s tree.
- The live beta homepage and CSS match the recorded hashes.
The workflow repeats the verification after the production build and immediately before publishing. If a check fails, the job stops rather than deploying an unverified production build.
Why compare Git trees rather than just commit IDs? The preview is built from a PR merge commit, while the actual commit on main can have a different ID after a merge, squash, or rebase. The tree comparison checks that the tracked source content is the same, including the theme submodule reference, even if the commits themselves differ.
There are limits. These checks happen after the PR is merged; a failed deployment doesn’t undo that merge. Beta could also change after the final check. Direct pushes to main, a skipped preview, or another PR replacing beta can all cause production deployment to fail. That’s a deliberate trade-off for this small setup, not a general-purpose release management system.
Two failures worth keeping#
The first beta run successfully uploaded the site, but its verification timed out fetching version.json from port 8089 on the apps container. The file was there and could be served through the public beta site. The workflow could also connect over SSH, but the direct HTTP connection from the runner timed out.
The fix was to use the connection that was already working: SSH to the apps container with host-key verification, then request http://127.0.0.1:8089 from there. Both beta verification and the production gate use that path.
That verifies what Nginx serves on the host. It does not prove that public DNS, TLS, Pangolin routing, or its authentication policy are correct. Those still need a separate end-to-end check.
The second failure happened after a successful beta run and a PR merge. The production gate asked GitHub for the preview workflow run and expected its pull_requests list to contain the PR. After the merge, the API response had an empty list, so the gate rejected a successful run.
The check was adjusted to handle an empty list while still matching the merged PR, head commit, branch, repository, workflow, and successful run attempt. If GitHub does return a non-empty PR list, it still needs to contain the expected PR. The tested and merged trees matched; the problem was an assumption about the API response, not the site content.
This was a useful reminder that a verification step can fail for reasons unrelated to the thing being deployed. It needs testing against the real service responses as well as against convenient examples.
What I got out of it#
The result is a reasonably small addition to the existing homelab: one Nginx container, two sites, a shared preview, and a production deployment that checks what was previewed before building again.
It’s not perfect. The shared beta site means previews can displace one another, the deployment credentials need further restriction, and checking Nginx locally doesn’t cover the entire public request path. But those limitations are visible, and the pipeline now has more to say than simply “the upload command finished.”
For a blog in a homelab, that’s a pretty useful improvement. Even if getting there did require a failed beta deployment and a failed production deployment first.