Skip to content

Commit 1da12fa

Browse files
committed
feat: add GitHub Actions CI/CD pipelines
1 parent 75180ac commit 1da12fa

2 files changed

Lines changed: 184 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
release:
7+
types: [ published ]
8+
9+
jobs:
10+
deploy-dev:
11+
name: Deploy to Dev
12+
runs-on: ubuntu-latest
13+
if: github.ref == 'refs/heads/main'
14+
environment: dev
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Configure AWS credentials
20+
uses: aws-actions/configure-aws-credentials@v4
21+
with:
22+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
23+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
24+
aws-region: us-east-1
25+
26+
- name: Update kubeconfig
27+
run: |
28+
aws eks update-kubeconfig \
29+
--name fleetops-dev \
30+
--region us-east-1
31+
32+
- name: Deploy with Helm
33+
run: |
34+
helm upgrade --install fleetops ./helm/fleetops \
35+
-f helm/fleetops/values-dev.yaml \
36+
--set image.tag=${{ github.sha }} \
37+
--wait \
38+
--timeout 5m
39+
40+
deploy-prod:
41+
name: Deploy to Prod
42+
runs-on: ubuntu-latest
43+
if: github.event_name == 'release'
44+
environment: prod
45+
46+
steps:
47+
- uses: actions/checkout@v4
48+
49+
- name: Configure AWS credentials
50+
uses: aws-actions/configure-aws-credentials@v4
51+
with:
52+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
53+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
54+
aws-region: us-east-1
55+
56+
- name: Update kubeconfig
57+
run: |
58+
aws eks update-kubeconfig \
59+
--name fleetops-prod \
60+
--region us-east-1
61+
62+
- name: Deploy with Helm
63+
run: |
64+
helm upgrade --install fleetops ./helm/fleetops \
65+
-f helm/fleetops/values-prod.yaml \
66+
--set image.tag=${{ github.ref_name }} \
67+
--wait \
68+
--timeout 10m

.github/workflows/ci.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, feat/* ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
lint:
11+
name: Lint & Format
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
- name: Install dependencies
22+
run: |
23+
pip install ruff black
24+
25+
- name: Run ruff
26+
run: ruff check app/
27+
28+
- name: Run black
29+
run: black --check app/
30+
31+
test:
32+
name: Tests
33+
runs-on: ubuntu-latest
34+
needs: lint
35+
36+
services:
37+
postgres:
38+
image: postgres:16-alpine
39+
env:
40+
POSTGRES_USER: fleetops
41+
POSTGRES_PASSWORD: fleetops
42+
POSTGRES_DB: fleetops
43+
ports:
44+
- 5432:5432
45+
options: >-
46+
--health-cmd pg_isready
47+
--health-interval 5s
48+
--health-timeout 5s
49+
--health-retries 5
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Setup Python
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: '3.12'
58+
59+
- name: Install dependencies
60+
run: pip install -r requirements.txt
61+
62+
- name: Run tests
63+
env:
64+
DATABASE_URL: postgresql+asyncpg://fleetops:fleetops@localhost:5432/fleetops
65+
run: pytest tests/ --cov=app --cov-report=term-missing
66+
67+
security:
68+
name: Security Scan
69+
runs-on: ubuntu-latest
70+
needs: lint
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Setup Python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: '3.12'
78+
79+
- name: Install security tools
80+
run: pip install bandit pip-audit
81+
82+
- name: Run Bandit
83+
run: bandit -r app/ -ll
84+
85+
- name: Run pip-audit
86+
run: pip-audit -r requirements.txt
87+
88+
build:
89+
name: Build & Push Docker Image
90+
runs-on: ubuntu-latest
91+
needs: [ test, security ]
92+
if: github.ref == 'refs/heads/main'
93+
94+
steps:
95+
- uses: actions/checkout@v4
96+
97+
- name: Configure AWS credentials
98+
uses: aws-actions/configure-aws-credentials@v4
99+
with:
100+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
101+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
102+
aws-region: us-east-1
103+
104+
- name: Login to Amazon ECR
105+
id: login-ecr
106+
uses: aws-actions/amazon-ecr-login@v2
107+
108+
- name: Build and push image
109+
env:
110+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
111+
IMAGE_TAG: ${{ github.sha }}
112+
run: |
113+
docker build -t $ECR_REGISTRY/fleetops:$IMAGE_TAG .
114+
docker build -t $ECR_REGISTRY/fleetops:latest .
115+
docker push $ECR_REGISTRY/fleetops:$IMAGE_TAG
116+
docker push $ECR_REGISTRY/fleetops:latest

0 commit comments

Comments
 (0)