CI/CD Pipeline Kurulumu ve Best Practices

Teknoloji 📖 2 dk okuma
#kariyer#web

CI/CD, modern yazılım geliştirme sürecinin omurgasıdır.

GitHub Actions Example

name: CI/CD Pipeline

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

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci
      
      - name: Run tests
        run: npm test
      
      - name: Run linter
        run: npm run lint

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Build
        run: npm run build
      
      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: dist
          path: dist/

  deploy:
    needs: build
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v3
      
      - name: Deploy to production
        run: |
          echo "Deploying to production..."
          # Deployment script

GitLab CI

stages:
  - test
  - build
  - deploy

test:
  stage: test
  script:
    - npm ci
    - npm test
  cache:
    paths:
      - node_modules/

build:
  stage: build
  script:
    - npm run build
  artifacts:
    paths:
      - dist/

deploy:
  stage: deploy
  script:
    - ./deploy.sh
  only:
    - main
  environment:
    name: production

Best Practices

1. Fast Feedback

# Parallel jobs
jobs:
  lint:
    runs-on: ubuntu-latest
  test:
    runs-on: ubuntu-latest
  typecheck:
    runs-on: ubuntu-latest

2. Caching

- uses: actions/cache@v3
  with:
    path: ~/.npm
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

3. Security Scanning

- name: Security audit
  run: npm audit --production

4. Automated Testing

  • Unit tests
  • Integration tests
  • E2E tests
  • Performance tests

Docker Integration

- name: Build Docker image
  run: docker build -t myapp:${{ github.sha }} .

- name: Push to registry
  run: docker push myapp:${{ github.sha }}

CI/CD ile güvenli ve hızlı deployment!