I wanted to set up a QA environment for my personal site.
Every push to main now deploys a copy of the site to my home server. That server is not open to the internet. GitHub Actions reaches it through Tailscale, deploys over SSH, and the QA copy is served on a real domain through a Cloudflare Tunnel that was already running there.

Also to be crystal clear, this is not the best solution possible, this is a solution that works for my case, where I don't want to spend crazy money in hosting, and I have already a self hosted solution that I can use for QA, but I also use for other things.

Production is unchanged. It's a separate VPS, deployed when I publish a GitHub release. What I wanted was a place to look at main after every merged PR, before it goes anywhere near production, without opening a single port on my home network.

The first real deploys taught me more than the design did, so most of this post is about what went wrong and how each failure stopped safely.

The setup

Piece What it is
The site A static Vite + React site, built into an nginx Docker image with a Dockerfile and compose.yaml
Production A separate VPS, deployed on GitHub releases (out of scope here)
The home server An Ubuntu box running about 40 other containers: self-hosted apps, databases, a reverse proxy. Already on my tailnet.
The code A private GitHub repo, where Actions runs
Serving A cloudflared tunnel already running on the server for the other apps

In the examples I'll call the server qa-box, the tailnet tailXXXX.ts.net, the deploy user deploy, the app folder /srv/apps/my-site, and the server's LAN IP 192.168.1.50.

QA gets its own hostname on the existing tunnel, behind Cloudflare Access. Opening it asks for an email address first, so only addresses I allow get in, and search engines can't index a second copy of my site.

The design, and what I rejected

Docker Compose on the server, from a git clone

QA runs the same image I get from a local docker compose up. The server keeps a git clone of the repo in /srv/apps/my-site, checks out the commit being deployed, and builds it with Compose.

Because the box is shared, isolation matters. Each app gets its own compose project name (-p) and its own host port. A deploy of this app can only touch containers in its own project. It can't replace or remove anything else.

Two alternatives I rejected:

  • Build with npm run build and serve with the host's nginx, like production. That needs Node on the server and a hand-made nginx site on a box that already has a reverse proxy and 40 containers. More moving parts on a shared machine.
  • Build in CI and rsync the dist/ folder. Simple, but QA wouldn't test the Docker image. Half the point of QA is to catch a broken image before production does. ### Tailscale with workload identity, not a stored secret

The runner joins the tailnet with tailscale/github-action@v4 using workload identity federation (OIDC). The job asks GitHub for an OIDC token (permissions: id-token: write), and Tailscale trusts tokens that match a credential I set up in the admin console. The action only needs oauth-client-id and audience.

The result: no long-lived Tailscale secret stored in GitHub. The runner joins as tag:ci, as an ephemeral node, and it's removed after the job.

Plain SSH with a dedicated deploy key, not Tailscale SSH

Tailscale SSH would have been neat, but it needs the destination to be tagged. Tagging the shared server would change who owns it in the tailnet and change the access rules for everything else on it. I didn't want a QA deploy to change how 40 other apps are reached.

So the runner uses normal SSH with a key made only for deploys. Tailscale's job is narrower: let tag:ci reach only tcp:22 on that one machine.

All settings in a GitHub Environment

At the start I had a question I couldn't answer: on a server shared with other apps, where do I say which folder belongs to this app? The answer turned out to be a GitHub Environment variable, validated before it's used.

Everything lives in an Environment called qa, limited to the main branch:

Name Kind Example
QA_HOST variable qa-box.tailXXXX.ts.net
QA_SSH_PORT variable 22
QA_SSH_USER variable deploy
QA_APP_PATH variable /srv/apps/my-site
QA_HTTP_PORT variable 7500
QA_COMPOSE_PROJECT variable my-site-qa
QA_SSH_PRIVATE_KEY secret private half of the deploy key
QA_SSH_KNOWN_HOSTS secret the server's host key line
TS_OAUTH_CLIENT_ID secret Tailscale trust credential ID
TS_AUDIENCE secret Tailscale audience value

Stream the deploy script from the runner

The deploy script lives in the repo, at scripts/deploy-qa.sh. The runner doesn't copy it to the server. It streams it over SSH:

ssh deploy@qa-box 'bash -s -- <args>' < scripts/deploy-qa.sh 

The server always runs the script from the commit being deployed, and nothing needs installing there first. If I change the script in a PR, the next deploy uses the new version.

The Tailscale policy

This is the part of the tailnet policy that matters:

"tagOwners": { "tag:ci": ["autogroup:admin"] }, "hosts": { "qa-box": "100.x.y.z" }, "grants": [ // GitHub Actions runners may reach only SSH on the QA server. { "src": ["tag:ci"], "dst": ["qa-box"], "ip": ["tcp:22"] } ], "tests": [ { "src": "tag:ci", "accept": ["qa-box:22"], "deny": ["qa-box:80", "qa-box:7500"] } ] 

A few things worth explaining.

Check for the default allow-all rule first. A new tailnet ships with a rule like "src": ["*"], "dst": ["*"]. If yours still has it, a tagged CI node can reach every device on your tailnet, and the narrow grant above adds nothing. Narrow the broad rule to autogroup:member, so it covers people's devices and not tagged nodes.

The tests block runs when you save the policy. If a later edit lets tag:ci reach port 80 or the QA port, or stops it reaching SSH, Tailscale refuses to save. It's a cheap way to make the intent stick.

I used a hosts alias instead of a tag. qa-box is just a name for the server's Tailscale IP. The server keeps its existing owner and every rule that already applied to it.

The OIDC subject trap

This one is easy to get wrong. When a job uses environment: qa, the subject of GitHub's OIDC token is:

repo:<owner>/<repo>:environment:qa 

It is not repo:<owner>/<repo>:ref:refs/heads/main, even though the job only runs on main. The Tailscale trust credential has to match the subject exactly, or the token is rejected. The credential also needs the Auth Keys write scope and the tag:ci tag, so it can create the ephemeral node.

The GitHub Actions job

This is the final version of the job. It runs after the build job (lint, typecheck, build) passes.

deploy-qa: name: Deploy to QA needs: build # only after lint/typecheck/build pass  if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest environment: name: qa concurrency: group: qa-deploy cancel-in-progress: false # a second merge waits, then deploys the newer commit  permissions: contents: read id-token: write # Tailscale workload identity federation (OIDC)  env: QA_HOST: ${{ vars.QA_HOST }} QA_SSH_PORT: ${{ vars.QA_SSH_PORT }} QA_SSH_USER: ${{ vars.QA_SSH_USER }} QA_APP_PATH: ${{ vars.QA_APP_PATH }} QA_HTTP_PORT: ${{ vars.QA_HTTP_PORT }} QA_COMPOSE_PROJECT: ${{ vars.QA_COMPOSE_PROJECT }} DEPLOY_SHA: ${{ github.sha }} steps: - uses: actions/checkout@v7 with: fetch-depth: 0 # full history, so the push below is not shallow  - name: Check QA settings run: | fail() { echo "::error::$1"; exit 1; } [[ "$QA_HOST" =~ ^[A-Za-z0-9.-]+$ ]] || fail "QA_HOST is missing or invalid" [[ "$QA_SSH_PORT" =~ ^[0-9]{1,5}$ ]] || fail "QA_SSH_PORT is missing or invalid" [[ "$QA_SSH_USER" =~ ^[a-z_][a-z0-9_-]{0,31}$ ]] || fail "QA_SSH_USER is missing or invalid" [[ "$QA_APP_PATH" =~ ^/[A-Za-z0-9._/-]+$ && "$QA_APP_PATH" != *..* ]] || fail "QA_APP_PATH is missing or invalid" [[ "$QA_HTTP_PORT" =~ ^[0-9]{4,5}$ ]] || fail "QA_HTTP_PORT is missing or invalid" [[ "$QA_COMPOSE_PROJECT" =~ ^[a-z0-9][a-z0-9_-]{0,62}$ ]] || fail "QA_COMPOSE_PROJECT is missing or invalid" [[ "$DEPLOY_SHA" =~ ^[0-9a-f]{40}$ ]] || fail "Unexpected commit SHA" - name: Join the tailnet uses: tailscale/github-action@v4 with: oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} audience: ${{ secrets.TS_AUDIENCE }} tags: tag:ci ping: ${{ vars.QA_HOST }} # wait until the server can see the new node  - name: Set up SSH env: SSH_KEY: ${{ secrets.QA_SSH_PRIVATE_KEY }} KNOWN_HOSTS: ${{ secrets.QA_SSH_KNOWN_HOSTS }} run: | install -m 700 -d ~/.ssh printf '%s\n' "$SSH_KEY" > ~/.ssh/qa_deploy chmod 600 ~/.ssh/qa_deploy printf '%s\n' "$KNOWN_HOSTS" > ~/.ssh/known_hosts - name: Push the commit to QA run: | GIT_SSH_COMMAND="ssh -i $HOME/.ssh/qa_deploy -p $QA_SSH_PORT -o StrictHostKeyChecking=yes -o BatchMode=yes" \ git push --force "$QA_SSH_USER@$QA_HOST:$QA_APP_PATH" "${DEPLOY_SHA}:refs/qa/deploy" - name: Deploy id: deploy run: | ssh -i ~/.ssh/qa_deploy -p "$QA_SSH_PORT" -o StrictHostKeyChecking=yes -o BatchMode=yes \ "$QA_SSH_USER@$QA_HOST" \ "bash -s -- '$QA_APP_PATH' '$DEPLOY_SHA' '$QA_HTTP_PORT' '$QA_COMPOSE_PROJECT'" \ < scripts/deploy-qa.sh - name: Show QA logs on failure if: failure() && steps.deploy.outcome == 'failure' run: | ssh -i ~/.ssh/qa_deploy -p "$QA_SSH_PORT" -o StrictHostKeyChecking=yes -o BatchMode=yes \ "$QA_SSH_USER@$QA_HOST" \ "cd '$QA_APP_PATH' && docker compose -p '$QA_COMPOSE_PROJECT' logs --tail 100" || true - name: Remove SSH key if: always() run: rm -rf ~/.ssh 

The concurrency group means two merges close together never deploy at the same time. The second run waits for the first, then deploys its own, newer commit. The "Show QA logs" step only runs when the deploy step itself failed, so a failed deploy shows the container's last 100 log lines right in the job output.

Keep ${{ }} out of run: blocks

There isn't a single ${{ }} inside a run: block. Every GitHub value goes into env: first and is used as "$VAR".

The reason: GitHub replaces ${{ }} by pasting the value into the script text before the shell runs it. If a value contains a quote, a semicolon or $(...), it stops being data and becomes part of the script. Through env:, the value reaches the shell as a variable, and quoting keeps it as one string.

On top of that, every value is checked against a strict regex in the "Check QA settings" step. The deploy script runs the same checks again on the server. Being careful twice costs a few lines.

Check host keys

Every SSH call uses StrictHostKeyChecking=yes, with the server's key in a known_hosts secret. Plenty of examples online use StrictHostKeyChecking=no to make the error go away. That turns off the one check that proves you're talking to your server.

My production workflow had the same problem. I fixed it there afterwards.

The deploy script

These are the key parts of scripts/deploy-qa.sh:

#!/usr/bin/env bash # Run on the QA server. The server hosts other apps: touch only <app_path> and <compose_project>. set -euo pipefail app_path=$1 sha=$2 host_port=$3 project=$4 # ...same regex checks as the runner... cd "$app_path" # The workflow pushes the commit to refs/qa/deploy first; fetch origin only if it is still missing. if ! git cat-file -e "$sha^{commit}" 2>/dev/null; then git fetch --prune origin git cat-file -e "$sha^{commit}" 2>/dev/null || { echo "Commit $sha not found after fetch" >&2; exit 67; } fi # Stop before touching anything if another project or container holds the port. others=$(docker ps --filter "publish=$host_port" --format '{{.Label "com.docker.compose.project"}}|{{.Names}}' | awk -F'|' -v p="$project" '$1 != p { print $2 " (project " ($1 == "" ? "none" : $1) ")" }') if [ -n "$others" ]; then echo "Port $host_port is already used by: $others" >&2 exit 68 fi # Build exactly the commit: drop local edits, keep an optional .env. git reset --hard --quiet git clean -fdx --quiet -e .env git checkout --quiet --detach "$sha" export HOST_PORT=$host_port docker compose -p "$project" up -d --build --wait --wait-timeout 120 --remove-orphans curl -fsS -o /dev/null "http://127.0.0.1:$host_port/" echo "QA is up: $(git rev-parse --short HEAD) on port $host_port" 

And the port line in compose.yaml:

ports: ["${HOST_BIND:-0.0.0.0}:${HOST_PORT:-7500}:80"] 

With no env vars set, local docker compose up still works and the site is on port 7500. The deploy script sets HOST_PORT from the Environment.

A few things about the script:

  • It only touches its own folder and its own compose project. git reset and git clean run inside /srv/apps/my-site. Compose runs with -p "$project", so --remove-orphans can only remove orphans of this project.
  • The port check runs before anything changes. If any container outside this project already publishes the port, the script stops with exit code 68 and names the container. More on why this exists below.
  • It builds exactly the commit. Local edits are dropped, untracked files are removed, and an optional .env survives. The checkout is detached at the SHA, not at a branch that might have moved. ### Failing safely with --wait

--wait makes Compose wait until the container's HEALTHCHECK (defined in the image) reports healthy. If the new image fails to build, or the new container never becomes healthy within 120 seconds, the command fails and the job fails.

The important part is what happens to the running site. Compose only replaces the old container once the new image is built. A broken build never gets as far as stopping the old container, so the old container keeps serving. The curl at the end is a last check that something actually answers on the port.

Testing it before the first real deploy

I tested the script locally before letting CI run it against the server:

  • Bad inputs were refused. '/tmp/x; echo pwned' as the path, HEAD as the SHA, and port 80 all failed the checks.
  • A deploy to a throwaway clone with a local edit dropped the edit but kept .env.
  • A commit with RUN false in the Dockerfile made the deploy fail, while the old container kept answering 200. ## What went wrong on the first real deploys

The plan had assumed four things that turned out to be wrong. Each failure stopped safely, and the running QA container was never touched. Here they are in the order I hit them.

1. QA_HOST is missing or invalid

I had forgotten to set one variable. The "Check QA settings" step stopped the job before it even joined the tailnet.

This is why the validation step comes first. The job failed in 6 seconds with a message that said exactly what was wrong. Without it, the same mistake would have surfaced later as a confusing SSH or Tailscale error with an empty hostname somewhere in it.

2. A fingerprint is not a known_hosts line

The next run got onto the tailnet and failed at SSH:

No ED25519 host key is known for qa-box.tailXXXX.ts.net and you have requested strict checking. 

The QA_SSH_KNOWN_HOSTS secret didn't hold a key line. I had pasted the key's fingerprint, which looks like this:

256 SHA256:... (ED25519) 

known_hosts wants the full public key line, the kind ssh-keyscan prints:

qa-box.tailXXXX.ts.net ssh-ed25519 AAAA... 

There's a second catch. The name at the start of the line must match QA_HOST exactly. With MagicDNS, qa-box and qa-box.tailXXXX.ts.net both resolve to the same machine, but to SSH they're different entries. If QA_HOST is the full name, the line must start with the full name.

The two key pairs are easy to mix up:

Server's ID card Runner's door key
Proves "I really am the server" "I'm allowed in"
Comes from /etc/ssh/ssh_host_ed25519_key.pub on the server a new key pair made only for deploys
GitHub secret QA_SSH_KNOWN_HOSTS (public line) QA_SSH_PRIVATE_KEY (private half)
Other half — server's ~/.ssh/authorized_keys

To build the known_hosts line, run ssh-keyscan from a machine on the tailnet:

ssh-keyscan -t ed25519 qa-box.tailXXXX.ts.net 

Then check that the fingerprint matches on the server itself:

# On the server ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub 

ssh-keyscan trusts whatever answers on that name and port. Comparing against the file on the server is what makes the line trustworthy.

For the door key, make a new key pair just for deploys. Don't reuse your laptop's personal key. If the deploy key ever leaks, you remove one line from the deploy user's authorized_keys and nothing else changes.

3. Three problems I found by looking at the server

Before the next attempt, I SSHed into the server and looked at how things were actually wired. I found three more problems, all of the "worked on my machine" kind.

cloudflared runs in a container, not on the host. My plan bound QA to 127.0.0.1, so it would only be reachable through the tunnel. But cloudflared on this box runs as a Docker container in its own network. Inside a container, 127.0.0.1 is the container itself, not the host. The tunnel would have got a 502.

Every other app on the server listens on 0.0.0.0:<port>, and the tunnel reaches them through the host's LAN IP. I switched QA to the same pattern: it binds to 0.0.0.0:7500, and the tunnel's route for the QA hostname points at http://192.168.1.50:7500. The trade-off is that QA is also reachable on my LAN. For a home network I accepted that. That's also why the bind address is a variable (HOST_BIND) in compose.yaml.

The port was already taken. Weeks earlier I had started a copy of the same site by hand, from the same folder, under a different compose project name. It was sitting on the port QA wanted.

The server couldn't get the commit. The plan had the server's clone run git fetch to get the commit being deployed. But the GitHub repo is private, and the server has no GitHub credentials. A git fetch would never have found the commit.

I didn't want to add a GitHub key to the server just for this. The runner already has an SSH connection to the server and the full repo. So it now pushes the exact commit to a private ref before deploying:

git push --force "$QA_SSH_USER@$QA_HOST:$QA_APP_PATH" "${DEPLOY_SHA}:refs/qa/deploy" 

The ref lives under refs/qa/, so it never shows up as a branch and never conflicts with your real branches. It needs fetch-depth: 0 on checkout, because git won't push from a shallow clone into a repository that doesn't already have the missing history. The script still falls back to git fetch origin if the commit is missing. The server never needs credentials for GitHub.

A small zsh trap while testing locally. I first wrote the refspec as "$SHA:refs/qa/deploy". In zsh, that lost its :r. :r is a zsh history modifier ("remove extension"), so zsh read $SHA:r as one expansion and left efs/qa/deploy behind it. Bash on the runner doesn't do this, but "${SHA}:refs/qa/deploy" is safe in both. Braces around variables next to a colon are a good habit anyway.

4. Bind for 0.0.0.0:7500 failed: port is already allocated

After the first good deploy, I renamed the compose project in the GitHub Environment and re-ran the job. That was a mistake.

Compose doesn't know a project was renamed. It saw a brand-new project and tried to start a second container on the same port, next to the old one. The site stayed up, because the old container kept serving, but the deploy failed after a full image build.

The fix was to put the old name back and remove the half-made project (docker compose -p <new-name> down). It also led to the early port check in the script. Now, if anything outside the current project holds the port, the script stops before building and says which container is in the way. It refuses in 0 seconds instead of failing after a build.

The lesson for me: the compose project name is part of the app's identity on the server, like its folder and its port. Changing it is a migration, not a setting tweak.

5. "This workflow run cannot be retried"

GitHub showed me this message during the fixes. It's also worth knowing what a re-run does: it uses the workflow file from the original commit, not the latest one. So after fixing the workflow itself, re-running an old failed run tests the old workflow.

What you want is a new run on the latest commit:

gh workflow run CI --ref main 

What I'd do differently

  • Look at the server before writing the plan. docker ps, the networks containers are on, the ports they publish, and where cloudflared runs. Three of my four wrong assumptions would have shown up there.
  • Treat isolation on a shared server as my job. One folder, one compose project name, one port per app. And never a global docker system prune on a box with 40 other containers.
  • Restrict the CI node on the tailnet from day one. Tag it, grant one host and one port, and write policy tests that prove it. Then check the tailnet doesn't still have the default allow-all rule.
  • Remember that GitHub Environments change the OIDC subject. With environment: qa, the subject ends in environment:qa, not the branch ref. The trust credential must match exactly.
  • Put the key line in known_hosts, not the fingerprint. And make the hostname at the start of the line match QA_HOST exactly.
  • Validate every input before it reaches a shell, and keep ${{ }} out of run:. Validating first also gives you fast, readable failures.
  • Design deploys to fail safely. Through every failure in this post, the old QA container kept serving. That's what made it fine to learn by breaking things.