Home / Market / ci setup

ci setup

ci-setup

claude-command★ 347020 dlgithubMITInstall in CosmosUpstream Source

Documentation & Preview

--- allowed-tools: Read, Write, Edit, Bash argument-hint: [platform] | --github-actions | --gitlab-ci | --jenkins | --full-setup description: Setup comprehensive CI/CD pipeline with automated testing, building, and deployment

---

CI/CD Pipeline Setup

Setup continuous integration pipeline: $ARGUMENTS

Current Project Analysis

Task

Implement comprehensive CI/CD following best practices: $ARGUMENTS

  1. Project Analysis
  1. CI/CD Platform Selection
  1. Repository Setup
  1. Build Pipeline Configuration

GitHub Actions Example:

   name: CI/CD Pipeline
   
   on:
     push:
       branches: [ main, develop ]
     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'
         - run: npm ci
         - run: npm run test
         - run: npm run build

GitLab CI Example:

   stages:
     - test
     - build
     - deploy
   
   test:
     stage: test
     script:
       - npm ci
       - npm run test
     cache:
       paths:
         - node_modules/
  1. Environment Configuration
  1. Automated Testing Integration

Multi-stage Testing:

   test:
     strategy:
       matrix:
         node-version: [16, 18, 20]
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v3
       - uses: actions/setup-node@v3
         with:
           node-version: ${{ matrix.node-version }}
       - run: npm ci
       - run: npm test
  1. Code Quality Gates
  1. Build Optimization

Caching Example:

   - name: Cache node modules
     uses: actions/cache@v3
     with:
       path: ~/.npm
       key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
       restore-keys: |
         ${{ runner.os }}-node-
  1. Docker Integration

Multi-stage Dockerfile:

   FROM node:18-alpine AS builder
   WORKDIR /app
   COPY package*.json ./
   RUN npm ci --only=production
   
   FROM node:18-alpine AS runtime
   WORKDIR /app
   COPY --from=builder /app/node_modules ./node_modules
   COPY . .
   EXPOSE 3000
   CMD ["npm", "start"]
  1. Deployment Strategies
  1. Infrastructure as Code
  1. Monitoring and Observability
  1. Security Integration

Security Scanning Example:

   security:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v3
       - name: Run Snyk to check for vulnerabilities
         uses: snyk/actions/node@master
         env:
           SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
  1. Database Migration Handling
  1. Performance Testing Integration
  1. Multi-Environment Deployment

Environment Deployment:

   deploy-staging:
     needs: test
     if: github.ref == 'refs/heads/develop'
     runs-on: ubuntu-latest
     steps:
       - name: Deploy to staging
         run: |
           # Deploy to staging environment
   
   deploy-production:
     needs: test
     if: github.ref == 'refs/heads/main'
     runs-on: ubuntu-latest
     environment: production
     steps:
       - name: Deploy to production
         run: |
           # Deploy to production environment
  1. Rollback and Recovery
  1. Notification and Reporting
  1. Compliance and Auditing
  1. Pipeline Optimization

Best Practices:

  1. Fail Fast: Implement early failure detection
  2. Parallel Execution: Run independent jobs in parallel
  3. Caching: Cache dependencies and build artifacts
  4. Security: Never expose secrets in logs
  5. Documentation: Document pipeline processes and procedures
  6. Monitoring: Monitor pipeline health and performance
  7. Testing: Test pipeline changes in feature branches
  8. Rollback: Always have a rollback strategy

Sample Complete Pipeline:

name: Full CI/CD Pipeline

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

jobs:
  lint-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
          cache: 'npm'
      - run: npm ci
      - run: npm run lint
      - run: npm run test:coverage
      - run: npm run build

  security-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Security scan
        run: npm audit --audit-level=high

  deploy-staging:
    needs: [lint-and-test, security-scan]
    if: github.ref == 'refs/heads/develop'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Deploy to staging
        run: echo "Deploying to staging"

  deploy-production:
    needs: [lint-and-test, security-scan]
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v3
      - name: Deploy to production
        run: echo "Deploying to production"

Start with basic CI and gradually add more sophisticated features as your team and project mature.