feat: CI/CD integration testing with network access #23
+22
-17
@@ -55,41 +55,46 @@ jobs:
|
|||||||
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
echo "✓ Pushed test image: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
echo "✓ Pushed test image: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
|
|
||||||
- name: Setup kubeconfig for integration test job
|
- name: Detect in-cluster Kubernetes authentication
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.kube
|
# When running inside K8s cluster, kubectl auto-detects service account
|
||||||
echo "${KUBECONFIG_B64}" | base64 -d > ~/.kube/config
|
# Mounted at: /var/run/secrets/kubernetes.io/serviceaccount/
|
||||||
env:
|
if [ -f /var/run/secrets/kubernetes.io/serviceaccount/token ]; then
|
||||||
KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }}
|
echo "✓ In-cluster authentication detected"
|
||||||
continue-on-error: true
|
export KUBECONFIG=/dev/null # kubectl will auto-use in-cluster auth
|
||||||
|
else
|
||||||
|
echo "⚠ Not running in-cluster, kubectl may fail"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Run integration tests via Kubernetes Job
|
- name: Run integration tests via Kubernetes Job
|
||||||
run: |
|
run: |
|
||||||
echo "Running integration tests via Kubernetes Job..."
|
echo "Running integration tests via Kubernetes Job..."
|
||||||
echo "Image: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
echo "Test image: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
|
|
||||||
# Apply job template from repo
|
# Apply job template from repo (uses in-cluster auth automatically)
|
||||||
kubectl apply -f k8s/integration-test-job.yaml
|
kubectl apply -f k8s/integration-test-job.yaml
|
||||||
|
|
||||||
# Update job to use new image
|
# Update job to use new image
|
||||||
kubectl set image job/api-gateway-integration-test \
|
kubectl set image job/api-gateway-integration-test \
|
||||||
api-gateway="${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
integration-tester="${IMAGE}:${{ steps.sha.outputs.short_sha }}" \
|
||||||
-n api --record
|
-n api --record
|
||||||
|
|
||||||
# Wait for job to complete (max 5 minutes)
|
# Wait for job to complete (max 10 minutes)
|
||||||
echo "Waiting for job to complete..."
|
echo "Waiting for job to complete (this may take a few minutes)..."
|
||||||
kubectl wait --for=condition=complete job/api-gateway-integration-test \
|
kubectl wait --for=condition=complete job/api-gateway-integration-test \
|
||||||
-n api --timeout=5m || true
|
-n api --timeout=10m 2>/dev/null || true
|
||||||
|
|
||||||
# Stream logs
|
# Stream logs
|
||||||
echo "Job logs:"
|
echo ""
|
||||||
kubectl logs -n api job/api-gateway-integration-test --all-containers=true --timestamps=true || true
|
echo "=== Job Logs ==="
|
||||||
|
kubectl logs -n api job/api-gateway-integration-test --all-containers=true --timestamps=true || echo "No logs available"
|
||||||
|
echo "================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Check if job succeeded
|
# Check if job succeeded
|
||||||
SUCCEEDED=$(kubectl get job api-gateway-integration-test -n api -o jsonpath='{.status.succeeded}')
|
SUCCEEDED=$(kubectl get job api-gateway-integration-test -n api -o jsonpath='{.status.succeeded}' 2>/dev/null || echo "0")
|
||||||
FAILED=$(kubectl get job api-gateway-integration-test -n api -o jsonpath='{.status.failed}')
|
FAILED=$(kubectl get job api-gateway-integration-test -n api -o jsonpath='{.status.failed}' 2>/dev/null || echo "0")
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Job Status: Succeeded=$SUCCEEDED, Failed=$FAILED"
|
echo "Job Status: Succeeded=$SUCCEEDED, Failed=$FAILED"
|
||||||
|
|
||||||
if [ "$SUCCEEDED" = "1" ]; then
|
if [ "$SUCCEEDED" = "1" ]; then
|
||||||
|
|||||||
@@ -15,27 +15,25 @@ spec:
|
|||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
containers:
|
containers:
|
||||||
- name: integration-tester
|
- name: integration-tester
|
||||||
image: golang:1.26-bookworm
|
image: forgejo.riotpiao.com/rock/api-gateway:latest
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: Always
|
||||||
workingDir: /workspace
|
workingDir: /app
|
||||||
command:
|
command:
|
||||||
- /bin/bash
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
set -e
|
set -e
|
||||||
echo "Starting integration tests..."
|
echo "Starting integration tests..."
|
||||||
|
echo "Gateway URL: http://api-gateway:8080"
|
||||||
|
|
||||||
# Clone the repo
|
# Wait for gateway service to be ready
|
||||||
git clone https://forgejo.riotpiao.com/riotpiao-poimen/homelab-frontend.git .
|
|
||||||
|
|
||||||
# Wait for gateway to be ready
|
|
||||||
echo "Waiting for gateway service to be ready..."
|
echo "Waiting for gateway service to be ready..."
|
||||||
for i in {1..30}; do
|
for i in $(seq 1 30); do
|
||||||
if curl -s http://api-gateway:8080/healthz | grep -q "alive"; then
|
if curl -s http://api-gateway:8080/healthz > /dev/null 2>&1; then
|
||||||
echo "✓ Gateway is ready"
|
echo "✓ Gateway is ready"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo "Attempting to reach gateway ($i/30)..."
|
echo "Waiting for gateway... ($i/30)"
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -47,6 +45,8 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- name: GATEWAY_URL
|
- name: GATEWAY_URL
|
||||||
value: "http://api-gateway:8080"
|
value: "http://api-gateway:8080"
|
||||||
|
- name: CI
|
||||||
|
value: "true"
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
cpu: 250m
|
cpu: 250m
|
||||||
@@ -72,4 +72,6 @@ spec:
|
|||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
- name: home
|
- name: home
|
||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: regcred
|
||||||
backoffLimit: 1
|
backoffLimit: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user