-
Notifications
You must be signed in to change notification settings - Fork 101
156 lines (133 loc) · 4.48 KB
/
Copy pathrelease.yml
File metadata and controls
156 lines (133 loc) · 4.48 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
AWS_REGION: eu-west-1
EKS_CLUSTER: esade-teaching
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v4
- run: uv sync --dev
- run: uv run ruff check src/ tests/
- run: uv run ruff format --check src/ tests/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v4
- run: uv sync --dev
- run: uv run pytest -v
release:
runs-on: ubuntu-latest
needs: [lint, test]
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
docker:
runs-on: ubuntu-latest
needs: [lint, test]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
runs-on: ubuntu-latest
needs: [docker]
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ env.AWS_REGION }}
- name: Configure kubectl
run: aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER }} --region ${{ env.AWS_REGION }}
- name: Deploy to EKS
run: kubectl apply -k k8s/
- name: Wait for rollout
run: kubectl rollout status deployment/hello-world -n hello-world --timeout=120s
- name: Verify deployment
run: |
echo "=== Pod Status ==="
kubectl get pods -n hello-world -o wide
echo ""
echo "=== Getting LoadBalancer URL ==="
LB=$(kubectl get svc -n hello-world hello-world -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "Service URL: http://$LB/"
echo ""
echo "=== Testing Load Balancer (20 requests) ==="
declare -A pod_hits
failed=0
for i in {1..20}; do
response=$(curl -s --max-time 5 "http://$LB/" || echo "FAILED")
if [[ "$response" == "FAILED" ]]; then
echo "Request $i: FAILED (timeout/error)"
((failed++))
elif [[ "$response" == hello-world\ from\ * ]]; then
hostname=$(echo "$response" | sed 's/hello-world from //' | tr -d '\n')
pod_hits["$hostname"]=$((${pod_hits["$hostname"]:-0} + 1))
echo "Request $i: $hostname"
else
echo "Request $i: UNEXPECTED RESPONSE: $response"
((failed++))
fi
done
echo ""
echo "=== Results ==="
echo "Unique pods reached: ${#pod_hits[@]}"
for pod in "${!pod_hits[@]}"; do
echo " - $pod: ${pod_hits[$pod]} hits"
done
echo "Failed requests: $failed"
echo ""
echo "=== Validation ==="
if [[ ${#pod_hits[@]} -lt 2 ]]; then
echo "FAIL: Load balancer did not distribute to multiple pods"
exit 1
fi
if [[ $failed -gt 2 ]]; then
echo "FAIL: Too many failed requests ($failed/20)"
exit 1
fi
echo "PASS: Load balancing verified across ${#pod_hits[@]} pods"