Home Projects Services Blog Contact
Back to Blog

Article

Subtitle

TL;DR

Summary

What is CI/CD?

CI (Continuous Integration): every time you push code, it's automatically tested. CD (Continuous Deployment): when tests pass, it's automatically deployed. Together, they make "push and forget" possible.

Companies like Google deploy to production hundreds of times per day. CI/CD is what makes that possible without chaos.

Why GitHub Actions?

GitHub Actions is free for public repos and generous for private ones. It's built into GitHub — no external tools needed. You just add a YAML file and it works.

Your First Workflow

.github/workflows/test.yml
name: Test & Deploy

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      
      - name: Install dependencies
        run: |
          pip install -r requirements.txt
      
      - name: Run tests
        run: |
          python manage.py test
      
      - name: Check code style
        run: |
          pip install flake8
          flake8 . --max-line-length=100

Auto-Deploy After Tests Pass

.github/workflows/deploy.yml
  deploy:
    needs: test  # Only runs if tests pass
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Deploy to VPS via SSH
        uses: appleboy/ssh-action@v1.0.0
        with:
          host: ${{ secrets.VPS_HOST }}
          username: ${{ secrets.VPS_USER }}
          key: ${{ secrets.VPS_SSH_KEY }}
          script: |
            cd /home/ubuntu/myapp
            git pull origin main
            docker compose build --no-cache
            docker compose up -d

Store sensitive data (SSH keys, passwords, API tokens) as GitHub Secrets — Settings → Secrets. Never hardcode them in your YAML files.

What to Add Next

  1. Add test coverage reports with pytest-cov
  2. Push Docker image to Docker Hub or GitHub Container Registry
  3. Add Slack/Telegram notification on deployment success or failure
  4. Create a staging environment that auto-deploys on PR merge
  5. Add automatic rollback if health check fails after deploy

Why This Changes Everything

With CI/CD, you spend less time on manual tasks and more time building. Every push is tested. Every deployment is reproducible. Errors are caught before they reach users. This is how professional teams work.

Tous les articles Article suivant