-
Notifications
You must be signed in to change notification settings - Fork 0
ci: production deploy job #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r1n04h
wants to merge
1
commit into
master
Choose a base branch
from
ci-deploy-job
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.3.14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| name: Deploy | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: [CI] | ||
| types: [completed] | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: deploy-production | ||
| cancel-in-progress: false | ||
|
|
||
| env: | ||
| DEPLOY_PATH: ${{ vars.DEPLOY_PATH || '/var/www/sparkhub' }} | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Deploy to VPS | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| if: > | ||
| github.event_name == 'workflow_dispatch' || | ||
| ( | ||
| github.event.workflow_run.conclusion == 'success' && | ||
| github.event.workflow_run.event == 'push' && | ||
| github.event.workflow_run.head_branch == 'master' | ||
| ) | ||
| steps: | ||
| - name: Checkout code at deployed revision | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
| with: | ||
| bun-version-file: .bun-version | ||
|
|
||
| - name: Build | ||
| run: | | ||
| bun install --frozen-lockfile | ||
| bun run build | ||
|
|
||
| - name: Prune to production dependencies | ||
| run: | | ||
| rm -rf node_modules | ||
| bun install --production --frozen-lockfile | ||
|
|
||
| - name: Deploy to VPS | ||
| env: | ||
| SSHPASS: ${{ secrets.SSH_PASSWORD }} | ||
| SSH_PORT: ${{ secrets.SSH_PORT || '22' }} | ||
| run: | | ||
| sudo apt-get update -qq | ||
| sudo apt-get install -y -qq sshpass rsync | ||
| SSH_OPTS="-p ${SSH_PORT} -o StrictHostKeyChecking=accept-new" | ||
| TARGET="${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}" | ||
|
|
||
| export RSYNC_RSH="ssh ${SSH_OPTS}" | ||
| sshpass -e rsync -avz --delete-delay --delay-updates \ | ||
| --exclude-from=deploy.exclude \ | ||
| ./ "${TARGET}:${DEPLOY_PATH}/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .git/ | ||
| .github/ | ||
| test/ | ||
| docs/ | ||
| *.sqlite | ||
| src/config.ts | ||
| src/config-server.ts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Production deployment | ||
|
|
||
| SparkHub deploys automatically when CI passes on a push to `master`. | ||
|
|
||
| ```text | ||
| push master → CI → GitHub Actions (install + build) → rsync to VPS → --watch reloads | ||
| ``` | ||
|
|
||
| The app is **built on GitHub Actions** (`bun install` + `bun run build`), then **rsynced in bulk** to the VPS (including `node_modules`). Server config files on the VPS are never overwritten (see `deploy.exclude`). The server runs **`bun run start:watch`** and reloads when rsync updates files. | ||
|
|
||
| ## One-time VPS setup | ||
|
|
||
| Git is not required on the server for deploys. | ||
|
|
||
| ### 1. Deploy user and directory | ||
|
|
||
| ```bash | ||
| sudo mkdir -p /var/www/sparkhub | ||
| sudo useradd --system --home-dir /var/www/sparkhub --shell /bin/bash deploy | ||
| sudo chown -R deploy:deploy /var/www/sparkhub | ||
| ``` | ||
|
|
||
| ### 2. Install Bun (as the deploy user) | ||
|
|
||
| ```bash | ||
| sudo -iu deploy bash -lc 'curl -fsSL https://bun.sh/install | bash' | ||
| ``` | ||
|
|
||
| Bun will install to `/var/www/sparkhub/.bun/bin/bun`. Verify: | ||
|
|
||
| ```bash | ||
| sudo -iu deploy bash -lc 'which bun && bun --version' | ||
| ``` | ||
|
|
||
| ### 3. Production configuration | ||
|
|
||
| Create config on the server before the first deploy (these paths are excluded from rsync): | ||
|
|
||
| ```bash | ||
| cd /var/www/sparkhub | ||
| mkdir -p src | ||
| # copy or create src/config.ts and src/config-server.ts | ||
| ``` | ||
|
|
||
| - `src/config.ts` — public domain | ||
| - `src/config-server.ts` — SQLite path, wallet seed, TLS cert paths | ||
|
|
||
| Ensure TLS certificate files exist at the paths referenced in `config-server.ts`. | ||
|
|
||
| Binding to port 443 usually requires: | ||
|
|
||
| ```bash | ||
| sudo setcap 'cap_net_bind_service=+ep' /var/www/sparkhub/.bun/bin/bun | ||
| ``` | ||
|
|
||
| ### 4. Keep the server running (pick one) | ||
|
|
||
| **Option A — PM2** | ||
|
|
||
| Run all of this as the `deploy` user (e.g. `sudo -iu deploy`): | ||
|
|
||
| ```bash | ||
| cd /var/www/sparkhub | ||
| pm2 start /var/www/sparkhub/.bun/bin/bun --name sparkhub -- run start:watch | ||
| pm2 save | ||
| pm2 startup # run the command it prints (as root) | ||
| ``` | ||
|
|
||
| **Option B — systemd** | ||
|
|
||
| ```bash | ||
| sudo tee /etc/systemd/system/sparkhub.service <<'EOF' | ||
| [Unit] | ||
| Description=SparkHub | ||
| After=network.target | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| User=deploy | ||
| WorkingDirectory=/var/www/sparkhub | ||
| Environment=HOME=/var/www/sparkhub | ||
| ExecStart=/var/www/sparkhub/.bun/bin/bun run start:watch | ||
| Restart=always | ||
| RestartSec=5 | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| sudo systemctl daemon-reload | ||
| sudo systemctl enable --now sparkhub | ||
| ``` | ||
|
|
||
| Adjust the `bun` path if needed (`sudo -iu deploy which bun`). | ||
|
|
||
| ### 5. First deploy | ||
|
|
||
| Merge this repo’s CD setup to `master`, add GitHub secrets (below), and let the **Deploy** workflow run. It will rsync the built app to the server. | ||
|
|
||
| If the app directory is empty, create `src/config.ts` and `src/config-server.ts` first, then run **Actions → Deploy → Run workflow**. | ||
|
|
||
| ### 6. SSH credentials for GitHub Actions | ||
|
|
||
| | Secret | Description | | ||
| |--------|-------------| | ||
| | `SSH_HOST` | VPS hostname or IP | | ||
| | `SSH_USER` | `deploy` | | ||
| | `SSH_PASSWORD` | Deploy user password | | ||
| | `SSH_PORT` | Optional; default `22` | | ||
|
|
||
| Optional repository **variables**: | ||
|
|
||
| | Variable | Default | | ||
| |----------|---------| | ||
| | `DEPLOY_PATH` | `/var/www/sparkhub` | | ||
|
|
||
| ### 7. Branch protection (recommended) | ||
|
|
||
| On `master`, require the **CI** workflow to pass before merge. | ||
|
|
||
| ## What gets synced | ||
|
|
||
| `deploy.exclude` keeps server-only files safe: | ||
|
|
||
| - `src/config.ts`, `src/config-server.ts` | ||
| - `.git/`, tests, docs, local SQLite files | ||
|
|
||
| ## Day-to-day operations | ||
|
|
||
| - **Deploy**: push to `master` (after CI passes) or **Actions → Deploy → Run workflow**. | ||
| - **Logs**: `pm2 logs sparkhub` or `journalctl -u sparkhub -f` | ||
| - **Rollback**: in **Actions → Deploy → Run workflow**, pick the branch or tag at the revision you want to ship. The workflow checks out the dispatched ref. For a fast revert, `git revert` and push to `master`. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Symptom | Check | | ||
| |---------|--------| | ||
| | Deploy workflow skipped | CI must pass on a **push** to `master`. | | ||
| | Config overwritten | Paths must stay listed in `deploy.exclude`. | | ||
| | Server did not reload | Process must use `bun run start:watch`. | | ||
| | `bun: command not found` | Bun not on deploy user `PATH`. | | ||
| | Permission denied on 443 | `setcap` on `bun` or reverse proxy on 443. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQLite WAL files unprotected from rsync deletion
Medium Severity
deploy.excludeonly excludes*.sqlite, but rsync with--delete-delayalso removes destination files that aren't present in the source and aren't covered by an exclude rule. SQLite's WAL mode produces*.sqlite-waland*.sqlite-shmcompanion files alongside the main database. Because those patterns are missing fromdeploy.exclude, every rsync deploy will delete them from the VPS if they exist, which can corrupt the live database mid-operation.Additional Locations (1)
.github/workflows/deploy.yml#L61-L64Reviewed by Cursor Bugbot for commit 0bf9dfa. Configure here.