Merge branches 'msignite-25' and 'msignite-25' of https://github.com/… #1
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 Pets Workshop to Azure | |
| on: | |
| push: | |
| branches: [ main, msignite-25 ] | |
| paths: | |
| - 'terraform/**' | |
| - 'server/**' | |
| - 'client/**' | |
| - '.github/workflows/azure-deploy.yml' | |
| pull_request: | |
| branches: [ main ] | |
| paths: | |
| - 'terraform/**' | |
| - 'server/**' | |
| - 'client/**' | |
| workflow_dispatch: | |
| inputs: | |
| terraform_action: | |
| description: 'Terraform action to perform' | |
| required: true | |
| default: 'plan' | |
| type: choice | |
| options: | |
| - plan | |
| - apply | |
| - destroy | |
| env: | |
| ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
| ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} | |
| ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
| TF_VAR_sql_admin_password: ${{ secrets.SQL_ADMIN_PASSWORD }} | |
| jobs: | |
| terraform: | |
| name: 'Terraform Infrastructure' | |
| runs-on: ubuntu-latest | |
| environment: production | |
| defaults: | |
| run: | |
| shell: bash | |
| working-directory: ./terraform | |
| outputs: | |
| backend_app_name: ${{ steps.terraform_output.outputs.backend_app_name }} | |
| frontend_deployment_token: ${{ steps.terraform_output.outputs.frontend_deployment_token }} | |
| resource_group_name: ${{ steps.terraform_output.outputs.resource_group_name }} | |
| static_web_app_name: ${{ steps.terraform_output.outputs.static_web_app_name }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.6.0 | |
| terraform_wrapper: false | |
| - name: Terraform Init | |
| run: terraform init | |
| - name: Terraform Format Check | |
| run: terraform fmt -check | |
| - name: Terraform Validate | |
| run: terraform validate | |
| - name: Terraform Plan | |
| if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'plan') | |
| run: terraform plan -no-color | |
| continue-on-error: true | |
| - name: Terraform Plan Status | |
| if: github.event_name == 'pull_request' && steps.plan.outcome == 'failure' | |
| run: exit 1 | |
| - name: Terraform Apply | |
| if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply') | |
| run: terraform apply -auto-approve | |
| - name: Terraform Destroy | |
| if: github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'destroy' | |
| run: terraform destroy -auto-approve | |
| - name: Terraform Output | |
| if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply') | |
| id: terraform_output | |
| run: | | |
| echo "backend_app_name=$(terraform output -raw backend_app_service_name)" >> $GITHUB_OUTPUT | |
| echo "frontend_deployment_token=$(terraform output -raw frontend_deployment_token)" >> $GITHUB_OUTPUT | |
| echo "resource_group_name=$(terraform output -raw resource_group_name)" >> $GITHUB_OUTPUT | |
| echo "static_web_app_name=$(terraform output -raw frontend_static_web_app_name)" >> $GITHUB_OUTPUT | |
| deploy_backend: | |
| name: 'Deploy Flask Backend' | |
| runs-on: ubuntu-latest | |
| needs: terraform | |
| if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| working-directory: ./server | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Login to Azure | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Deploy to Azure Web App | |
| uses: azure/webapps-deploy@v2 | |
| with: | |
| app-name: ${{ needs.terraform.outputs.backend_app_name }} | |
| package: ./server | |
| startup-command: 'gunicorn --bind=0.0.0.0 --timeout 600 app:app' | |
| deploy_frontend: | |
| name: 'Deploy Astro Frontend' | |
| runs-on: ubuntu-latest | |
| needs: terraform | |
| if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| cache-dependency-path: './client/package-lock.json' | |
| - name: Install dependencies | |
| working-directory: ./client | |
| run: npm ci | |
| - name: Build Astro app | |
| working-directory: ./client | |
| run: npm run build | |
| env: | |
| # Update API endpoint to point to Azure App Service | |
| VITE_API_URL: https://${{ needs.terraform.outputs.backend_app_name }}.azurewebsites.net | |
| - name: Deploy to Static Web App | |
| uses: Azure/static-web-apps-deploy@v1 | |
| with: | |
| azure_static_web_apps_api_token: ${{ needs.terraform.outputs.frontend_deployment_token }} | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| action: 'upload' | |
| app_location: '/client' | |
| api_location: '' | |
| output_location: 'dist' | |
| database_setup: | |
| name: 'Setup Database' | |
| runs-on: ubuntu-latest | |
| needs: terraform | |
| if: (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.terraform_action == 'apply') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Login to Azure | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: Setup Database Schema | |
| run: | | |
| # Note: Add your database migration/setup commands here | |
| echo "Database setup would go here" | |
| echo "You may want to run SQL scripts to create tables and seed data" | |
| # Example: sqlcmd -S $SQL_SERVER -d $SQL_DATABASE -U $SQL_USER -P $SQL_PASSWORD -i ./database/schema.sql |