โš™๏ธ

CI/CD with GitHub Actions

๐Ÿ‘จโ€๐Ÿณ Chefโฑ๏ธ 30 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขGitHub repo
  • โ€ขDocker deploy

What you'll build

A CI/CD pipeline that automatically runs your tests and deploys your application every time you push to the main branch. You'll configure a GitHub Actions workflow that runs on GitHub servers, executes your test suite, builds the Docker image, and deploys it to your VPS via SSH. When finished, you'll have automatic and reliable deploys where you only need to git push to see your changes in production.


Step 1: Ask an AI for the workflow

I need a GitHub Actions workflow that:
- Runs on push to main
- Runs tests
- Docker build
- Deploy to VPS via SSH
- Notify on Slack if fails

Give me the complete .yml file.

Workflow

# .github/workflows/deploy.yml
name: Deploy

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci && npm test

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Deploy
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.HOST }}
          username: ${{ secrets.USER }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /app
            git pull
            docker compose up -d --build

Required secrets

  • HOST: Server IP
  • USER: SSH user
  • SSH_KEY: Private key

Next step

โ†’ API Testing