Skip to content

Commit eef58f3

Browse files
committed
Merge branch 'main' into test-driver-did-bsv
2 parents d0e8fe9 + 3386e59 commit eef58f3

6 files changed

Lines changed: 576 additions & 26 deletions

File tree

ci/deploy-k8s-aws/scripts/cleanup-orphaned.sh

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
# Orphaned resources are those that:
1010
# - Have the label 'managed-by=github-action'
1111
# - Do NOT have corresponding services in docker-compose.yml
12+
# - Are NOT in the exclusion list (special deployments managed separately)
13+
#
14+
# Excluded deployments:
15+
# - uni-resolver-frontend: Web UI deployed separately, not in docker-compose.yml
1216
#
1317
# The script removes:
14-
# - Orphaned Deployments
15-
# - Orphaned Services
18+
# - Orphaned Deployments (not in docker-compose.yml and not excluded)
19+
# - Orphaned Services (not in docker-compose.yml AND no matching deployment)
1620
# - Service-specific ConfigMaps (not the global app-config)
1721
#
1822
# Prerequisites:
@@ -41,6 +45,10 @@ echo "===================================================================="
4145
echo "Checking for orphaned deployments in namespace: $NAMESPACE"
4246
echo "===================================================================="
4347

48+
# Deployments that are not in docker-compose.yml but should be kept
49+
# These are special deployments managed separately
50+
EXCLUDED_DEPLOYMENTS="uni-resolver-frontend"
51+
4452
# Get all deployments managed by this GitHub Action
4553
kubectl get deployments -n "$NAMESPACE" -l managed-by=github-action -o json 2>/dev/null | \
4654
jq -r '.items[].metadata.name' > managed_deployments.txt || touch managed_deployments.txt
@@ -69,6 +77,13 @@ orphans_found=0
6977

7078
# Find and remove orphaned deployments
7179
while read -r deployment; do
80+
# Check if this deployment is in the exclusion list
81+
if echo "$EXCLUDED_DEPLOYMENTS" | grep -qw "$deployment"; then
82+
echo ""
83+
echo "ℹ Skipping deployment: $deployment (excluded from cleanup)"
84+
continue
85+
fi
86+
7287
# Check if this deployment exists in docker-compose.yml
7388
if ! grep -q "^${deployment}$" compose_services.txt; then
7489
echo ""
@@ -113,3 +128,80 @@ else
113128
echo "✓ Cleanup completed: $orphans_found orphaned deployment(s) removed"
114129
fi
115130
echo "===================================================================="
131+
132+
echo ""
133+
echo "===================================================================="
134+
echo "Checking for orphaned services in namespace: $NAMESPACE"
135+
echo "===================================================================="
136+
137+
# Get all services managed by this GitHub Action
138+
kubectl get services -n "$NAMESPACE" -l managed-by=github-action -o json 2>/dev/null | \
139+
jq -r '.items[].metadata.name' > managed_services.txt || touch managed_services.txt
140+
141+
# Check if there are any managed services
142+
if [ ! -s managed_services.txt ]; then
143+
echo "No managed services found in namespace"
144+
echo "===================================================================="
145+
exit 0
146+
fi
147+
148+
echo "Managed services in cluster:"
149+
cat managed_services.txt
150+
151+
echo ""
152+
echo "Services in docker-compose.yml:"
153+
cat compose_services.txt
154+
155+
echo ""
156+
echo "Comparing services with docker-compose.yml and deployments..."
157+
158+
# Track orphaned services
159+
orphaned_services=0
160+
161+
# Find and remove orphaned services
162+
while read -r service; do
163+
# Check if this service is in the exclusion list
164+
if echo "$EXCLUDED_DEPLOYMENTS" | grep -qw "$service"; then
165+
echo ""
166+
echo "ℹ Skipping service: $service (excluded from cleanup)"
167+
continue
168+
fi
169+
170+
# Check if service exists in docker-compose.yml OR has a matching deployment
171+
service_in_compose=false
172+
deployment_exists=false
173+
174+
if grep -q "^${service}$" compose_services.txt; then
175+
service_in_compose=true
176+
fi
177+
178+
if kubectl get deployment "$service" -n "$NAMESPACE" &>/dev/null; then
179+
deployment_exists=true
180+
fi
181+
182+
# Service is orphaned if it's not in compose AND has no matching deployment
183+
if [ "$service_in_compose" = false ] && [ "$deployment_exists" = false ]; then
184+
echo ""
185+
echo "⚠ Found orphaned service: $service"
186+
echo " This service is not defined in docker-compose.yml and has no matching deployment"
187+
echo " Removing service..."
188+
189+
orphaned_services=$((orphaned_services + 1))
190+
191+
if kubectl delete service "$service" -n "$NAMESPACE" --ignore-not-found=true; then
192+
echo " ✓ Service '$service' deleted"
193+
else
194+
echo " ✗ Failed to delete service '$service'"
195+
fi
196+
fi
197+
done < managed_services.txt
198+
199+
echo ""
200+
echo "===================================================================="
201+
if [ $orphaned_services -eq 0 ]; then
202+
echo "✓ No orphaned services found"
203+
echo " All managed services match docker-compose.yml or have deployments"
204+
else
205+
echo "✓ Cleanup completed: $orphaned_services orphaned service(s) removed"
206+
fi
207+
echo "===================================================================="
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/bin/bash
2+
3+
################################################################################
4+
# Deploy Universal Resolver Frontend
5+
#
6+
# This script deploys the uni-resolver-frontend application which provides
7+
# the web UI for the Universal Resolver. This is separate from the services
8+
# defined in docker-compose.yml.
9+
#
10+
# Components deployed:
11+
# - ConfigMap: uni-resolver-frontend (contains backend URL)
12+
# - Deployment: uni-resolver-frontend (web UI container)
13+
# - Service: uni-resolver-frontend (NodePort service)
14+
#
15+
# Prerequisites:
16+
# - kubectl must be configured and authenticated
17+
# - NAMESPACE environment variable must be set
18+
#
19+
# Usage:
20+
# NAMESPACE=uni-resolver ./deploy-frontend.sh
21+
################################################################################
22+
23+
set -e
24+
25+
# Validate prerequisites
26+
if [ -z "$NAMESPACE" ]; then
27+
echo "Error: NAMESPACE environment variable is not set"
28+
exit 1
29+
fi
30+
31+
# Configuration
32+
BACKEND_URL="https://dev.uniresolver.io/"
33+
34+
echo "===================================================================="
35+
echo "Deploying Universal Resolver Frontend"
36+
echo "===================================================================="
37+
echo ""
38+
39+
################################################################################
40+
# Step 1: Deploy ConfigMap
41+
################################################################################
42+
43+
echo "Step 1: Creating/updating ConfigMap..."
44+
45+
cat > configmap-uni-resolver-frontend.yaml << EOF
46+
apiVersion: v1
47+
kind: ConfigMap
48+
metadata:
49+
name: uni-resolver-frontend
50+
namespace: ${NAMESPACE}
51+
labels:
52+
app: uni-resolver-frontend
53+
managed-by: github-action
54+
data:
55+
backend_url: ${BACKEND_URL}
56+
EOF
57+
58+
if kubectl apply -f configmap-uni-resolver-frontend.yaml; then
59+
echo "✓ ConfigMap created/updated"
60+
else
61+
echo "✗ Failed to create ConfigMap"
62+
exit 1
63+
fi
64+
65+
echo ""
66+
67+
################################################################################
68+
# Step 2: Deploy Frontend Application
69+
################################################################################
70+
71+
echo "Step 2: Creating/updating Deployment and Service..."
72+
73+
cat > deployment-uni-resolver-frontend.yaml << EOF
74+
apiVersion: apps/v1
75+
kind: Deployment
76+
metadata:
77+
name: uni-resolver-frontend
78+
namespace: ${NAMESPACE}
79+
labels:
80+
app: uni-resolver-frontend
81+
type: frontend
82+
managed-by: github-action
83+
spec:
84+
replicas: 1
85+
selector:
86+
matchLabels:
87+
app: uni-resolver-frontend
88+
template:
89+
metadata:
90+
labels:
91+
app: uni-resolver-frontend
92+
spec:
93+
containers:
94+
- name: uni-resolver-frontend
95+
image: universalresolver/universal-resolver-frontend
96+
imagePullPolicy: Always
97+
ports:
98+
- containerPort: 7081
99+
env:
100+
- name: BACKEND_URL
101+
valueFrom:
102+
configMapKeyRef:
103+
name: uni-resolver-frontend
104+
key: backend_url
105+
---
106+
apiVersion: v1
107+
kind: Service
108+
metadata:
109+
name: uni-resolver-frontend
110+
namespace: ${NAMESPACE}
111+
labels:
112+
app: uni-resolver-frontend
113+
managed-by: github-action
114+
spec:
115+
type: NodePort
116+
selector:
117+
app: uni-resolver-frontend
118+
ports:
119+
- protocol: TCP
120+
port: 7081
121+
targetPort: 7081
122+
EOF
123+
124+
if kubectl apply -f deployment-uni-resolver-frontend.yaml; then
125+
echo "✓ Deployment and Service created/updated"
126+
else
127+
echo "✗ Failed to create Deployment and Service"
128+
exit 1
129+
fi
130+
131+
echo ""
132+
133+
################################################################################
134+
# Step 3: Wait for Deployment to be Ready
135+
################################################################################
136+
137+
echo "Step 3: Waiting for deployment to become ready..."
138+
139+
if kubectl rollout status deployment/uni-resolver-frontend -n "$NAMESPACE" --timeout=300s; then
140+
echo "✓ Frontend deployment is ready"
141+
else
142+
echo "⚠ Frontend deployment rollout timed out"
143+
echo " Continuing with deployment process..."
144+
fi
145+
146+
echo ""
147+
148+
################################################################################
149+
# Summary
150+
################################################################################
151+
152+
echo "===================================================================="
153+
echo "Frontend Deployment Summary"
154+
echo "===================================================================="
155+
echo ""
156+
157+
# Show deployment status
158+
echo "Deployment:"
159+
kubectl get deployment uni-resolver-frontend -n "$NAMESPACE" -o wide
160+
161+
echo ""
162+
echo "Service:"
163+
kubectl get service uni-resolver-frontend -n "$NAMESPACE" -o wide
164+
165+
echo ""
166+
echo "Pods:"
167+
kubectl get pods -n "$NAMESPACE" -l app=uni-resolver-frontend -o wide
168+
169+
echo ""
170+
echo "✓ Frontend deployment complete"

0 commit comments

Comments
 (0)