{"id":12651,"date":"2023-10-28T09:29:02","date_gmt":"2023-10-28T07:29:02","guid":{"rendered":"https:\/\/flaven.fr\/?p=12651"},"modified":"2026-09-16T10:12:29","modified_gmt":"2026-09-16T08:12:29","slug":"step-by-step-introducing-to-azure-cloud-deployment-deploying-a-fastapi-ml-feature-api","status":"publish","type":"post","link":"https:\/\/flaven.fr\/2023\/10\/step-by-step-introducing-to-azure-cloud-deployment-deploying-a-fastapi-ml-feature-api\/","title":{"rendered":"Step by step Introducing to Azure Cloud Deployment: Deploying a FastAPI ML Feature API"},"content":{"rendered":"<p>This last post is again a journal to me of an how-to. This time, the post is dedicated on how to deploy in the Cloud a Machine Learning&#8217;s features API, built with FastAPI. For the cloud, I have chosen Azure as I will probably work with it. Indeed, the deployment in the Cloud is the last step to close my Machine Learning&#8217;s API creation process investigation. Previously, I explored roughly all the required steps from ML (Machine Learning) customization to development with FastAPI, through the discovery of specific packages like Whisper, Spacy for instance.<\/p>\n<p><b>For this post, you can find all files for each project on my GitHub account. See <a href=\"https:\/\/github.com\/bflaven\/ia_usages\/tree\/main\/ia_deploy_api_ml_architecture\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/bflaven\/ia_usages\/tree\/main\/ia_deploy_api_ml_architecture<\/a><\/b><\/p>\n<p>For such exploration, I know the drill by now! Based on some stakeholders needs, I came to the unsurprising conclusion that the target will be an API, developed in Python with FastAPI, hosted in the Azure Cloud, exposing value-added AI &#8220;features&#8221; based on different models such as  the ones provided by Spacy or Whisper for various contents type such as Audio, Text, Image&#8230; overcoming as much as possible the multilingual issue for non-English languages.<\/p>\n<p>In these last months, I just more or less consciously combine a Design Thinking Process with DevOps Lifecycle. All that remains now is to iterate on this workflow to refine the API creation segments.<\/p>\n<p>In a near future, I will shed some light over the overall methodology that has inspired me, this natural combination between Design Thinking Process &#038; DevOps Lifecycle.<\/p>\n<h2>1. Methodology reminder: Involuntarily mixing Design Thinking Process &#038; DevOps Lifecycle<\/h2>\n<p><b>I did not intend to do so but involuntarily I have taken a mix of the two methods. At least, their keywords\/values have been my compass during this first part of a journey through IA!<br \/>\nJust as reminder for myself, for each method, here are both the basic and an acronym forged like a mantra to remember these keywords\/core values.<\/b><\/p>\n<h3>1.1 Design Thinking Process<\/h3>\n<blockquote><p>\n&#8220;Design thinking should bring your ideas to life by putting users at the center of every process.&#8221;\n<\/p><\/blockquote>\n<p><b>Acronym: E.D.I.P.T<\/b><\/p>\n<ul>\n<li><b>Empathize<\/b> \u2013 Understanding people<\/li>\n<li><b>Define<\/b> \u2013 Figuring out the problem<\/li>\n<li><b>Ideate<\/b> \u2013 Generating your ideas<\/li>\n<li><b>Prototype<\/b> \u2013 Creation and experimentation<\/li>\n<li><b>Test<\/b> \u2013 Refining the product<\/li>\n<\/ul>\n<h3>1.2 DevOps Lifecycle<\/h3>\n<p>DevOps is a software development methodology that combines software development (Dev) with information technology operations (Ops), blending these two worlds in the entire service lifecycle: from the initial product design, through the whole development process, and to production support.<\/p>\n<p><b>Acronym: P.C.B.T.P.R.O.M<\/b><\/p>\n<ul>\n<li><b>Planning:<\/b> task management, schedules.<\/li>\n<li><b>Coding:<\/b> code development and review, source code management tools, code merging.<\/li>\n<li><b>Building:<\/b> continuous integration tools, version control tools, build status.<\/li>\n<li><b>Testing:<\/b> continuous testing tools that provide quick and timely feedback on business risks, performance measurement.<\/li>\n<li><b>Packaging:<\/b> artifact repository, application pre-deployment staging.<\/li>\n<li><b>Releasing:<\/b> change management, release approvals, release automation.<\/li>\n<li><b>Operating:<\/b> infrastructure installation, configuration and management, infrastructure changes (scalability), infrastructure as code tools, capacity planning, capacity &#038; resource management, security check, service deployment, high availability (HA), data recovery, log\/backup management, database management.<\/li>\n<li><b>Monitoring:<\/b> service performance monitoring, log monitoring, applications performance monitoring, end-user experience, incident management.<\/li>\n<\/ul>\n<h2>2. Experiments to prepare deployment of POC, made with FastAPI, on Azure<\/h2>\n<p>Let&#8217;s get down to practice without further delay. On many subjects and particularly on artificial intelligence, far too many people pay lip service.<\/p>\n<p><b>Here is the code produced through the different experiments that I made to understand deploy on Azure for a webapp.<\/b><\/p>\n<ul>\n<li>advanced_docker_compose_fastapi: several example using docker-compose and Makefile.<\/li>\n<li>api_fastapi_routes: routing issue and different solutions provided with the help of ChatGPT<\/li>\n<li>fastapi-simple-app: simple app to deploy<\/li>\n<li>fastapi_cheatsheet: cheat sheet for fastapi for documentation especially. <\/li>\n<li>fastapi_tiangolo_advanced_settings: advanced setting examples. <\/li>\n<li>mamamia-fastapi-azure: application, written with the help of ChatGPT, made with FastAPI deployed to the Azure Cloud.<\/li>\n<\/ul>\n<h2>3. Requirement: Using docker is a requirement to deploy on Azure<\/h2>\n<p>Well, you will quickly discover that the must-have to deploy on Azure is to use Docker.<br \/>\n<b>Docker enable you to create en development environment for your app and then deploy it to Azure. Moreover, Docker makes it easy to get started and enables easier switching between projects, operating systems, and machines.<\/b><\/p>\n<p>According to me, here are the two pitfalls that I learn from Docker usage:<\/p>\n<ol>\n<li>Clean often Images and Containers: Docker takes huge amount of space disk on your local disk as you are going to create images, containers and so on. So, you must learn quickly how to undo. Undo means to clean up your local disk and get rid of the images and containers.<\/li>\n<li>Leverage on docker-compose.yaml &#038; Makefile: Docker require a to know\/learn a bunch of commands and concepts that will slow down your learning curb. <b>The best idea to optimize this task is by adding to your project a docker-compose.yaml and Makefile to manage the Docker for FastAPI. The Makefile is the &#8216;entrypoint&#8217; for the tools in this structure, such that you can easily run different commands without remembering the exact arguments.<\/b><\/li>\n<\/ol>\n<p><i>Source: <a href=\"https:\/\/github.com\/BiteStreams\/fastapi-template\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/BiteStreams\/fastapi-template<\/a><\/i><\/p>\n<h2>4. How-to: Deploying a containerized FastAPI app to Azure Container Apps<\/h2>\n<p>Below here is the best post that I have found made by Pamela Fox, Principal Cloud Advocate at Microsoft. I am truly focusing only on the step by step to deploy a very simple fastapi on Azure services.<\/p>\n<p>Source: <a href=\"https:\/\/blog.pamelafox.org\/2023\/03\/deploying-containerized-fastapi-app-to.html\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.pamelafox.org\/2023\/03\/deploying-containerized-fastapi-app-to.html<\/a><\/p>\n<p>I have described each step as much detail as possible because I have an annoying tendency to forget steps or to not remember commands. I also hate typing these very commands. It is the reason I added so many Makefiles or scripts to all the projects. Let do the computers do the work for me. This is the great benefit of IT, namely automation, even if sometimes it is as said Peter Drucker &#8220;There is surely nothing quite so useless as doing with great efficiency what should not be done at all.&#8221;<\/p>\n<p><H3>4.1. Installing and Using Azure Cli<\/H3><br \/>\n<b>The first thing to do is to install Azure Cli<\/b><\/p>\n<pre class=\"php\">\r\n\r\n# SOME COMMANDS FOR AZURE CLI\r\n\r\n# Install the azure-cli\r\nbrew update && brew install azure-cli\r\n\r\n# Check the install\r\naz --version\r\n\r\n# Log in to Azure\r\naz login\r\n\r\n# By default, this command logs in with a user account. CLI will try to launch a web browser to log in interactively. If a web browser is not available, CLI will fall back to device code login. To login with a service principal, specify --service-principal.\r\n<\/pre>\n<p><H3>4.2. Create a simple FastAPI App to deploy to Azure<\/H3><br \/>\n<b>You need to have an app to deploy! Right? Here is a simple one below. You can find some more on my github account in &#8220;simple-app-fastapi-azure&#8221; and in &#8220;mamamia-fastapi-azure&#8221;<\/b><\/p>\n<p><b>For this post, you can find all files for each project on my GitHub account. See <a href=\"https:\/\/github.com\/bflaven\/ia_usages\/tree\/main\/ia_deploy_api_ml_architecture\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/bflaven\/ia_usages\/tree\/main\/ia_deploy_api_ml_architecture<\/a><\/b><\/p>\n<pre>\r\n# go to the dir\r\ncd \/Users\/brunoflaven\/Documents\/03_git\/ia_usages\/ia_deploy_api_ml_architecture\r\n\r\n# make a directory named \"simple-app-fastapi-azure\"\r\nmkdir simple-app-fastapi-azure\r\n\r\n# get into the directory named \"simple-app-fastapi-azure\"\r\ncd simple-app-fastapi-azure\r\n\r\n# command to delete the all directory\r\nrm -R simple-app-fastapi-azure\r\n\r\n# create the FastAPI files\r\n# you can create all the files at once\r\ntouch main.py requirements.txt Dockerfile .dockerignore\r\n# and the cut and paste the code for each file.\r\n<\/pre>\n<p>For the code to put in each file. See below. It reduces to the minimum.<\/p>\n<p><b>1. main.py<\/b><\/p>\n<pre>\r\n#!\/usr\/bin\/python\r\n# -*- coding: utf-8 -*-\r\n#\r\nfrom fastapi import FastAPI, File, status\r\nfrom fastapi.responses import RedirectResponse\r\nfrom fastapi.responses import StreamingResponse\r\nfrom fastapi.responses import FileResponse\r\nfrom fastapi.middleware.cors import CORSMiddleware\r\nfrom fastapi.exceptions import HTTPException\r\n \r\napp = FastAPI()\r\n\r\n# home\r\n@app.get(\"\/\")\r\nasync def home():\r\n    # return RedirectResponse(\"\/docs\")\r\n    return {'Azure FastAPI test api': 'It is running'}\r\n\r\n    \r\n    \r\n<\/pre>\n<p><b>2. requirements.txt<\/b><\/p>\n<pre>\r\nfastapi\r\nuvicorn\r\n<\/pre>\n<p><b>3. Dockerfile<\/b><\/p>\n<pre>\r\n# Choose our version of Python\r\nFROM python:3.9\r\n\r\n# Set up a working directory\r\nWORKDIR \/code\r\n\r\n# Copy just the requirements into the working directory so it gets cached by itself\r\nCOPY requirements.txt .\r\n\r\n# Install the dependencies from the requirements file\r\nRUN pip install --no-cache-dir --upgrade -r requirements.txt\r\n\r\n# Copy the code\r\nCOPY . .\r\n\r\nEXPOSE 80\r\n\r\nCMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"80\", \"--proxy-headers\"]\r\n<\/pre>\n<p><b>4. .dockerignore<\/b><br \/>\nI have picked an extended model for .dockerignore on this site: <a href=\"https:\/\/shisho.dev\/blog\/posts\/how-to-use-dockerignore\/\" target=\"_blank\" rel=\"noopener\">https:\/\/shisho.dev\/blog\/posts\/how-to-use-dockerignore\/<\/a><\/p>\n<pre>\r\n__pycache__\r\n*.pyc\r\n*.pyo\r\n*.pyd\r\n.Python\r\nenv\r\npip-log.txt\r\npip-delete-this-directory.txt\r\n.tox\r\n.coverage\r\n.coverage.*\r\n.cache\r\nnosetests.xml\r\ncoverage.xml\r\n*.cover\r\n*.log\r\n.git\r\n.mypy_cache\r\n.pytest_cache\r\n.hypothesis\r\nMakefile\r\nREADME.md\r\n<\/pre>\n<p><b>If you have a development environment, you can test your API.  A development environment is made with tools like Anaconda, Poetry, Venv&#8230; etc. I am using Anaconda.<\/b><\/p>\n<pre>\r\n\r\n# V1\r\n# launch the app\r\nuvicorn main:app --reload\r\n\r\n# in a browser you can check type URL\r\nhttp:\/\/127.0.0.1:8000\r\nhttp:\/\/localhost:8000\r\n# I have declared in my hosts file cypress.mydomain.priv pointed to 127.0.0.1\r\nhttp:\/\/cypress.mydomain.priv:8000\r\n\r\n# ctrl+c to stop the server\r\n\r\n# V2\r\n# launch the app\r\nuvicorn main:app --host 0.0.0.0 --port 80 --reload\r\n\r\n# in a browser you can check type URL\r\nhttp:\/\/127.0.0.1\r\nhttp:\/\/localhost\r\n# I have declared in my hosts file cypress.mydomain.priv pointed to 127.0.0.1\r\nhttp:\/\/cypress.mydomain.priv\r\n\r\n\r\n# See more at https:\/\/fastapi.tiangolo.com\/deployment\/manually\/\r\n<\/pre>\n<p><H3>4.3. Using Docker<\/H3><\/p>\n<p>Before the deployment in itself on Azure, it is better to run locally this new API you just build with the help of Docker.<\/p>\n<pre>\r\n\r\n# get into the dir\r\ncd \/Users\/brunoflaven\/Documents\/03_git\/ia_usages\/ia_deploy_api_ml_architecture\/simple-app-fastapi-azure\r\n\r\n# START with increment the tags e.g test1, test2, test3... etc\r\n\r\n# build the Docker image named \"bf-fastapi-demo:test2\"\r\ndocker build --tag bf-fastapi-demo:test2 .\r\n# The application Docker has to be up and running\r\n\r\n# run a container named \"test2-bf-fastapi-container\". It is an instance of an image named \"bf-fastapi-demo:test1\"\r\ndocker run -d --name test2-bf-fastapi-container -p 80:80 bf-fastapi-demo:test2\r\n\r\n# The Dockerfile tells FastAPI to use a port of 80, so the run command publishes the container's port 80 as port 80 on the local computer. I visit localhost:80 to confirm that my API is up and running. &#x1f3c3;&#x1f3fd;&#x200d;&#x2640;&#xfe0f;\r\n\r\n# check the app locally\r\nhttp:\/\/localhost:80\r\n\r\n# list the images\r\ndocker ps\r\n\r\n# stop the container test2-bf-fastapi-container\r\ndocker stop test2-bf-fastapi-container\r\n\r\n# remove the container test2-bf-fastapi-container\r\ndocker rm -f test2-bf-fastapi-container\r\n\r\n\r\n# remove the image with bf-fastapi-demo:test2\r\ndocker rmi --force bf-fastapi-demo:test2\r\n\r\n\r\n# END If you change the code, you can restart from START above and redo the commands.\r\n\r\n# NUKE DOCKER IMAGES AND CONTAINERS\r\n# remove all containers\r\ndocker rm -f $(docker ps -aq)\r\n\r\n\r\n\r\n# remove everything\r\ndocker system prune\r\n\r\n<\/pre>\n<p><H3>4.4. Deploying to Azure<\/H3><\/p>\n<p>Then it is time to play in the big leagues and deploy on Azure your application. One According to me, Deployment has to be treated as non-event for a POC or a real application. It has to occur as much as possible as its is the best way to learn form your errors.<\/p>\n<p>Here is a list of REQUIRED VALUES that you are going to manipulate. Behind these values you have element that interact with the azure platform. I found handy to make a list to figure out before stating the deployment process all the values required.<\/p>\n<pre>\r\n# Example of model project\r\n# See https:\/\/blog.pamelafox.org\/2023\/03\/deploying-containerized-fastapi-app-to.html\r\n\r\ndocker-image-name = fastapi-demo\r\nregistry-name = pamelascontainerregistry\r\nregistry-server-login-server = pamelascontainerregistry.azurecr.io\r\nresource-group = fastapi-aca-rg\r\ncontainer-registry = application-name = pamelascontainerregistry\r\ncontainer-env = fastapi-aca-env\r\n\r\n# Example for a personal project\r\ndocker-image-name = fastapi-try-demo\r\nregistry-name = maltryappkdo001\r\nlogin-server = maltryappkdo001.azurecr.io\r\nresource-group = fastapi-try-rg\r\ncontainer-registry = application-name = maltryappkdo001\r\ncontainer-env = fastapi-try-env\r\n<\/pre>\n<p><H4><b>4.1 Push image to registry<\/b><\/H4><\/p>\n<p>This step is required before publishing any app on Azure. When this step is completed, you do not have to redo this step, you are just updating an existing app, you can jump directly to the point 3.4<\/p>\n<pre>\r\n\r\n# Go to the dir\r\ncd \/Users\/brunoflaven\/Documents\/01_work\/blog_articles\/ia_deploy_api_ml_architecture\/simple-app-fastapi-azure\/\r\n\r\n\r\n# Deploying Option #2: Step-by-step az commands\r\n# STEP_1. check the install\r\naz --version\r\n\r\n# STEP_2. Requirement, you must be logged\r\naz login\r\n\r\n# By default, this command logs in with a user account. CLI will try to launch a web browser to log in interactively. If a web browser is not available, CLI will fall back to device code login. To login with a service principal, specify --service-principal.\r\n\r\n# STEP_3. Create a resource group\r\n# Careful you can reuse an existing one but in this example I created from scratch\r\n# COMMAND MODEL :: az group create --location eastus --name fastapi-aca-rg\r\n\r\n# COMMAND GOOD\r\naz group create --location eastus --name fastapi-try-rg\r\n\r\n# if you need to delete\r\naz group delete --name fastapi-try-rg\r\n\r\n\r\n# STEP_4. Create a container registry wannatrycontainerregistry for the resource group \"fastapi-try-rg\"\r\n\r\n# COMMAND MODEL :: az acr create --resource-group fastapi-aca-rg \\ --name pamelascontainerregistry --sku Basic\r\n\r\n# COMMAND GOOD\r\naz acr create --resource-group fastapi-try-rg --name wannatrycontainerregistry --sku Basic\r\n\r\n\r\n# STEP_5. Log into the registry so that later commands can push images to it:\r\n# COMMAND MODEL :: az acr login --name pamelascontainerregistry\r\n\r\n# COMMAND GOOD\r\naz acr login --name wannatrycontainerregistry\r\n\r\n\r\n\r\n# STEP_6. uploads the code to cloud and builds it there:\r\n# COMMAND MODEL :: az acr build --platform linux\/amd64 -t pamelascontainerregistry.azurecr.io\/fastapi-try:latest -r pamelascontainerregistry .\r\n\r\n# must be in a directory with a Dockerfile\r\n# cd \/Users\/brunoflaven\/Documents\/03_git\/ia_usages\/ia_deploy_api_ml_architecture\/simple-app-fastapi-azure\r\n\r\n# COMMAND GOOD\r\naz acr build --platform linux\/amd64 -t wannatrycontainerregistry.azurecr.io\/fastapi-try:latest -r wannatrycontainerregistry .\r\n\r\n\r\n<\/pre>\n<p><H4><b>4.2 Deploy to Azure Container App<\/b><\/H4><\/p>\n<pre>\r\n\r\n# You must be in the directory of your app \r\n# cd \/Users\/brunoflaven\/Documents\/03_git\/ia_usages\/ia_deploy_api_ml_architecture\/simple-app-fastapi-azure\r\n\r\n\r\n# STEP_1: (OPTIONNAL) Upgrade the extension and register the necessary providers:\r\naz extension add --name containerapp --upgrade\r\naz provider register --namespace Microsoft.App\r\naz provider register -n Microsoft.OperationalInsights --wait\r\n\r\n# STEP_2: Create an environment for the container app:\r\n# COMMAND MODEL :: az containerapp env create --name fastapi-aca-env \\\r\n    --resource-group fastapi-aca-rg --location eastus\r\n\r\n# COMMAND GOOD\r\naz containerapp env create --name fastapi-try-env --resource-group fastapi-try-rg --location eastus\r\n\r\n\r\n\r\n# This will output the URL aka defaultDomain e.g : \r\n# orangesmoke-cceb35b3.eastus.azurecontainerapps.io\r\n# purpleground-2c63d040.eastus.azurecontainerapps.io\r\n\r\n\r\n# STEP_3: You must enable the admin:\r\n# Run 'az acr update -n pamelascontainerregistry --admin-enabled true' to enable admin first.\r\n\r\n# COMMAND GOOD\r\naz acr update -n wannatrycontainerregistry --admin-enabled true\r\n\r\n# STEP_4: Generate credentials to use for the next step:\r\n# COMMAND MODEL :: az acr credential show --name pamelascontainerregistry\r\n\r\n# output where you get the password\r\n\r\n# COMMAND GOOD\r\naz acr credential show --name wannatrycontainerregistry\r\n\r\n# OUPUT where you can find the password.\r\n{\r\n  \"passwords\": [\r\n    {\r\n      \"name\": \"password\",\r\n      \"value\": \"FAKE+Ubb8iqWTtnDVDZg1ylHcCtHTTogZDt6iULcbKC+XXXXXXXXX\"\r\n    },\r\n    {\r\n      \"name\": \"password2\",\r\n      \"value\": \"FAKE+lwCMl71GlToW8YyeAsGaskVE4X8oLE2S8HipB+XXXXXXXXX\"\r\n    }\r\n  ],\r\n  \"username\": \"wannatrycontainerregistry\"\r\n}\r\n\r\n\r\n# STEP_5: Create the container app, passing in the username and password from the credentials:\r\n\r\n# COMMAND MODEL \r\naz containerapp create --name fmm-fastapi-app \\\r\n    --resource-group fmm-fastapi-rg \\\r\n    --image pamelascontainerregistry.azurecr.io\/fastapi-aca:latest \\\r\n    --environment fastapi-aca-env \\\r\n    --registry-server pamelascontainerregistry.azurecr.io \\\r\n    --registry-username pamelascontainerregistry \\\r\n    --registry-password PASSWORD_HERE \\\r\n    --ingress external \\\r\n    --target-port 80\r\n\r\n# COMMAND GOOD\r\n# Do not forget to replace the password with one show earlier\r\n\r\naz containerapp create --name try-fastapi-app \\\r\n    --resource-group try-fastapi-rg \\\r\n    --image wannatrycontainerregistry.azurecr.io\/try-fastapi:latest \\\r\n    --environment try-fastapi-env \\\r\n    --registry-server wannatrycontainerregistry.azurecr.io \\\r\n    --registry-username wannatrycontainerregistry \\\r\n    --registry-password PASSWORD_HERE \\\r\n    --ingress external \\\r\n    --target-port 80\r\n\r\n\r\n\r\n# Output you have your f... latestRevisionFqdn where it is the url where the app live ! Bingo\r\n\r\n<\/pre>\n<p><H4><b>4.3 If you need to clean up everything on Azure<\/b><\/H4><\/p>\n<p>CAUTION: I like to undo thing or I should even say nuke things. This command is the perfect one, you &#8220;kill&#8221; all your azure environment from group to app deployed. With great power comes great responsibility.<\/p>\n<pre>\r\n\r\n# CAUTION: with this command, you will remove and clean up everything\r\naz group delete --name try-fastapi-rg\r\n\r\n<\/pre>\n<p><H4><b>4.4 If you need to update an existing application on Azure<\/b><\/H4><br \/>\nHere the most useful 2 commands as you may change some stuff in your application, every time you want to deploy just perform these 2 commands. You must be in the root application directory and ensure that the application is running locally with Docker.<\/p>\n<pre>\r\n# You must be in the directory of your app \r\n# cd \/Users\/brunoflaven\/Documents\/03_git\/ia_usages\/ia_deploy_api_ml_architecture\/simple-app-fastapi-azure\/\r\n\r\n# Do not forget to login if needed. Requirement, you must be logged\r\n# az login\r\n\r\n\r\n# Make any code updates just re-build the image (step_1) and tell the container app to update (step_2):\r\n# COMMAND MODEL :: STEP_1 \r\naz acr build --platform linux\/amd64 \\\r\n    -t pamelascontainerregistry.azurecr.io\/fastapi-aca:latest \\\r\n    -r pamelascontainerregistry .\r\n\r\n# COMMAND MODEL :: STEP_2\r\naz containerapp update --name fastapi-aca-app \\\r\n  --resource-group fastapi-aca-rg \\\r\n  --image pamelascontainerregistry.azurecr.io\/fastapi-aca:latest\r\n\r\n\r\n# COMMAND_GOOD_1\r\naz acr build --platform linux\/amd64 \\\r\n    -t wannatrycontainerregistry.azurecr.io\/try-fastapi:latest \\\r\n    -r wannatrycontainerregistry .\r\n\r\n# COMMAND_GOOD_2\r\naz containerapp update --name try-fastapi-app \\\r\n  --resource-group try-fastapi-rg \\\r\n  --image wannatrycontainerregistry.azurecr.io\/try-fastapi:latest \r\n\r\n# show the log\r\naz webapp log tail --name wannatrycontainerregistry --resource-group try-fastapi-rg\r\n\r\n# show the group\r\naz group show --name try-fastapi-rg\r\n\r\n\r\n<\/pre>\n<p><H4><b>4.5 The magic command &#8220;all-in-one&#8221;<\/b><\/H4><br \/>\nA unique command that &#8220;Create or update a container app as well as any associated resources (ACR, resource group, container apps environment, GitHub Actions, etc.).&#8221;<\/p>\n<pre>\r\n# COMMAND UNIQUE MODEL \r\naz containerapp up \\\r\n  -g fastapi-aca-rg \\\r\n  -n fastapi-aca-app \\\r\n  --registry-server pamelascontainerregistry.azurecr.io \\\r\n  --ingress external \\\r\n  --target-port 80 \\\r\n  --source .\r\n\r\n# CAUTION the registry-server must exist\r\n\r\n# COMMAND_GOOD UNIQUE\r\naz containerapp up \\\r\n  -g try-fastapi-rg \\\r\n  -n try-fastapi-app \\\r\n  --registry-server wannatrycontainerregistry.azurecr.io \\\r\n  --ingress external \\\r\n  --target-port 80 \\\r\n  --source .\r\n<\/pre>\n<h2>5. Other infos<\/h2>\n<p>I just note down few elements on solutions to the obstacles encountered or essential commands. FOMO syndrom?<\/p>\n<p><H3>5.1 Fixed issue on path on Poetry<\/H3><\/p>\n<p><b>I had to solve an issue on path for Poetry, here is what works for me. I always forget the command to edit the bash profile on a Mac.<\/b><\/p>\n<pre>\r\n# how-to to get started you need Poetry's bin directory (\/Users\/brunoflaven\/.local\/bin) in your `PATH` as an environment variable.\r\nAdd `export PATH=\"\/Users\/brunoflaven\/.local\/bin:$PATH\"` to your shell configuration file. Alternatively, you can call Poetry explicitly with `\/Users\/brunoflaven\/.local\/bin\/poetry`.\r\n\r\n# check the path\r\necho $PATH\r\n\r\n# Added path to ~\/.zshrc\r\n# edit \r\nsudo vi ~\/.zshrc\r\n\r\n# Save and Update ~\/.zshrc\r\nsource ~\/.zshrc\r\n\r\n# Check PATH\r\necho $PATH\r\n\r\n# You can test that everything is set up by executing:\r\npoetry --version\r\n\r\n<\/pre>\n<p><H3>5.1 Some Docker commands<\/H3><br \/>\n<b>Always, keep in mind some docker commands that can be useful.<\/b><\/p>\n<pre>\r\n\r\n# Enter the following command for details on the containers currently running:\r\ndocker ps\r\n\r\n# Remove all containers\r\ndocker rm -f $(docker ps -aq)\r\n\r\n# Remove docker images\r\ndocker system prune\r\n\r\n# List the containers\r\ndocker ps\r\ndocker container ls\r\ndocker ps \u2013a\r\n\r\n# Stop container #container-id\r\ndocker stop e53c84c9f9d2\r\n\r\n# Below it requires a docker-compose.yml\r\n\r\n# to stop the stack\r\ndocker-compose stop \r\n\r\n# to start the stack\r\ndocker-compose start \r\n<\/pre>\n<h2>Videos to tackle this post<\/h2>\n<p>You can find my WALKTHROUGHS for these 5 videos walkthrough_ia_deploy_api_ml_architecture.diff (Video #1, Video #2, Video #3, Video #4, Video #5)<\/p>\n<p><b>Video #1 seamless #fastapi #api #development: From Local Setup with #anaconda to #azure #deployment<\/b><\/p>\n<p>A quick and basic API building FastAPI to test it locally with anaconda.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/TMSIobG9nQo\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p><b>Video #2 Simplified #azure #deployment: #containerizing #fastapi #app with #docker &#038; Integration with #azure<\/b><\/p>\n<p>Optimizing Azure Deployment: Containerize Your FastAPI Application with Docker for Effortless Integration into the Azure Ecosystem<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/6Z7UyMgehjk\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p><b>Video #3 mastering #azure #cloud #deployment: Deploy a Simple FastAPI Application in 10 Minutes in Azure!<\/b><\/p>\n<p>A comprehensive step-by-step tutorial takes you on a journey through the entire process of deploying a FastAPI application on the Azure Cloud. From creating the Azure resource group to publishing your app, you&#8217;ll learn how to do it all using Azure Command Line Interface (AZ CLI). Get ready to streamline your FastAPI deployment on Azure in no time!&#8221;<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/7WdUmqp1eDY\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p><b>Video #4 #streamline #azure #deployment: Simplify #docker Operations with a #makefile for Your #application<\/b><\/p>\n<p>In this video, we&#8217;ll guide you through the essential steps of preparing your application for deployment on Azure. We&#8217;ll also show you how to save precious time by using a Makefile to automate and simplify the process of running Docker commands. Say goodbye to tedious typing and hello to efficient Azure deployment!<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/9DDuserTvCk\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p><b>Video #5 #development: #streamlit, #fastapi, simplify the deployment of #frontend &#038; #backend with a #makefile<\/b><\/p>\n<p>Explore the advanced world of application development as we guide you through the creation of a dynamic web application using Streamlit for the frontend and FastAPI for the backend. But that&#8217;s not all \u2013 we&#8217;ll also show you how to streamline your workflow with a Makefile, eliminating the need to type out lengthy Docker commands.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/VDw1wutnqN8\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<p><H2>More infos<\/H2><\/p>\n<ul>\n<li>Deploying a containerized FastAPI app to Azure Container Apps<br \/><a href=\"https:\/\/blog.pamelafox.org\/2023\/03\/deploying-containerized-fastapi-app-to.html\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.pamelafox.org\/2023\/03\/deploying-containerized-fastapi-app-to.html<\/a><\/li>\n<li>The site of pamela fox<br \/><a href=\"https:\/\/www.pamelafox.org\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.pamelafox.org\/<\/a><\/li>\n<li>How to Deploy Projects from GitHub Repo into Azure App Services<br \/><a href=\"https:\/\/andrewhalil.com\/2021\/01\/10\/deploying-projects-from-github-repo-into-azure-app-services\/\" target=\"_blank\" rel=\"noopener\">https:\/\/andrewhalil.com\/2021\/01\/10\/deploying-projects-from-github-repo-into-azure-app-services\/<\/a><\/li>\n<li>Building a Machine Learning Microservice with FastAPI<br \/><a href=\"https:\/\/developer.nvidia.com\/blog\/building-a-machine-learning-microservice-with-fastapi\/\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.nvidia.com\/blog\/building-a-machine-learning-microservice-with-fastapi\/<\/a><\/li>\n<li>How to Build an Instant Machine Learning Web Application with Streamlit and FastAPI<br \/><a href=\"https:\/\/developer.nvidia.com\/blog\/how-to-build-an-instant-machine-learning-web-application-with-streamlit-and-fastapi\/\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.nvidia.com\/blog\/how-to-build-an-instant-machine-learning-web-application-with-streamlit-and-fastapi\/<\/a><\/li>\n<li>Deploying a Simple Streamlit app using Docker<br \/><a href=\"https:\/\/www.section.io\/engineering-education\/how-to-deploy-streamlit-app-with-docker\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.section.io\/engineering-education\/how-to-deploy-streamlit-app-with-docker\/<\/a><\/li>\n<li>How To Deploy Streamlit Apps with Docker<br \/><a href=\"https:\/\/www.youtube.com\/watch?v=doCia_CKcko\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/watch?v=doCia_CKcko<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This last post is again a journal to me of an how-to. This time, the post is dedicated on how to deploy in the Cloud&hellip; <\/p>\n<p class=\"text-center\"><a href=\"https:\/\/flaven.fr\/2023\/10\/step-by-step-introducing-to-azure-cloud-deployment-deploying-a-fastapi-ml-feature-api\/\" class=\"more-link\">Continue reading &rarr; <span class=\"screen-reader-text\">Step by step Introducing to Azure Cloud Deployment: Deploying a FastAPI ML Feature API<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":12655,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bf_ai_meta_description":"Deploy a FastAPI ML feature API on Azure Cloud. Step-by-step guide covers tools and outcomes for closing your ML API creation process.","bf_ai_og_title":"Azure Cloud Deployment: FastAPI ML API","footnotes":"","jetpack_publicize_message":"Step by step Introducing to #Azure #Cloud #Deployment: Deploying a #FastAPI #ML #Feature #API","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3438,3437,3444,3447,3448,3449,3450,3435],"tags":[2532,2183,164,504,1917,3072,3493,2200,3063,3068,3067,3064,3065,2434,3069,3066,3040,787,2529,2540,153,2776,3070,3489,3071,2387,2580,3508,3049],"class_list":["post-12651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-machine-learning","category-business-case-studies","category-programming-databases","category-technology-trends","category-tools-productivity","category-tutorials-how-to","category-ux-product-design","category-web-development","tag-anaconda","tag-api","tag-apps","tag-automation","tag-azure","tag-azure-cli","tag-clip","tag-cloud","tag-container","tag-containers","tag-deployment","tag-design-thinking-process","tag-devops-lifecycle","tag-docker","tag-docker-compose-yaml","tag-experiments","tag-fastapi","tag-github","tag-how-to","tag-ia","tag-images","tag-machine-learning","tag-makefile","tag-microsoft-azure","tag-pamela-fox","tag-poc","tag-spacy","tag-test-automation","tag-whisper"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Vuhl-3i3","jetpack_featured_media_url":"https:\/\/flaven.fr\/wp-content\/uploads\/2023\/10\/ia_deploy_api_ml_architecture_b.jpg","_links":{"self":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/12651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/comments?post=12651"}],"version-history":[{"count":21,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/12651\/revisions"}],"predecessor-version":[{"id":12673,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/12651\/revisions\/12673"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media\/12655"}],"wp:attachment":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media?parent=12651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/categories?post=12651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/tags?post=12651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}