1+ name : CI/CD Pipeline
2+
3+ on :
4+ push :
5+ branches : [ main, master, develop ]
6+ pull_request :
7+ branches : [ main, master ]
8+
9+ env :
10+ RUBY_VERSION : ' 3.2.0'
11+ BUNDLE_PATH : vendor/bundle
12+
13+ jobs :
14+ test :
15+ name : Test Suite
16+ runs-on : ubuntu-latest
17+
18+ services :
19+ prometheus :
20+ image : prom/prometheus:latest
21+ ports :
22+ - 9090:9090
23+
24+ steps :
25+ - name : Checkout code
26+ uses : actions/checkout@v4
27+
28+ - name : Set up Ruby
29+ uses : ruby/setup-ruby@v1
30+ with :
31+ ruby-version : ${{ env.RUBY_VERSION }}
32+ bundler-cache : true
33+
34+ - name : Install dependencies
35+ run : |
36+ bundle config path vendor/bundle
37+ bundle install --jobs 4 --retry 3
38+
39+ - name : Run RuboCop
40+ run : bundle exec rubocop
41+
42+ - name : Run RSpec tests
43+ run : bundle exec rspec --format documentation
44+
45+ - name : Upload coverage reports
46+ uses : codecov/codecov-action@v3
47+ if : success()
48+ with :
49+ file : ./coverage/lcov.info
50+ flags : unittests
51+ name : codecov-umbrella
52+
53+ security :
54+ name : Security Scan
55+ runs-on : ubuntu-latest
56+
57+ steps :
58+ - name : Checkout code
59+ uses : actions/checkout@v4
60+
61+ - name : Set up Ruby
62+ uses : ruby/setup-ruby@v1
63+ with :
64+ ruby-version : ${{ env.RUBY_VERSION }}
65+ bundler-cache : true
66+
67+ - name : Run security audit
68+ run : |
69+ bundle audit --update
70+ bundle exec brakeman --no-pager
71+
72+ build :
73+ name : Build Docker Image
74+ runs-on : ubuntu-latest
75+ needs : [test, security]
76+ if : github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
77+
78+ steps :
79+ - name : Checkout code
80+ uses : actions/checkout@v4
81+
82+ - name : Set up Docker Buildx
83+ uses : docker/setup-buildx-action@v3
84+
85+ - name : Login to Container Registry
86+ uses : docker/login-action@v3
87+ with :
88+ registry : quay.io
89+ username : ${{ secrets.QUAY_USERNAME }}
90+ password : ${{ secrets.QUAY_TOKEN }}
91+
92+ - name : Extract metadata
93+ id : meta
94+ uses : docker/metadata-action@v5
95+ with :
96+ images : quay.io/dkirwan/asset_monitoring
97+ tags : |
98+ type=ref,event=branch
99+ type=ref,event=pr
100+ type=sha,prefix={{branch}}-
101+ type=raw,value=latest,enable={{is_default_branch}}
102+
103+ - name : Build and push Docker image
104+ uses : docker/build-push-action@v5
105+ with :
106+ context : .
107+ platforms : linux/amd64,linux/arm64
108+ push : true
109+ tags : ${{ steps.meta.outputs.tags }}
110+ labels : ${{ steps.meta.outputs.labels }}
111+ cache-from : type=gha
112+ cache-to : type=gha,mode=max
113+
114+ deploy :
115+ name : Deploy to Kubernetes
116+ runs-on : ubuntu-latest
117+ needs : [build]
118+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
119+ environment : production
120+
121+ steps :
122+ - name : Checkout code
123+ uses : actions/checkout@v4
124+
125+ - name : Configure kubectl
126+ uses : azure/k8s-set-context@v3
127+ with :
128+ method : kubeconfig
129+ kubeconfig : ${{ secrets.KUBE_CONFIG }}
130+
131+ - name : Deploy to Kubernetes
132+ run : |
133+ # Update image tag in deployment
134+ sed -i "s|quay.io/dkirwan/asset_monitoring:.*|quay.io/dkirwan/asset_monitoring:${GITHUB_SHA}|g" kubernetes/deployment.yaml
135+
136+ # Apply Kubernetes manifests
137+ kubectl apply -f kubernetes/
138+
139+ # Wait for deployment to be ready
140+ kubectl rollout status deployment/crypto -n monitoring-example --timeout=300s
0 commit comments