How to deploy azure app service with azure cli from local git

2 months ago

This tutorial is additon to the ms azure tutorial

https://docs.microsoft.com/vi-vn/azure/app-service/quickstart-python?tabs=bash&pivots=python-framework-flask
Install azure cli
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli
Login to azure

az login

it will open brower for you to login.
After login.
Check your current subscription
Your active subscription is marked as True in the IsDefault column.

az account list -o table
Name                  CloudName    SubscriptionId                        State    IsDefault
--------------------  -----------  ------------------------------------  -------  -----------
Azure subscription 1  AzureCloud   id1                                   Enabled  True
Azure subscription 2  AzureCloud   id2                                   Enabled  False

As you can see you currently in Azure subscription 1 to change subscription

 az account set --subscription subscription 2

You dont need to type the whole subscription name. Just type G and tab
Now check again

az account list -o table
Name                  CloudName    SubscriptionId                        State    IsDefault
--------------------  -----------  ------------------------------------  -------  -----------
Azure subscription 1  AzureCloud   id1                                   Enabled  False
Azure subscription 2  AzureCloud   id2                                   Enabled  True

Now you are in the right subscription.
Check list app app service

az webapp list

If you got error

To fix that you need to insetall decorator

 pip install decorator
# output
Collecting decorator
  Downloading decorator-5.0.9-py3-none-any.whl (8.9 kB)
Installing collected packages: decorator
Successfully installed decorator-5.0.9

Create deployment git local

Option 1:
CLI

az webapp deployment source config-local-git --resource-group proj1 --name vt1test
# output
{
  "url": "https://None@vt1test.scm.azurewebsites.net/vt1test.git"
}

Option 2: Azure portal
https://docs.microsoft.com/en-us/azure/app-service/deploy-local-git?tabs=portal

It will show you the git url after

Connect local to app service git

# git uri Format
https://<app-name>.scm.azurewebsites.net/<app-name>.git

git remote set-url origin https://vt1test.scm.azurewebsites.net:443/vt1test.git

Test git remote
 

git remote -v
# output
origin  https://vt1test.scm.azurewebsites.net:443/vt1test.git (fetch)
origin  https://vt1test.scm.azurewebsites.net:443/vt1test.git (push)

Test git pus
 

git push
fatal: Authentication failed for 'https://vt1test.scm.azurewebsites.net:443/vt1test.git/'

You will get an Authentication failed error
To fix that:

Deployment center

Now go to app service -> deployment center -> Local Git/FPTS credentials

Scroll down to user scope and set new username and password



Option 1: check your local git credential username

git config --list
user.name=VUONGT1
user.email=vuong@vuong.com
user.username=Vuong
credential.username=vt1test # copy this username and paste in the username above
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://vt1test.scm.azurewebsites.net:443/vt1test.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

Option 2: Set username in portal then update your local username.
Set username and password. Example username: vt1test password: your_password
Now update your local username
 

git config --global --edit
# Out put

[user]
        name = VUONGT1
        email = vuong@vuong.com
        username = Vuong
[credential]
        username = vt1test # here is your username

Check git push again it will work

git push
Enumerating objects: 75, done.
Counting objects: 100% (75/75), done.
Delta compression using up to 8 threads
Compressing objects: 100% (71/71), done.


Now check your app url for the update.

To update you can just change your local branch then git push comment again.
Done!

Update:

How to update new code from source control?

git pull git@github.com:cotcac/python-docs-hello-world.git

or

git remote add something git://host.example.com/path/to/repo.git
git checkout master
git pull something master

https://stackoverflow.com/questions/12921125/git-merge-branch-of-another-remote