mirror of
https://github.com/ghndrx/k8s-game-2048.git
synced 2026-02-10 14:54:59 +00:00
- Fixed 'Run smoke test' step that had both 'uses' and 'run' keys - Removed all duplicated deployment sections and jobs - Added service manifest application before patching - Simplified workflow to focus on core deployment functionality - Removed duplicated kubectl setup and Playwright testing sections - This should resolve the GitHub Actions validation errors for dev deployment
123 lines
4.2 KiB
YAML
123 lines
4.2 KiB
YAML
name: Deploy to Development
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Build and Push Container Image"]
|
|
types:
|
|
- completed
|
|
branches: [ develop ]
|
|
push:
|
|
branches: [ develop ]
|
|
workflow_dispatch:
|
|
inputs:
|
|
image_tag:
|
|
description: 'Image tag to deploy (default: latest)'
|
|
required: false
|
|
default: 'latest'
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ghndrx/k8s-game-2048
|
|
|
|
jobs:
|
|
deploy-dev:
|
|
name: Deploy to Development
|
|
runs-on: ubuntu-latest
|
|
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
|
|
environment: development
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up kubectl
|
|
uses: azure/setup-kubectl@v3
|
|
with:
|
|
version: 'latest'
|
|
|
|
- name: Configure kubectl
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
|
|
- name: Set image tag
|
|
run: |
|
|
IMAGE_TAG="${{ github.event.inputs.image_tag || 'latest' }}"
|
|
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
|
|
echo "Deploying image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG"
|
|
|
|
- name: Deploy to development
|
|
run: |
|
|
echo "🚀 Deploying to development environment..."
|
|
|
|
# Apply namespace
|
|
kubectl apply -f manifests/dev/namespace.yml
|
|
|
|
# Ensure GHCR secret exists
|
|
if kubectl get secret ghcr-secret -n default &>/dev/null; then
|
|
echo "🔐 Copying GHCR secret to dev namespace..."
|
|
kubectl get secret ghcr-secret -o yaml | \
|
|
sed 's/namespace: default/namespace: game-2048-dev/' | \
|
|
sed '/resourceVersion:/d' | \
|
|
sed '/uid:/d' | \
|
|
sed '/creationTimestamp:/d' | \
|
|
kubectl apply -f -
|
|
fi
|
|
|
|
# Apply the Knative service manifest first
|
|
kubectl apply -f manifests/dev/service.yml
|
|
|
|
# Update image in service
|
|
kubectl patch ksvc game-2048-dev -n game-2048-dev --type merge -p '{"spec":{"template":{"spec":{"containers":[{"image":"${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}","imagePullPolicy":"Always"}]}}}}'
|
|
|
|
echo "⏳ Waiting for deployment to be ready..."
|
|
kubectl wait --for=condition=Ready ksvc/game-2048-dev -n game-2048-dev --timeout=300s || echo "⚠️ Service may still be starting"
|
|
|
|
- name: Verify deployment
|
|
run: |
|
|
echo "📊 Deployment status:"
|
|
kubectl get ksvc -n game-2048-dev
|
|
|
|
echo ""
|
|
echo "✅ Development deployment completed!"
|
|
echo "🌐 Available at: https://2048-dev.wa.darknex.us"
|
|
|
|
- name: Run smoke test
|
|
run: |
|
|
echo "🧪 Running smoke test..."
|
|
sleep 30
|
|
|
|
for i in {1..5}; do
|
|
echo "Attempt $i/5..."
|
|
# Test canonical domain first
|
|
if curl -s --max-time 30 https://game-2048-dev.game-2048-dev.dev.wa.darknex.us/ | grep -q "2048"; then
|
|
echo "✅ Canonical domain smoke test passed!"
|
|
break
|
|
# Fallback to custom domain
|
|
elif curl -s --max-time 30 https://2048-dev.wa.darknex.us/ | grep -q "2048"; then
|
|
echo "✅ Custom domain smoke test passed!"
|
|
break
|
|
elif [ $i -eq 5 ]; then
|
|
echo "⚠️ Smoke test failed after 5 attempts"
|
|
exit 1
|
|
else
|
|
echo "Retrying in 30 seconds..."
|
|
sleep 30
|
|
fi
|
|
done
|
|
|
|
- name: Create deployment summary
|
|
run: |
|
|
echo "## 🚀 Development Deployment Summary" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Component | Status |" >> $GITHUB_STEP_SUMMARY
|
|
echo "|-----------|--------|" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Namespace | ✅ Applied |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Service | ✅ Deployed |" >> $GITHUB_STEP_SUMMARY
|
|
echo "| Health Check | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 🔗 URLs" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Canonical**: https://game-2048-dev.game-2048-dev.dev.wa.darknex.us" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Custom**: https://2048-dev.wa.darknex.us" >> $GITHUB_STEP_SUMMARY
|