-
Notifications
You must be signed in to change notification settings - Fork 3
295 lines (258 loc) Β· 10.3 KB
/
visualizer.yml
File metadata and controls
295 lines (258 loc) Β· 10.3 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: visualizer build, push, deploy
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- architecture: amd64
runner: ubuntu-24.04
platform: linux/amd64
- architecture: arm64
runner: ubuntu-24.04-arm
platform: linux/arm64
outputs:
images: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to container registry
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,format=short,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.title=Debug Visualizer
org.opencontainers.image.description=Debug visualizer web application
org.opencontainers.image.vendor=${{ github.repository_owner }}
- name: Create architecture-specific tags
id: arch-tags
run: |
# Get the base tags and add architecture suffix to each
BASE_TAGS="${{ steps.meta.outputs.tags }}"
ARCH_TAGS=""
while IFS= read -r tag; do
if [[ -n "$tag" ]]; then
if [[ -z "$ARCH_TAGS" ]]; then
ARCH_TAGS="${tag}-${{ matrix.architecture }}"
else
ARCH_TAGS="${ARCH_TAGS}\n${tag}-${{ matrix.architecture }}"
fi
fi
done <<< "$BASE_TAGS"
echo "arch-tags<<EOF" >> $GITHUB_OUTPUT
echo -e "$ARCH_TAGS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build and push multi-arch image
if: github.event_name == 'push'
id: build
uses: docker/build-push-action@v6
with:
context: ./visualizer
file: ./visualizer/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.arch-tags.outputs.arch-tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Docker image (PR test)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v6
with:
context: ./visualizer
file: ./visualizer/Dockerfile
platforms: ${{ matrix.platform }}
push: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test-${{ matrix.architecture }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Show build information
run: |
echo "Built for architecture: ${{ matrix.architecture }}"
echo "Platform: ${{ matrix.platform }}"
echo "Runner: ${{ matrix.runner }}"
if [ "${{ github.event_name }}" == "push" ]; then
echo "Image tags: ${{ steps.arch-tags.outputs.arch-tags }}"
else
echo "Test build completed for PR"
fi
merge:
needs: build
runs-on: ubuntu-24.04
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,format=short,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.title=Debug Visualizer
org.opencontainers.image.description=Debug visualizer web application
org.opencontainers.image.vendor=${{ github.repository_owner }}
- name: Create multi-architecture manifest
run: |
# Get the tags from metadata (convert newlines to spaces for proper iteration)
TAGS=$(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' ')
# Create manifest for each tag
for tag in $TAGS; do
# Skip empty tags
if [[ -z "$tag" ]]; then
continue
fi
echo "Creating manifest for tag: $tag"
# Create manifest from existing architecture-specific images
docker buildx imagetools create -t "$tag" \
"${tag}-amd64" \
"${tag}-arm64"
echo "Manifest created for $tag"
done
- name: Show manifest information
run: |
echo "Multi-architecture manifest created"
echo "Image tags: ${{ steps.meta.outputs.tags }}"
echo "Supported platforms: linux/amd64, linux/arm64"
deploy:
needs: merge
runs-on: ubuntu-24.04
if: github.event_name == 'push'
environment: ${{ github.ref_name == 'main' && 'prod' || 'dev' }}
permissions:
contents: read
packages: read
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare deployment configuration
id: cfg
run: |
BRANCH="${{ github.ref_name }}"
if [ "$BRANCH" = "main" ]; then
NAMESPACE="production"
ENVIRONMENT_URL="https://visualizer.coregame.de"
DEPLOYMENT_NAME="debug-visualizer"
else
NAMESPACE="development"
ENVIRONMENT_URL="https://dev.visualizer.coregame.de"
DEPLOYMENT_NAME="debug-visualizer-dev"
fi
echo "namespace=${NAMESPACE}" >> $GITHUB_OUTPUT
echo "environment_url=${ENVIRONMENT_URL}" >> $GITHUB_OUTPUT
echo "deployment_name=${DEPLOYMENT_NAME}" >> $GITHUB_OUTPUT
- name: Setup kubectl CLI
uses: azure/setup-kubectl@v4
with:
version: "v1.28.4"
- name: Configure Kubernetes context
run: |
set -euo pipefail
mkdir -p ~/.kube
if [ -n "${KUBECONFIG_DATA:-}" ]; then
echo "Using KUBECONFIG_DATA from environment variable"
echo "$KUBECONFIG_DATA" | base64 -d > ~/.kube/config
elif [ -n "${{ secrets.KUBECONFIG_DATA }}" ]; then
echo "Using KUBECONFIG_DATA from GitHub secret"
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > ~/.kube/config
elif [ -f .kube/config ]; then
echo "Using repository kubeconfig at .kube/config"
cp .kube/config ~/.kube/config
else
echo "ERROR: No kubeconfig provided. Set KUBECONFIG_DATA (env or secret) or commit .kube/config for CI use."
exit 1
fi
chmod 600 ~/.kube/config
echo "KUBECONFIG=$HOME/.kube/config" >> $GITHUB_ENV
- name: Verify Kubernetes cluster
run: |
kubectl cluster-info
kubectl get nodes
- name: Setup Helm
uses: azure/setup-helm@v4
with:
version: "v3.13.3"
- name: Determine image tag to deploy
id: image
run: |
BRANCH="${{ github.ref_name }}"
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
TAG="${BRANCH}-${SHORT_SHA}"
echo "repo=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "Deploying image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}"
- name: Ensure Kubernetes namespace exists
run: |
kubectl create namespace ${{ steps.cfg.outputs.namespace }} --dry-run=client -o yaml | kubectl apply -f -
- name: Validate Helm chart
run: |
helm lint ./visualizer/helm/debug-visualizer --values ./visualizer/helm/debug-visualizer/${{ github.ref_name == 'main' && 'values-prod.yaml' || 'values-dev.yaml' }}
- name: Deploy application with Helm
run: |
VALUES_FILE=${{ github.ref_name == 'main' && 'values-prod.yaml' || 'values-dev.yaml' }}
helm upgrade --install \
${{ steps.cfg.outputs.deployment_name }} \
./visualizer/helm/debug-visualizer \
--namespace ${{ steps.cfg.outputs.namespace }} \
--values ./visualizer/helm/debug-visualizer/${VALUES_FILE} \
--set image.repository=${{ steps.image.outputs.repo }} \
--set image.tag=${{ steps.image.outputs.tag }} \
--wait \
--timeout=3m \
--atomic \
--history-max=5
- name: Verify Kubernetes deployment
run: |
kubectl rollout status deployment/${{ steps.cfg.outputs.deployment_name }} -n ${{ steps.cfg.outputs.namespace }} --timeout=300s
kubectl get deploy/${{ steps.cfg.outputs.deployment_name }} -n ${{ steps.cfg.outputs.namespace }} -o wide | cat
kubectl get svc -n ${{ steps.cfg.outputs.namespace }} | cat
kubectl get ingress -n ${{ steps.cfg.outputs.namespace }} | cat
- name: Write deployment summary
run: |
echo "## Application Deployment" >> $GITHUB_STEP_SUMMARY
echo "Environment: ${{ github.ref_name == 'main' && 'prod' || 'dev' }}" >> $GITHUB_STEP_SUMMARY
echo "Namespace: ${{ steps.cfg.outputs.namespace }}" >> $GITHUB_STEP_SUMMARY
echo "Deployment: ${{ steps.cfg.outputs.deployment_name }}" >> $GITHUB_STEP_SUMMARY
echo "Image: ${{ steps.image.outputs.repo }}:${{ steps.image.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "URL: ${{ steps.cfg.outputs.environment_url }}" >> $GITHUB_STEP_SUMMARY