fix: deploy.yml #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Potpie Service to Lightsail Kubernetes | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| workflow_dispatch: | |
| env: | |
| DOCKER_EMAIL: digital@pixdata.io | |
| DOCKER_USERNAME: pagewings | |
| IMAGE_NAME: coderide-potpie-service | |
| REGISTRY: docker.io | |
| jobs: | |
| build-and-push: | |
| environment: master | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| name: Build and Push Docker Image | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ env.DOCKER_EMAIL }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=sha,prefix={{branch}}- | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| deploy: | |
| environment: master | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| name: Deploy to Kubernetes | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup kubectl | |
| uses: azure/setup-kubectl@v3 | |
| with: | |
| version: 'latest' | |
| - name: Configure kubectl | |
| run: | | |
| mkdir -p ~/.kube | |
| echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config | |
| chmod 600 ~/.kube/config | |
| - name: Verify kubectl connection to Lightsail | |
| run: kubectl cluster-info | |
| - name: Check existing Redis services | |
| run: | | |
| echo "=== Available Redis services ===" | |
| kubectl get svc | grep -E "(redis|valkey)" || echo "No Redis services found" | |
| kubectl get pods | grep -E "(redis|valkey)" || echo "No Redis pods found" | |
| - name: Update secrets for Lightsail | |
| run: | | |
| # Get valkey password from existing secret | |
| VALKEY_PASSWORD=$(kubectl get secret valkey-auth -n valkey -o jsonpath='{.data.VALKEY_PASSWORD}' | base64 -d) | |
| # Create potpie secrets with valkey password | |
| kubectl create secret generic potpie-secrets \ | |
| --from-literal=POTPIE_API_KEY="${{ secrets.POTPIE_API_KEY }}" \ | |
| --from-literal=REDIS_PASSWORD="$VALKEY_PASSWORD" \ | |
| --namespace=default \ | |
| --dry-run=client -o yaml | kubectl apply -f - | |
| - name: Deploy to Lightsail Kubernetes | |
| run: | | |
| # Create valkey service if not exists | |
| kubectl apply -f kubernetes/valkey-service.yaml | |
| # Apply all manifests (image is already correct in deployment.yaml) | |
| kubectl apply -f kubernetes/deployment.yaml | |
| kubectl apply -f kubernetes/service.yaml | |
| - name: Wait for deployment rollout | |
| run: | | |
| kubectl rollout status deployment/potpie-service --namespace=default --timeout=300s | |
| - name: Verify deployment | |
| run: | | |
| kubectl get pods -l app=potpie-service --namespace=default | |
| kubectl get svc potpie-service --namespace=default | |
| - name: Get service status | |
| run: | | |
| echo "=== Deployment Status ===" | |
| kubectl get deployment potpie-service --namespace=default | |
| echo "" | |
| echo "=== Service Status ===" | |
| kubectl get svc potpie-service --namespace=default | |
| echo "" | |
| echo "=== Pod Status ===" | |
| kubectl get pods -l app=potpie-service --namespace=default | |
| echo "" | |
| echo "=== Recent Events ===" | |
| kubectl get events --namespace=default --sort-by='.lastTimestamp' | tail -10 | |
| health-check: | |
| runs-on: ubuntu-latest | |
| environment: master | |
| needs: deploy | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| name: Health Check | |
| steps: | |
| - name: Setup kubectl | |
| uses: azure/setup-kubectl@v3 | |
| with: | |
| version: 'latest' | |
| - name: Configure kubectl | |
| run: | | |
| mkdir -p ~/.kube | |
| echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config | |
| chmod 600 ~/.kube/config | |
| - name: Wait for pods to be ready | |
| run: | | |
| kubectl wait --for=condition=ready pod -l app=potpie-service --namespace=default --timeout=300s | |
| - name: Test service health | |
| run: | | |
| # Get service IP | |
| SERVICE_IP=$(kubectl get svc potpie-service --namespace=default -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | |
| if [ -z "$SERVICE_IP" ]; then | |
| SERVICE_IP=$(kubectl get svc potpie-service --namespace=default -o jsonpath='{.spec.clusterIP}') | |
| fi | |
| echo "Testing service at IP: $SERVICE_IP" | |
| # Test health endpoint | |
| kubectl run curl-test --image=curlimages/curl:latest --rm -i --restart=Never -- \ | |
| curl -f "http://$SERVICE_IP/health" || echo "Health check failed" | |
| # Test metrics endpoint | |
| kubectl run curl-test --image=curlimages/curl:latest --rm -i --restart=Never -- \ | |
| curl -f "http://$SERVICE_IP/metrics" || echo "Metrics check failed" | |
| - name: Cleanup test resources | |
| if: always() | |
| run: | | |
| kubectl delete pod curl-test --ignore-not-found=true --namespace=default |