Loading…
Loading documentation...
Automate builds, tests, and deployments with CI/CD best practices.
Automate building, testing and deploying your application to a Servers Are Up server using GitHub Actions.
This tutorial sets up a pipeline that:
maindeploy user, the nextjs service and /home/deploy/deploy.shOn your own computer, generate a key used only for deployments:
ssh-keygen -t ed25519 -C "github-deploy" -f deploy_key -N ""
On the server, in the root shell from How to connect and sudo -i, let that key sign in as deploy. Paste the whole line of deploy_key.pub in place of PUBLIC_KEY_LINE:
install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
echo 'PUBLIC_KEY_LINE' >> /home/deploy/.ssh/authorized_keys
chown deploy:deploy /home/deploy/.ssh/authorized_keys
chmod 600 /home/deploy/.ssh/authorized_keys
In your GitHub repository, go to Settings > Secrets and variables > Actions and add:
| Secret | Value |
|---|---|
DEPLOY_SSH_KEY |
Contents of deploy_key (the private key) |
DEPLOY_HOST |
The address in the server's How to connect command |
DEPLOY_PORT |
The port in that command (after -p) |
DEPLOY_USER |
deploy |
Create .github/workflows/deploy.yml:
name: Build & Deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm test
- run: npm run lint
build-and-deploy:
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run build
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: /home/deploy/deploy.sh
The build on GitHub catches a broken build before it reaches the server; the server builds again in deploy.sh, from the same commit.
If your app ships as a Docker image, install Docker on the server (apt update && apt install -y docker.io, then usermod -aG docker deploy), log the server in to your registry once, and deploy the image instead:
build-and-push:
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and push Docker image
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login your-registry -u "${{ secrets.REGISTRY_USER }}" --password-stdin
docker build -t your-registry/app:${{ github.sha }} .
docker push your-registry/app:${{ github.sha }}
- name: Deploy container
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
docker pull your-registry/app:${{ github.sha }}
docker stop app || true
docker rm app || true
docker run -d --name app --restart unless-stopped -p 3000:3000 \
--env-file /home/deploy/.env \
your-registry/app:${{ github.sha }}
The container listens on port 3000, so the forward from Deploy Next.js keeps working.
Add a final step to the deploy job to notify your team:
- name: Notify deployment
if: success()
run: |
curl -X POST "${{ secrets.WEBHOOK_URL }}" \
-H 'Content-Type: application/json' \
-d '{"text": "Deployed commit ${{ github.sha }} to production"}'
@v4)deploy.sh exits at the first failing step and restarts nothingOpen the workspace to check your machine’s connection and available controls. For automation, consult the REST API or MCP guide. Include the resource and region when you contact support.