Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Python sample app to demonstrate GitHub Actions - The cat said no!

License

Notifications You must be signed in to change notification settings

Azure-Samples/pythonSample_thecatsaidno

Repository files navigation

page_type description products languages urlFragment
sample
Deploy Python application using GitHub Actions
GitHub Actions
Azure App service
Python

Deploying a Python Web App using GitHub actions

Learn to deploy a Python package to Azure App Service and set up a CI/CD workflow using GitHub Actions

Overview

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.

Prerequisites

  1. You will need a GitHub account. If you do not have one, you can sign up for free here

  2. 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.

Setting up the GitHub repository

Fork this repo and open the sample app code in VS Code to get started.

Create an Azure App Service

Create a web app hosted in Azure with a unique name, Linux as the OS and Python 3.7 as the runtime.

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:

Set up CI/CD workflow with GitHub Actions

We'll use GitHub actions to automate our deployment workflow for this web app.

  1. Navigate to the sample CI/CD workflow file workflow.yml in your GitHub repo under .github/workflows/ folder path

  2. 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
  1. 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.

  2. We will now add the publish profile as a secret associated with this repo. On the GitHub repository, click on the "Settings" tab.

  3. Go to "Secrets". Create a new secret called "AZURE_WEBAPP_PUBLISH_PROFILE" and paste the contents from the settings file.

  4. Once you're done editing the workflow by configuring the required environment variables, click on "Start commit". Committing the file will trigger the workflow.

  5. 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.

  6. Browse your app by pasting the URL of your Azure web app: https://AZURE_WEBAPP_NAME.azurewebsites.net

  7. 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.

  8. Once the workflow successfully completes execution, browse back to your website to visualise the new changes you introduced!

Contributing

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 [email protected] with any additional questions or comments.

About

Python sample app to demonstrate GitHub Actions - The cat said no!

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •