Interesting practices in cloud dev ops mainly for building, testing , deploying and security aspects .
Lot of exams dumps.
Articles help to build dockers and complete CI/CD automation for your applications. 1) Azure - Micro services 2)
Azure Dev ops (CI/CD) 3) Identity 4) secure dev ops
.
give call on (+61)0426622462 or email to :dasaradhreddyk@gmail.com
This articles works perfectly. simple steps. check in api file to Git. add requirements.txt file . Trigger build using git actions. It works perfectly.
I have created deployment from Azure portal i.e after creating web app I have attached git repo for deployment to this web app. If requirements.txt is good it deploys flash api to azure web app without any issues.
Deploying applications to the cloud requires choosing suitable services and understanding the deployment process. In this tutorial, we’ll focus on deploying a Python-based Flask application to Azure using Azure App Service.
Step 1: Setting Up Your Flask Application
Create Your Flask Application: Start by building your Flask application. Ensure that the main file is named application.py for compatibility during deployment on Azure. This is crucial for maintaining data integrity in a cloud infrastructure.
Go to your Github and change the name of adding another file with application.py Note: You might get errors when you have more than one file with py extension.
If you haven’t already, sign up for an Azure account. You can opt for a student subscription or use the free subscription for the first year.
2. Accessing App Services:
Navigate to the Azure portal and locate “App Services.” and click on “Create” to start the process of creating a new service.
Press enter or click to view image in full size
Step 3: Confugure your Web App
Choose “Web App” among the options.
2. Select your subscription and create a new resource group (if needed).
3. Fill in the instance name, select the “code” option, choose the Python version, and leave other settings as default.
Get Johnas Chami’s stories in your inbox
Join Medium for free to get updates from this writer.
4. Proceed to the “databases” section and maintain default settings and then skip ahead to the “deployments” section.
Press enter or click to view image in full size
Step 4: Confuguring GitHub Actions
Enable GitHub Actions settings and link your GitHub account.
2. Choose the repository and branch for deployment and skip other settings, review your configurations, and proceed with the deployment creation.
3. After deployment, a GitHub workflow file will be generated in your repository.
Step 5: Checking Deployment Status
Access the created resource and note the default domain address.
2. Give some time for the deployment to complete as the model is still in the deployment phase.
Press enter or click to view image in full size
3. Monitor your deployment with GitHub Actions. Go to your GitHub repository and navigate to GitHub Actions and observe the step-by-step progress of your application’s deployment.
Press enter or click to view image in full size
Step 6: Verifying Successful Deployment
Check GitHub Actions to ensure both build and deployment phases are successful.
2. Note the time taken for the deployment process.
Final Step:
Accessing the deployed application: Use the default domain provided to access your deployed application.
Press enter or click to view image in full size
Verify that your Flask application is running as expected.
Press enter or click to view image in full size
Congratulations! You’ve successfully deployed your Flask application to Azure using Azure App Service. This process leverages GitHub Actions for smooth integration and provides a reliable cloud environment for your Python-based ML prediction model.
As a software Engineer, I would like to deploy my Dockerized Python Application to Azure Container Instance (ACI) using Azure DevOps so that I can automate my workflow and eliminate any manual intervention during the deployment.
In this blog post, I will walk you through how to build and deploy a Dockerized Python Application to Azure Container Instances (ACI) using Azure DevOps. The workflow will build and deploy the docker image to Azure Container Registry (ACR),and finally, the application will be deployed to Azure Container Instances.
What is Azure? Azure is a cloud computing platform and services, provided by Microsoft. It offers many services, including Databases, storage, Virtual Machines, and more. Azure allows developers and organizations; to build, deploy, and manage applications and services through Microsoft-managed data centers.
Azure Container Instance (ACI) is a managed Azure service that allows you to run containers in the cloud without managing the underlying infrastructure. ACI allows developers to quickly deploy and manage containerized applications without the overhead of managing Kubernetes clusters or virtual machines (infrastructure). ACI is a serverless container service, which simply means that you only pay for the resources (CPU and memory) your container uses and you do not need to worry about how to provision or manage servers.
Azure Container Registry (ACR) is a managed Azure registry service that allows you to manage and store your Docker container images in Azure. It integrates seamlessly with Azure services and it is designed for building and storing Docker container images that can later be used in Azure Container Instance (ACI), Azure Kubernetes Service (AKS), or other containerized services.
Azure DevOps is a set of development tools and services from Microsoft that allow you to build, deploy, test, and deploy your software more efficiently and effectively. It also provides a comprehensive DevOps lifecycle solution, which includes source control, continuous integration and Delivery (CICD), collaboration tools, and project management.
Prerequisites
Azure Subscription: You must have an active Azure account and subscription. You can create a free account here
Azure CLI: Install Azure CLI (Command Line Interface) if you do not have it already. Install Azure CLI here
Docker: Docker is installed on your local machine. If you do not have Docker. Install Docker here
Azure DevOps Account: Setup an Azure DevOps Organization project here
Below is a step-by-step guide on deploying a Dockerized Python Application from Azure pipelines and later deploying it to an Azure Container instance.
Step 1: Create the Python App with Classes, Getters, and Setters
The Python app will be written in classes and you will be using Flask which is a Python framework to develop the Python application. The app will demonstrate how to manage a simple greeting message and expose getter and setter methods.
It manages the _message attribute, which stores the greeting message Hello World
It has the getter method get_message() to fetch the current greeting.
It has the setter method set_message(message) to modify the greeting message.
2b: Class App:
It initializes the Flask application and the Greeting class instance.
The index / route returns the current greeting message.
The /update/<message> route allows the greeting message to be updated using either GET or POST method
Step 3: Create the requirements.txt file
Navigate to the root project and create a new file with the filename requirements.txt which will contain the necessary Python dependencies. Copy and paste the code below in the requirements.txt file.
Flask==3.1.0 gunicorn==23.0.0 setuptools>=70.0.0
Step 4: Create the Dockerfile
Navigate to the root project and create a new file with the filename Dockerfile with the code below
Before deploying using Azure DevOps, let's test this setup locally
a. Build the Docker image using the command below
docker build -t python-app .
b. Run the Docker container
docker run -p 5000:5000 python-app
c. In your browser, navigate to http://localhost:5000/ to see the greeting message.
d. To update the greeting message from your browser, visit http://localhost:5000/update/<new-message>. The actual greeting message will be http://localhost:5000/update/Hello%20from%20Dockerized%20App
Step 6: Create the Azure DevOps Pipeline
Navigate to the root project and create a new file with the filename azure-pipelines.yml
connectedServiceNameARM This is a profile for which to establish integration with Azure, which will create permissions and allow you to create services (ACR and ACI on Azure). It will also allow you to link your Azure subscription.
sampleapp This is the profile for establishing connectivity with ACR (Azure Container Registry)
ExitoLab, this is the profile for establishing connectivity with Git.
Here is a summary of the YAML file / deployment file
The pipeline runs automatically when changes are pushed to the main branch
Different variable definitions define the key configurations, such as azure subscription, resource group, ACR name, image name / tag
There is a step that verifies if the specified resource group exists, if not it creates it.
A step checks if the Azure Container Registry (ACR) exist with admin access enabled, if not it creates it.
Implemented a caching mechanism to make the pipeline (speed up Docker builds) runs faster
A step installs Trivy, scan the image for High and Critical vulnerabilities but it does not fail that pipeline if a vulnerability is found but it can fail the pipeline if a vulnerability is found. It then pushes the the docker image with tag latest, $(imageTag) to ACR.
A steps deploys the container image to ACI (Azure Container Instances) with specified resources (CPU, Memory, ports and DNS label)
I hope you can now deploy a Dockerized Python application by leveraging Azure DevOps and Azure Container Instances (ACI) by automating the entire process of building, scanning and deploying with minimal manual effort. This pipeline demonstrates how infrastructure components like resource group, ACR are provisioned if missing, scan docker image using Trivy for vulnerabilities and deploy the Docker image to ACI (Azure Container Instances).
This ties in well with the previous infrastructure studies I’ve been completing, and I’d like to be able to combine both skills to build out a cloud-based deployment pipeline for my Python projects.
Get Michael Rodgers’s stories in your inbox
Join Medium for free to get updates from this writer.
To begin with, I’ve created a local development Docker host, with Jenkins installed for CI/CD, and Prometheus and Grafana installed for monitoring. My next step is following the Docker documentation for Pythonwhich details deploying a Flask application to a container. I’ve listed the steps I’ve taken below.
Steps Taken
Prepare Repository and Minimal Flask Server
I’ll be using the GitLab repo that I’ve previously stored files relating to this Docker host, creating a new branch for this project.
mkdir hello-py && cd hello-py to create a folder within the file structure to hold project files
mkdir server && cd server && touch main.py to create the code file structure and Flask server entry point, entering the following code:
touch Dockerfile within the hello-py directory create a file to build the custom Docker image
# syntax=docker/dockerfile:1 specify the Dockerfile syntax
FROM python:3.9.13-slim-buster specify the base Python image to use
WORKDIR /hello-py create a working directory for the subsequent commands
COPY requirements.txt requirements.txt copy the pip requirements file
RUN pip3 install -r requirements.txt use the copied requirements file to install pip dependencies
COPY . . will copy the Python project files into the /hello-py image directory
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] supply the command to run that will launch the server, and make it accessible outside of the container
The final Dockerfile code should look like this:
# syntax=docker/dockerfile:1
# base python image for custom image FROM python:3.9.13-slim-buster
# create working directory and install pip dependencies WORKDIR /hello-py COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt
# copy python project files from local to /hello-py image working directory COPY . .
# run the flask server CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
Build the Image
docker build --tag hello-py . in the local file’s terminal to build the image using the Dockerfile
Custom Python server image built with Dockerfile
Testing the Image in a Local Container
docker run -d -p 5001:5000 hello-py on my local machine to test that the image was built successfully
I’m using an external port of 5001 on the container on my local machine as I have been using port 5000 for running the Flask server through VSCode’s terminal, and want to make sure there are no conflicts. When we move the image to the remote Docker host I’ll use an external port of 5000
Container deployed from custom image on local computer
Push to Docker Hub and Deploy to Remote Container
docker login --username=mjrod run this if required to connect CLI to Docker Hub account
docker tag hello-py mjrod/hello-py tag the image with your Docker Hub username: <username>/<image-name>
docker push mjrod/hello-py to push a new repository to Docker Hub to store the image
Image pushed from CLI to Docker Hub successfully
After this, log into the remote Docker host using SSH and run the following
docker pull mjrod/hello-py:latest to pull the previously uploaded image from Docker Hub
docker run -d -p 5000:5000 --name=hello-py mjrod/hello-py to launch the container
Containers deployed on remote Docker host
Navigate to http://<remote-docker-ip>:5000 to see the Python application running in the remote container
Next Steps
Begin coding my Python application — now that I have the ability to package up my Python code and deploy it to a container, I’d like to begin building high-quality web applications to cement both my programming and infrastructure learnings.
Build a Jenkins pipeline to automate the rebuilding phases for each Docker images — each time I make code changes, the steps outlined in this document will need to be repeated to make the images reflect the code base. I’d like to link my Gitlab repo and my Docker host using Jenkins to automate some of this task away.