|
| 1 | +trigger: |
| 2 | +- main # Or your desired branch |
| 3 | + |
| 4 | +pool: |
| 5 | + vmImage: ubuntu-latest |
| 6 | + |
| 7 | +variables: |
| 8 | + pythonVersion: '3.13' |
| 9 | + artifactName: 'python-app' |
| 10 | + zipName: 'release1.zip' |
| 11 | + appFolder: 'scholas-api' # Adjust if your code lives elsewhere |
| 12 | + |
| 13 | +stages: |
| 14 | +- stage: Build |
| 15 | + jobs: |
| 16 | + - job: BuildJob |
| 17 | + steps: |
| 18 | + - checkout: self |
| 19 | + |
| 20 | + - script: | |
| 21 | + echo "📁 Listing repo contents for debug" |
| 22 | + ls -al |
| 23 | + displayName: 'List all files' |
| 24 | +
|
| 25 | + - task: UsePythonVersion@0 |
| 26 | + inputs: |
| 27 | + versionSpec: '$(pythonVersion)' |
| 28 | + addToPath: true |
| 29 | + displayName: 'Set up Python' |
| 30 | + |
| 31 | + - script: | |
| 32 | + python -m venv venv |
| 33 | + source venv/bin/activate |
| 34 | + displayName: 'Create and activate virtual environment' |
| 35 | +
|
| 36 | + - script: | |
| 37 | + cd $(appFolder) |
| 38 | + pip install -r requirements.txt |
| 39 | + pip install uvicorn |
| 40 | + displayName: 'Install dependencies and uvicorn' |
| 41 | +
|
| 42 | + - script: | |
| 43 | + pip freeze |
| 44 | + displayName: 'Verify installed packages' |
| 45 | +
|
| 46 | + - script: | |
| 47 | + cd $(appFolder) |
| 48 | + zip -r ../$(zipName) . |
| 49 | + displayName: 'Zip app contents' |
| 50 | +
|
| 51 | + - task: PublishBuildArtifacts@1 |
| 52 | + inputs: |
| 53 | + PathtoPublish: '$(zipName)' |
| 54 | + ArtifactName: '$(artifactName)' |
| 55 | + publishLocation: 'Container' |
| 56 | + displayName: 'Publish artifact for deployment' |
| 57 | + |
| 58 | +- stage: Deploy |
| 59 | + dependsOn: Build |
| 60 | + jobs: |
| 61 | + - deployment: DeployJob |
| 62 | + environment: 'Production' |
| 63 | + strategy: |
| 64 | + runOnce: |
| 65 | + deploy: |
| 66 | + steps: |
| 67 | + - download: current |
| 68 | + artifact: $(artifactName) |
| 69 | + |
| 70 | + - script: | |
| 71 | + unzip $(zipName) |
| 72 | + displayName: 'Unzip artifact' |
| 73 | +
|
| 74 | + - task: AzureCLI@2 |
| 75 | + inputs: |
| 76 | + azureSubscription: '<your-service-connection-name>' # 🟡 Service connection name |
| 77 | + scriptType: bash |
| 78 | + scriptLocation: inlineScript |
| 79 | + inlineScript: | |
| 80 | + echo "🔐 Logging in with service principal..." |
| 81 | + az login --service-principal \ |
| 82 | + --username ${{ secrets.REGISTRY_USERNAME }} \ |
| 83 | + --password ${{ secrets.REGISTRY_PASSWORD }} \ |
| 84 | + --tenant ${{ secrets.TENANT_ID }} |
| 85 | +
|
| 86 | + echo "🚀 Deploying to Azure Web App..." |
| 87 | + az webapp deployment source config-zip \ |
| 88 | + --resource-group ScholasUI-RG \ |
| 89 | + --name scholasapplicationwebdev2 \ |
| 90 | + --src $(zipName) |
| 91 | +
|
| 92 | + echo "⚙️ Configuring startup command..." |
| 93 | + az webapp config set \ |
| 94 | + --name scholasapplicationwebdev2 \ |
| 95 | + --resource-group ScholasUI-RG \ |
| 96 | + --startup-file "python3 -m uvicorn School:app --host 0.0.0.0 --port 8000" |
| 97 | + displayName: 'Login and Deploy with Azure CLI' |
0 commit comments