Skip to content

Commit 8a7914f

Browse files
authored
Create azure-webapps-python.yml
1 parent cae682f commit 8a7914f

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# This workflow will build and push a Python application to an Azure Web App when a commit is pushed to your default branch.
2+
#
3+
# This workflow assumes you have already created the target Azure App Service web app.
4+
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=bash&pivots=python-framework-flask
5+
#
6+
# To configure this workflow:
7+
#
8+
# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
9+
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials
10+
#
11+
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
12+
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret
13+
#
14+
# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the PYTHON_VERSION environment variables below.
15+
#
16+
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
17+
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
18+
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
19+
20+
name: Build and deploy Python app to Azure Web App
21+
22+
env:
23+
AZURE_WEBAPP_NAME: your-app-name # set this to the name of your Azure Web App
24+
PYTHON_VERSION: '3.8' # set this to the Python version to use
25+
26+
on:
27+
push:
28+
branches: [ "main" ]
29+
workflow_dispatch:
30+
31+
permissions:
32+
contents: read
33+
34+
jobs:
35+
build:
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Set up Python version
42+
uses: actions/setup-python@v3.0.0
43+
with:
44+
python-version: ${{ env.PYTHON_VERSION }}
45+
cache: 'pip'
46+
47+
- name: Create and start virtual environment
48+
run: |
49+
python -m venv venv
50+
source venv/bin/activate
51+
52+
- name: Install dependencies
53+
run: pip install -r requirements.txt
54+
55+
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
56+
57+
- name: Upload artifact for deployment jobs
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: python-app
61+
path: |
62+
.
63+
!venv/
64+
65+
deploy:
66+
permissions:
67+
contents: none
68+
runs-on: ubuntu-latest
69+
needs: build
70+
environment:
71+
name: 'Development'
72+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
73+
74+
steps:
75+
- name: Download artifact from build job
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: python-app
79+
path: .
80+
81+
- name: 'Deploy to Azure Web App'
82+
id: deploy-to-webapp
83+
uses: azure/webapps-deploy@v2
84+
with:
85+
app-name: ${{ env.AZURE_WEBAPP_NAME }}
86+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}

0 commit comments

Comments
 (0)