I am trying to deploy a test project using the Flask
framework into the azure cloud using the Azure CLI
https://learn.microsoft.com/en-us/azure/app-service/containers/quickstart-python?tabs=bash
https://learn.microsoft.com/en-us/azure/app-service/containers/how-to-configure-python
There are some issues regarding the runtime_version
of my app. Everytime I try to run the command for deploying it tries to upgrade the runtime_version to the python|3.7
even if I set it to the python|3.8
in the settings and then the deployment fails. It has to be set to python|3.7
to be succesfully deployed.
The app is quite simple:
from flask import Flask
from markupsafe import escape
app = Flask(__name__)
@app.route('/')
def index():
return 'Index page'
@app.route('/hello')
def hello_world():
return 'Hello, World!!!'
@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return 'User %s' % escape(username)
@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an int
return 'Post %d' % post_id
@app.route('/path/<path:subpath>')
def show_subpath(subpath):
# show the subpath after /path/
return 'Subpath %s' % escape(subpath)
@app.route('/projects/')
def projects():
return 'The project page'
@app.route('/about')
def about():
return 'The about page'
I also created a requirements.txt file with the required packages as recommended in the microsoft documentation.
click==7.1.2
flask==1.1.2
itsdangerous==1.1.0
jinja2==2.11.2
markupsafe==1.1.1
werkzeug==1.0.1
And this is the command I used to deploy the application the first time
az webapp up --sku F1 -l westeurope -n XXXXXX-blf
Output:
(venv) D:\dev\FlaskTesting [master ≡ +4 ~0 -1 !]> az webapp up --sku F1 -l westeurope -n XXXXXX-blf
webapp XXXXXX-blf doesn't exist
Creating Resource group 'InsaneSpeech_rg_Linux_westeurope' ...
Resource group creation complete
Creating AppServicePlan 'InsaneSpeech_asp_Linux_westeurope_0' ...
Creating webapp 'XXXXXX-blf' ...
Creating zip with contents of dir D:\dev\FlaskTesting ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
You can launch the app at http://XXXXXX-blf.azurewebsites.net
{
"URL": "http://XXXXXX-blf.azurewebsites.net",
"appserviceplan": "InsaneSpeech_asp_Linux_westeurope_0",
"location": "westeurope",
"name": "XXXXXX-blf",
"os": "Linux",
"resourcegroup": "InsaneSpeech_rg_Linux_westeurope",
"runtime_version": "python|3.7",
"runtime_version_detected": "-",
"src_path": "D:\\dev\\FlaskTesting"
}
Then I go to the azure portal and try to change the Stack settings
to target Python 3.8
under XXXXXX-blf -> Settings -> Configuration -> General settings -> Stack | Major version / Minor version
After clicking save I try to run again the command to update my code
az webapp up -n python-blf
But this time the output shows an error:
Webapp XXXXXX-blf already exists. The command will deploy contents to the existing app.
Updating runtime version from PYTHON|3.8 to python|3.7
Creating zip with contents of dir D:\dev\FlaskTesting ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
Configuring default logging for the app, if not already enabled
Zip deployment failed. {'id': 'd9ff6c84c00844bf9f988bd4c98c81d6', 'status': 3, 'status_text': '',
'author_email': 'N/A', 'author': 'N/A', 'deployer': 'Push-Deployer', 'message': 'Created via a push deployment',
'progress': '', 'received_time': '2020-07-05T09:10:02.1802651Z', 'start_time': '2020-07-05T09:10:02.3953194Z',
'end_time': '2020-07-05T09:10:18.7991349Z',
'last_success_end_time': None, 'complete': True, 'active': False, 'is_temp': False, 'is_readonly': True,
'url': 'https://XXXXXX-blf.scm.azurewebsites.net/api/deployments/latest',
'log_url': 'https://XXXXXX-blf.scm.azurewebsites.net/api/deployments/latest/log', 'site_name': 'XXXXXX-blf'}.
Please run the command az webapp log deployment show
-n XXXXXX-blf -g InsaneSpeech_rg_Linux_westeurope
I check the log url and this is the issue:
{
"ClassName":"System.IO.FileNotFoundException",
"Message":"No log found for 'latest'.",
"Data":null,
"InnerException":null,
"HelpURL":null,
"StackTraceString":" at Kudu.Core.Deployment.DeploymentManager.GetLogEntries(String id) in /tmp/KuduLite/Kudu.Core/Deployment/DeploymentManager.cs:line 111\n at Kudu.Services.Deployment.DeploymentController.GetLogEntry(String id) in /tmp/KuduLite/Kudu.Services/Deployment/DeploymentController.cs:line 432",
"RemoteStackTraceString":null,
"RemoteStackIndex":0,
"ExceptionMethod":null,
"HResult":-2147024894,
"Source":"Kudu.Core",
"WatsonBuckets":null,
"FileNotFound_FileName":null,
"FileNotFound_FusionLog":null
}
After this issue, without changing anything I can run the same command again and get a correct deployment but with python|3.7
...
(venv) D:\dev\FlaskTesting [master ≡ +5 ~0 -1 !]> az webapp up -n XXXXXX-blf
Webapp XXXXXX-blf already exists. The command will deploy contents to the existing app.
Creating zip with contents of dir D:\dev\FlaskTesting ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
You can launch the app at http://XXXXXX-blf.azurewebsites.net
{
"URL": "http://XXXXXX-blf.azurewebsites.net",
"appserviceplan": "InsaneSpeech_asp_Linux_westeurope_0",
"location": "westeurope",
"name": "XXXXXX-blf",
"os": "Linux",
"resourcegroup": "InsaneSpeech_rg_Linux_westeurope",
"runtime_version": "python|3.7",
"runtime_version_detected": "-",
"sku": "FREE",
"src_path": "D:\\dev\\FlaskTesting"
}
UPDATE
I have configured the CI\CD in azure linked to my github repository and the github actions do deploy on push with my webapp running python 3.8
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Python app to Azure Web App - XXXXXX-blf
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.8'
- name: Build using AppService-Build
uses: azure/appservice-build@v1
with:
platform: python
platform-version: '3.8'
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v1
with:
app-name: 'XXXXXX-blf'
slot-name: 'production'
publish-profile: ${{ XXXXXXXXXXXXXXXXXXX }}
Any idea?