How to Separate Open-Source Code from Production Deployment with GitHub Actions
A practical walkthrough of using two GitHub repositories, repository dispatch events, SSH, and Docker Compose to deploy a self-hosted application.
I had a bunch of GitHub Actions workflows in the Radiant repository that really had nothing to do with running Radiant on someone else’s machine. They were there to update my server, check on things, and help me troubleshoot deployment problems. Since I’d like other people to be able to use the application, I decided to move most of that stuff into a separate repository.
Radiant is an application I’ve been developing to help manage KAAD-LP 103.5 FM, a community radio station in Sonora, California. It deals with the programming schedule, logs of what aired, and publishing information to the station website. It’s separate from the actual audio streaming setup, which uses Liquidsoap (for routing and processing audio) and Icecast (for serving audio to internet listeners). I’ve written a bit about both the streaming setup and the automation of song metadata previously.
Radiant runs in Docker Compose and consists of a Node.js API, a React admin interface, PostgreSQL and Directus. For the purposes of this tutorial, though, it could be just about any application you maintain in GitHub and run on your own Linux server.
What I wanted to accomplish
GitHub Actions is GitHub’s automation service. It can run instructions when something happens in a repository, such as a push to the main branch.
I wanted to retain the ability to merge a PR and have the updated application running on my virtual private server (VPS) without having to log in and do it myself. The public repository now just sends a notification, and the private repository does the actual work over SSH.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Public application repository
|
| Push to main
v
GitHub Actions notification
|
| repository_dispatch
v
Private deployment repository
|
| SSH
v
Production server
|
+-- Update source code
+-- Build application images
+-- Restart application containers
+-- Check application health
I initially had the private repository polling the public one, but there wasn’t much point in doing that when GitHub could just send an event every time I pushed a change.
I’m assuming you already have an application in GitHub and a working installation on your server. The server-side examples assume Git, SSH, Docker and Docker Compose are configured and that the deployment account has the necessary permissions.
Step 1: Separate the repositories
I use the following division of responsibilities:
| Repository | Contents |
|---|---|
| radiant (public) | Application source, Docker Compose configuration, migrations, documentation, and general automated tests |
| radiant-deploy (private) | Production deployment workflows and references to deployment secrets |
I created a new private repository, radiant-deploy, for this. There isn’t a second copy of Radiant in that repository; the server still pulls code directly from radiant.
The application repository should still contain everything another person needs to install and run the application independently.
Step 2: Configure the credentials
GitHub’s repository dispatch API lets one repository send a custom event to another. The default Actions token is generally scoped to the repository running the workflow, so for this setup I use a fine-grained personal access token.
Create a token scoped to the private deployment repository with Contents read/write permission, as required by the repository dispatch API. Store it in the public application’s repository under Settings → Secrets and variables → Actions, for example as DEPLOY_DISPATCH_TOKEN.
I keep the production SSH credentials in the private repository’s Actions secrets. Typical values include the server hostname, deployment username, private SSH key, and a verified SSH host key or known_hosts entry.
Keep the application’s runtime configuration on the server. Never commit tokens, private keys, or passwords to either repository.
Step 3: Send an event when the application changes
In the public repository, create a file such as .github/workflows/notify-private-deploy.yml. Here’s a stripped-down version of the workflow:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
name: Notify deployment
on:
push:
branches: [main]
permissions: {}
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Notify private repository
env:
GH_TOKEN: $
TARGET_REPO: YOUR_OWNER/YOUR_DEPLOY_REPO
SOURCE_SHA: $
run: |
gh api --method POST "repos/$TARGET_REPO/dispatches" \
-f event_type=radiant-main-updated \
-f "client_payload[sha]=$SOURCE_SHA"
Replace YOUR_OWNER/YOUR_DEPLOY_REPO with the actual private repository name. The GitHub CLI (gh) sends the event along with the commit identifier, which is useful for tracing a deployment back to a change.
See Radiant’s notification workflow for the project’s implementation.
This notification is the remaining installation-specific piece in the public project. Someone cloning Radiant for their own station can remove or replace it. Without the configured secret, a push-triggered notification may fail, but it is not needed to run the application.
Step 4: Receive the event in the private repository
Create a workflow under .github/workflows/ in the private repository. Its triggers can look like this:
1
2
3
4
5
6
7
8
9
10
name: Deploy application
on:
repository_dispatch:
types: [radiant-main-updated]
workflow_dispatch:
concurrency:
group: production-deploy
cancel-in-progress: false
The event type must match the one sent by the public repository. The workflow must exist on the private repository’s default branch for repository dispatch to trigger it.
I also wanted to be able to run this manually, hence the workflow_dispatch trigger. In my actual deployment workflow, I also have a dry-run input that defaults to true for manual runs, allowing me to inspect the server without updating it.
The concurrency setting helps avoid overlapping production deployments.
Next, add a job that establishes a verified SSH connection to the server and runs your deployment commands. Configure SSH host-key verification rather than disabling it. The private repository is responsible for this connection; the public repository does not need your production SSH key.
Step 5: Update the application on the server
Once connected to the server, this is essentially what I need to do to update Radiant (change the path and service names to suit your application):
1
2
3
4
5
6
7
8
9
10
set -euo pipefail
cd /path/to/radiant
git fetch origin main
git switch main
git merge --ff-only origin/main
docker compose build radiant-api radiant-admin
docker compose up -d --no-deps radiant-api
docker compose up -d --no-deps radiant-admin
A fast-forward-only merge avoids automatically creating a merge commit or force-resetting the server’s checkout. In production, also explicitly check that the working tree is clean before starting the update.
Docker Compose manages the application’s containers. In this example, the new application images are built while the existing containers are still running. Only the API and administration containers are recreated; PostgreSQL and Directus remain running.
These commands illustrate the application-specific part of the deployment rather than a complete turnkey SSH workflow.
Step 6: Verify the deployment
After restarting the containers, check that the application endpoints respond. For example, if your API exposes a health endpoint, you could use:
1
2
3
curl --fail --silent --show-error \
--retry 12 --retry-connrefused --retry-delay 5 \
https://your-app.example/api/health
Use your actual health endpoint and add a corresponding check for the administration interface. Only record the commit as successfully deployed after the checks pass.
In Radiant’s implementation, the server records the successfully deployed commit. If another event arrives and that commit is already running, the workflow can skip an unnecessary rebuild. A manual run can retry a failed deployment.
Test the private workflow manually first, then push a small change to the public main branch. Verify that the notification succeeds, the private workflow runs, and the application actually behaves as expected.
A few caveats
The notification contains the triggering commit SHA, but my deployment fetches the latest main branch when it runs. This is not an immutable release system. If you need to deploy exactly the artifact associated with each event, you’ll need a different checkout or image-tagging strategy.
This is also not a zero-downtime setup. Recreating containers may briefly interrupt service, and health checks do not automatically roll back a failed deployment.
Finally, the dispatch token can indirectly initiate a production deployment. Protect the main branch and workflow files, limit access to credentials, remove obsolete secrets, and rotate any credentials that may have been exposed. Deleting a file does not remove its contents from Git history.
Cleaning up
Once I had a successful deployment on November 24, I went back and removed the old workflows from the public repository. I left the general application CI (the automated code checks) in place. If you’re migrating an existing setup, don’t forget to remove the old deployment secrets as well once you’ve confirmed you no longer need them.
Much of this work was implemented collaboratively with ChatGPT. If you’re interested in what that experience was like, rather than the deployment mechanics, I’ve written a companion reflection.