During the Qiita Azure posting campaign, I've summarized how to deploy a GitHub repository to Azure because it's a good opportunity. It was surprisingly easy with the VS Code extension Deploy to Azure.
Use GitHub for the repository and Azure AppService for the deployment destination. Action of GitHub is used for linking from GitHub to Azure, but basically the extension of VS Code does it for you, so even first-time users can easily do it.
Create a GitHub repository. No special settings are required, so they will be omitted.
Create a resource for the AppService to deploy to. Basically, it will be created in the Azure portal.
2.1. Log in to the portal and go to the App Service screen.
2.2. Click the Add button from the AppService screen to move to the resource creation screen.
2.3. Enter the information required to create the resource.
If you can create it properly, a screen like this will be displayed.
Since it is troublesome to manually write the yaml file used for Action on GitHub, I will use the extension of VS Code.
Clone the GitHub repository and add the source you want to deploy.
python -m pip freeze> requirements.txt
`command.If you use VS Code's Deploy to Azure extension, it will automatically generate a yaml of Action on GitHub. Since it is troublesome to make yaml from 1, install Deploy to Azure.
Since it is required for Deploy to Azure, get an AccessToken according to the following GitHub Docs. https://docs.github.com/ja/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
3.1. Open the cloned directory with VS Code, open the command palette with Ctr + Shift + P, and execute the Deploy to Azure: Configure CI / CD Pipeline command. 3.2. You will be asked for the Access Token on GitHub, so enter the Access Token you obtained in advance. 3.3. You will be asked for the environment and subscription of the web service, so enter it. 3.4. The fourth input item should be the resource name of the Azure App Service created in 2, so select it.
If you enter so far, you should see `` `.github \ workflows \ workflow.yml``` in the open directory.
Depending on the environment, v1 actions may not be available, so modify azure / webapps-deploy @ v1
to azure / webapps-deploy @ v2
.
All you have created so far will be reflected in the GitHub repository. When you push the source, Action on GitHub will read yaml and execute it until deployment.
If you want to see the progress of Action, select the target repository on GitHub, click the Actions tab, and the workflow of Action is running with a commit message.
It is completed when it becomes as follows.
If you add code to this yaml, you can also automate the test. By the way, if the test fails, the Action will stop and it will not be deployed. The following is an example added when running pytest
workflow.yml
- name: pytest
working-directory: .
run: |
pip install pytest
pip install -r requirements.txt
python -m pytest
I summarized how to deploy Azure. There is also a function called DevOps starter in Azure that allows you to do everything written here with GUI, but since the default was python2 and unnecessary things such as dashboard etc. came with it, I summarized this method that I can do as I like. ..
Recommended Posts