page_type | description | products | languages | urlFragment | |||
---|---|---|---|---|---|---|---|
sample |
Deploy Python application using GitHub Actions |
|
|
Learn to deploy a Python package to Azure App Service and set up a CI/CD workflow using GitHub Actions
GitHub Actions gives you the flexibility to build an automated software development lifecycle workflow. You can write individual tasks ("Actions") and combine them to create a custom workflow. Workflows are configurable automated processes that you can set up in your repository to build, test, package, release, or deploy any project on GitHub.
With GitHub Actions you can build end-to-end continuous integration (CI) and continuous deployment (CD) capabilities directly in your repository.
-
You will need a GitHub account. If you do not have one, you can sign up for free here
-
Microsoft Azure Account: You will need a valid and active Azure account for this lab. If you do not have one, you can sign up for a free trial.
Fork this repo and open the sample app code in VS Code to get started.
Create a web app hosted in Azure with a unique name, Linux as the OS and Python 3.7 as the runtime.
![](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/deploytoazure.png)
![](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/1-CONTRIBUTION-GUIDE/images/visualizebutton.png)
This template creates a web app on azure with Python 3.7 enabled allowing you to run Python applications in Azure.
The web app with Python is an app service that allow you to deploy your Django or Flask website. This will deploy a free tier Linux App Service Plan where you will host your App Service.
If you are new to Azure App Service, see:
If you are new to template deployment, see:
We'll use GitHub actions to automate our deployment workflow for this web app.
-
Navigate to the sample CI/CD workflow file
workflow.yml
in your GitHub repo under.github/workflows/
folder path -
Modify the values of the environment variables based on your Azure app:
env:
AZURE_WEBAPP_NAME: your-app-name # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.7' # set this to the Python version to use
-
In the portal, Overview page, click on "Get publish profile". A publish profile is a kind of deployment credential, useful when you don't own the Azure subscription. Open the downloaded settings file in VS Code and copy the contents of the file.
-
We will now add the publish profile as a secret associated with this repo. On the GitHub repository, click on the "Settings" tab.
-
Go to "Secrets". Create a new secret called "AZURE_WEBAPP_PUBLISH_PROFILE" and paste the contents from the settings file.
-
Once you're done editing the workflow by configuring the required environment variables, click on "Start commit". Committing the file will trigger the workflow.
-
You can go back to the Actions tab, click on your workflow, and see that the workflow is queued or being deployed. Wait for the job to complete successfully.
-
Browse your app by pasting the URL of your Azure web app: https://AZURE_WEBAPP_NAME.azurewebsites.net
-
Make any changes by editing the app contents and commit the changes. Browse to the Actions tab in GitHub to view the live logs of your Action workflow which got triggered with the push of the commit.
-
Once the workflow successfully completes execution, browse back to your website to visualise the new changes you introduced!
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.