Deploy React app via GitHub Actions
Setup app on VPS
- Login to root account.
- Download the script.
curl -sSL https://kb.subratlima.com/scripts/vps/setup_app -o setup_app
chmod +x setup_app
- Run the script, example given below.
./setup_app "kb"
# where
# kb : app/user name
Add Secret keys
- Open the GitHub repo page.
- Goto
Project > Settings > Security > Secrets and variables > Actions. - Add the following secret keys in
New Repository secret.
| name | secret |
|---|---|
| VPS_IP | server ip |
| VPS_USERNAME | server login username |
| VPS_PRIVATE_KEY | server user ssh private key |
| VPS_APP_DIR | server application dir |
Create the GitHub workflow
Create the workflow file .github/workflows/deploy.yml.
React App workflow
name: Build and Deploy
on:
push:
branches: [main] # branch name
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v6
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'pnpm'
- name: Install Dependencies
run: pnpm install --frozen-lockfile
- name: Build Project
run: pnpm run build # This generates the dist folder
- name: Copy Dist to VPS
uses: appleboy/scp-action@master
with:
port: 22 # SSH port
source: "dist/*" # Path to the dist files
host: ${{ secrets.VPS_IP }} # Your VPS IP
username: ${{ secrets.VPS_USERNAME }} # Your VPS username
key: ${{ secrets.VPS_PRIVATE_KEY }} # Your SSH private key
target: ${{ secrets.VPS_APP_DIR }} # Destination on your VPS
strip_components: 1
Push changes to GitHub
Add the workflow, commit and push to GitHub.
Add website to caddy on VPS
- Login again to root account.
- Download the script.
curl -sSL https://kb.subratlima.com/scripts/vps/caddy_static -o caddy_static
chmod +x caddy_static
- Run the script, example given below.
./caddy_static "kb.subratlima.com" "kb"
# where
# kb.subratlima.com : domain name
# kb : app/user name
Your app should now auto deploy the updates.