-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (96 loc) · 3.25 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Thunder CI/CD Pipeline
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
jobs:
test:
name: Run Tests and Generate Coverage
runs-on: ubuntu-latest
env:
JWT_SECRET: "testsecret"
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpass
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U testuser -d testdb"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install Dependencies
run: go mod tidy
- name: Generate SSL Certificates
run: |
mkdir -p certs
openssl req -x509 -newkey rsa:4096 -keyout certs/server.key -out certs/server.crt -days 365 -nodes \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
- name: Run Unit Tests
run: go test -v ./...
- name: Run Integration Tests (gRPC + REST)
run: go test -v ./backend/... ./db/...
- name: Generate Coverage Report
run: go test -coverprofile=coverage.txt ./backend/... ./db/...
- name: Print Coverage Summary
run: go tool cover -func=coverage.txt
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.txt
deploy:
name: Build and Deploy to Kubernetes
runs-on: ubuntu-latest
needs: test # Ensures tests pass before deployment
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Generate SSL Certificates
run: |
mkdir -p certs
openssl req -x509 -newkey rsa:4096 -keyout certs/server.key -out certs/server.crt -days 365 -nodes \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
- name: Log in to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: docker build -t raezil/app:latest .
- name: Push Docker Image
run: docker push raezil/app:latest
- name: Install and Start Minikube
run: |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod +x minikube-linux-amd64
sudo mv minikube-linux-amd64 /usr/local/bin/minikube
minikube start --driver=docker
- name: Set Up Kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Deploy to Kubernetes
working-directory: ./k8s
run: |
kubectl apply -f postgres-deployment.yaml
kubectl apply -f postgres-service.yaml
kubectl apply -f pgbouncer-all.yaml
kubectl apply -f app-deployment.yaml
kubectl apply -f app-service.yaml
- name: Verify Deployment
run: kubectl rollout status deployment/app-deployment