Developing a Simple Python Application and Automating the CI/CD and Containerization Process [Part 3B]
Constructing the CI/CD Framework
In the previous articles, I talked about how to set up the code base to create a simple banking application in Python, provision the infrastructure via Terraform, and build the continuous integration and continuous deployment (CI/CD) process to create a Docker image from the code that can be deployed as a container. If you want a refresher on these concepts, check out the resources section at the end of this article for links to my previous posts! Now let’s look at the second half of the CI/CD process, which is automating the infrastructure build out using the Terraform scripts we developed in part 2 of the series.
We’ll start off with uploading our IaC scripts into a remote repository under the same project we were working on in part 3A. Again, here I won’t be discussing in detail the process of git commits, pushes, and merges, because I sincerely believe that if you’ve gotten this far in the tutorial, you are probably already quite familiar with those concepts, and the last thing I’d want to do is bore my readers! But for those of us that would like to brush up on how Git works to sync our local project code to a remote repository, the documentation provided on their website is an excellent source to refer to (which I’ve linked in the resources section at the end of the article). After our code has been merged into the remote project repository, we should see an interface similar to Figure 1.
Now that we have all our scripts synced with our remote project, we can go ahead and set up a build pipeline to perform the Terraform plan and apply processes for us and create the resources on the cloud. To do this, we’ll again use the classic editor (which I talked about in the previous article) to help set up custom build stages without writing any YAML syntax to code the actual pipeline. Figures 2–7 illustrate the process of setting up the Terraform infrastructure build out stages.
Let’s skim through this process quickly. In the classic editor, we have to sync the new remote repository that we created to hold our Terraform scripts, and select an empty job template as we did before. Here, we’ll be able to configure the agent pool and specification (I chose Ubuntu latest, but any other agent should also be totally fine). Then I used the Terraform CLI task plugin to set up Terraform init, plan, and apply tasks. For the init task, we have to select the provider that we will be contacting, which in this case is Azure Resource Manager (Azure RM). This way, Azure DevOps will know to connect to the Microsoft Azure cloud platform when creating or modifying the resources we specified in our Terraform scripts. The plan and apply tasks don’t require any initialization and can just be configured to run with Azure CLI Login. In all three of these tasks, I’ve specified the configuration directory as the default working directory since the source for this pipeline was directed to the repository that contains our Terraform scripts. We want Azure DevOps to read from these scripts and run the Terraform commands that we supply to the terminal through the plugin. Once we have this set up in place, we can trigger the build pipeline and Terraform will start the infrastructure plan creation and apply process as shown in Figures 8–12.
And that concludes the automated infrastructure build out process. When we navigate to Azure Portal, we should be able to see the resources that we just built out under the resource group/subscription that we specified in our Terraform scripts. In parts 3A and 3B of this series of articles, we were able to see how we can automate the continuous integration and continuous deployment process for application code as well as infrastructure. Ideally, the end goal is for these processes to happen on their own as soon as a new file or change is committed to their respective repositories, indicating a modification in application code or infrastructure. The next and final article in this series will talk about the actual deployment process, which involves running the containerized image we built in part 3A as a deployment onto a Microsoft Azure managed Kubernetes cluster instance. We’ll delve into the concept of Kubernetes, what it can be useful for, and how to set up a deployment. Until then, hope you can peruse my previous articles and also do a bit of coding on your own! Till the next one! 😁
Find my code here 👉 https://abujji.visualstudio.com/banking-app-python/_git/terraform_scripts
Resources:
- https://medium.com/@madhuvanthi-sridhar/developing-a-simple-python-application-and-automating-the-ci-cd-and-containerization-process-part-5d11509cbe9d
- https://medium.com/@madhuvanthi-sridhar/developing-a-simple-python-application-and-automating-the-ci-cd-and-containerization-process-part-19b39ccda807
- https://medium.com/@madhuvanthi-sridhar/developing-a-simple-python-application-and-automating-the-ci-cd-and-containerization-process-part-6d37caacf2c
- https://git-scm.com/docs/git-push
- https://stackoverflow.com/ (If you’re in Tech, then you know how big of a lifesaver this forum is 😂)
- As always, my Brain 😎