Skip
Arish's avatar

2. CI/CD Pipeline Architecture


Pipeline Structure

yaml
1Stages:
2  1. Setup       → Install Ruby, dependencies
3  2. Test        → RSpec, Minitest
4  3. Lint        → RuboCop, ESLint
5  4. Security    → Brakeman, Bundler Audit
6  5. Build       → Docker image
7  6. Deploy      → Staging → Production

Parallel vs Sequential

yaml
1# Sequential (slower)
2test → lint → security → build → deploy
3
4# Parallel (faster)
5┌─ test ────┐
6├─ lint ────┼─→ build → deploy
7└─ security ┘

Environment Strategy

feature/* → Run tests only develop → Tests + Deploy to staging main → Tests + Deploy to production

Rails Pipeline Example

yaml
1name: CI/CD
2
3on:
4  push:
5    branches: [main, develop]
6  pull_request:
7    branches: [main]
8
9jobs:
10  test:
11    runs-on: ubuntu-latest
12    steps:
13      - uses: actions/checkout@v4
14      - name: Setup Ruby
15        uses: ruby/setup-ruby@v1
16      - name: Run tests
17        run: bundle exec rspec
18
19  deploy:
20    needs: test
21    if: github.ref == 'refs/heads/main'
22    runs-on: ubuntu-latest
23    steps:
24      - name: Deploy to production
25        run: ./deploy.sh