name: CD on: push: tags: - 'v*' workflow_run: workflows: ["CI"] types: - completed env: PYTHON_VERSION: '3.9' jobs: release: name: Create Release runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} 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 sudo apt-get update sudo apt-get install -y build-essential cmake libopencv-dev libeigen3-dev - name: Build project run: | chmod +x tools/build.sh ./tools/build.sh - name: Create release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} release_name: Release ${{ github.ref }} draft: false prerelease: false - name: Upload build artifacts uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ./build/ asset_name: nowyouseeme-${{ github.ref_name }}-linux.tar.gz asset_content_type: application/gzip deploy-staging: name: Deploy to Staging runs-on: ubuntu-latest if: github.ref == 'refs/heads/develop' 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 staging run: | echo "Deploying to staging environment..." # Add your staging deployment commands here # Example: docker build and push to staging registry - name: Notify deployment run: | echo "Staging deployment completed successfully" deploy-production: name: Deploy to Production runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') needs: [release] 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 production run: | echo "Deploying to production environment..." # Add your production deployment commands here # Example: docker build and push to production registry - name: Notify deployment run: | echo "Production deployment completed successfully" azure-container-registry: name: Build and Push to Azure Container Registry runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Login to Azure uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - 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: | ${{ 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 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 build dependencies run: | python -m pip install --upgrade pip pip install build twine - name: Build package run: python -m build - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 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, 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 Azure deployment steps completed successfully" # Add your notification logic here (Slack, Discord, etc.) - name: Notify on failure if: failure() run: | echo "Azure deployment failed" # Add your failure notification logic here