From cab539b9cb5cfe8a2b5fe157463740e46524a3e3 Mon Sep 17 00:00:00 2001 From: defiQUG Date: Wed, 6 Aug 2025 06:07:47 +0000 Subject: [PATCH] Refactor CI/CD workflow to deploy to Azure services, including Azure Container Registry, App Service, Functions, Kubernetes, Cognitive Services, Monitoring, and DevOps integration. Update deployment steps and notifications for Azure-specific processes. --- .github/workflows/cd.yml | 193 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 181 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 0914ff9..de51d90 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -118,8 +118,8 @@ jobs: run: | echo "Production deployment completed successfully" - docker: - name: Build and Push Docker Image + azure-container-registry: + name: Build and Push to Azure Container Registry runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') steps: @@ -129,23 +129,169 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Login to Docker Hub - uses: docker/login-action@v2 + - name: Login to Azure + uses: azure/login@v1 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + creds: ${{ secrets.AZURE_CREDENTIALS }} - - name: Build and push Docker image + - name: Login to Azure Container Registry + uses: azure/docker-login@v1 + with: + login-server: ${{ secrets.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Build and push container image uses: docker/build-push-action@v4 with: context: . push: true tags: | - nowyouseeme/nowyouseeme:${{ github.ref_name }} - nowyouseeme/nowyouseeme:latest + ${{ secrets.ACR_LOGIN_SERVER }}/nowyouseeme:${{ github.ref_name }} + ${{ secrets.ACR_LOGIN_SERVER }}/nowyouseeme:latest cache-from: type=gha cache-to: type=gha,mode=max + - name: Deploy to Azure Container Instances + run: | + # Deploy to Azure Container Instances + az container create \ + --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --name nowyouseeme-${{ github.ref_name }} \ + --image ${{ secrets.ACR_LOGIN_SERVER }}/nowyouseeme:${{ github.ref_name }} \ + --dns-name-label nowyouseeme-${{ github.ref_name }} \ + --ports 8000 \ + --environment-variables \ + DATABASE_URL=${{ secrets.DATABASE_URL }} \ + REDIS_URL=${{ secrets.REDIS_URL }} \ + JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} + + azure-app-service: + name: Deploy to Azure App Service + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ secrets.AZURE_APP_NAME }} + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: . + + azure-functions: + name: Deploy to Azure Functions + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Azure Functions Core Tools + uses: Azure/functions-action@v1 + with: + app-name: ${{ secrets.AZURE_FUNCTION_APP_NAME }} + + - name: Deploy to Azure Functions + run: | + func azure functionapp publish ${{ secrets.AZURE_FUNCTION_APP_NAME }} + + azure-kubernetes: + name: Deploy to Azure Kubernetes Service + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Get AKS credentials + run: | + az aks get-credentials \ + --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --name ${{ secrets.AKS_CLUSTER_NAME }} + + - name: Deploy to AKS + run: | + # Apply Kubernetes manifests + kubectl apply -f k8s/ + + # Update deployment with new image + kubectl set image deployment/nowyouseeme \ + nowyouseeme=${{ secrets.ACR_LOGIN_SERVER }}/nowyouseeme:${{ github.ref_name }} + + azure-cognitive-services: + name: Deploy ML Models to Azure Cognitive Services + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install azure-cognitiveservices-vision-customvision + + - name: Deploy ML models + run: | + # Deploy custom vision models + python scripts/deploy_ml_models.py \ + --endpoint ${{ secrets.AZURE_CUSTOM_VISION_ENDPOINT }} \ + --key ${{ secrets.AZURE_CUSTOM_VISION_KEY }} \ + --project-id ${{ secrets.AZURE_CUSTOM_VISION_PROJECT_ID }} + + azure-monitoring: + name: Setup Azure Monitoring + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Setup Application Insights + run: | + # Create Application Insights resource + az monitor app-insights component create \ + --app ${{ secrets.APP_INSIGHTS_NAME }} \ + --location ${{ secrets.AZURE_LOCATION }} \ + --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --application-type web + + - name: Setup Log Analytics + run: | + # Create Log Analytics workspace + az monitor log-analytics workspace create \ + --resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \ + --workspace-name ${{ secrets.LOG_ANALYTICS_WORKSPACE }} + publish-pypi: name: Publish to PyPI runs-on: ubuntu-latest @@ -172,20 +318,43 @@ jobs: with: password: ${{ secrets.PYPI_API_TOKEN }} + azure-devops-integration: + name: Azure DevOps Integration + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Azure DevOps + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Create Azure DevOps work items + run: | + # Create work items for tracking + az boards work-items create \ + --organization ${{ secrets.AZURE_DEVOPS_ORG }} \ + --project ${{ secrets.AZURE_DEVOPS_PROJECT }} \ + --type "Release" \ + --title "Release ${{ github.ref_name }}" \ + --description "Automated release for version ${{ github.ref_name }}" + notify: name: Notify Team runs-on: ubuntu-latest if: always() - needs: [release, deploy-production, docker, publish-pypi] + needs: [release, deploy-production, azure-container-registry, azure-app-service, azure-functions, azure-kubernetes, azure-cognitive-services, azure-monitoring, azure-devops-integration, publish-pypi] steps: - name: Notify on success if: success() run: | - echo "All deployment steps completed successfully" + echo "All Azure deployment steps completed successfully" # Add your notification logic here (Slack, Discord, etc.) - name: Notify on failure if: failure() run: | - echo "Deployment failed" + echo "Azure deployment failed" # Add your failure notification logic here \ No newline at end of file