This tutorial shows you how to set up a CI/CD pipeline in OpenCodeHub to deploy your application automatically when code is pushed.
We will use GitHub Actions syntax, which OpenCodeHub supports via its integrated runner system.
We have a Node.js web app. We want to:
- Run tests on every push.
- If tests pass on
main, deploy to a production server via SSH.
Create a file named .github/workflows/deploy.yml in your repository.
name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ${{ secrets.PROD_USER }}
key: ${{ secrets.PROD_SSH_KEY }}
script: |
cd /var/www/myapp
git pull origin main
npm install
pm2 restart myappYour workflow needs access to your production server credentials. Never commit these to code!
- Go to Repository Settings > Secrets.
- Add the following secrets:
PROD_HOST: Your server IP (e.g.,1.2.3.4).PROD_USER: SSH username (e.g.,ubuntu).PROD_SSH_KEY: Your private SSH key content.
- Commit and push the workflow file.
- Navigate to the Actions tab in your repository.
- You should see a new workflow run named "CI/CD Pipeline".
- Click on it to see the live logs of the
testanddeployjobs.
- "Runner not found": Ensure you have at least one runner connected to your instance (see Runner Setup).
- SSH Failures: Verify your
PROD_SSH_KEYmatches the public key in~/.ssh/authorized_keyson the target server.