Build A Quadratic Equation Solver Application Using Docker, Terraform, Bashscript And Cloudformation

Build A Quadratic Equation Solver Application Using Docker, Terraform, Bashscript And Cloudformation

**
Add Subtitle**

Building a quadratic equation solver application using Docker, Terraform, Bash scripting and Cloudformation.

🚀 Overview:

This project aims to develop and deploy a scalable web application that solves quadratic equations, incorporating modern DevOps practices and cloud infrastructure automation. The application will provide users with a simple interface to input coefficients (a, b, c) of a quadratic equation (ax² + bx + c = 0) and receive calculated roots in real-time.

The technical implementation leverages containerization through Docker for consistent deployment environments, Infrastructure as Code (IaC) using both Terraform and AWS CloudFormation for cloud resource management, and Bash scripting for automation and operational tasks. This multi-tool approach demonstrates the integration of various DevOps technologies while solving a practical mathematical problem.

🔧 Problem Statement

Educational institutions and students often need quick access to quadratic equation solutions, but existing calculators are typically standalone applications or simple websites that lack scalability and modern deployment practices. Additionally, organizations face several challenges when deploying and maintaining such applications:

  1. Consistency Issues: Different development and production environments lead to deployment failures and inconsistent behavior.

  2. Manual Infrastructure Setup: Traditional deployment methods require manual configuration, making it time-consuming and error-prone to set up new environments.

  3. Limited Scalability: Most existing solutions cannot easily scale to handle varying loads of user requests.

  4. Complex Maintenance: Without proper automation and infrastructure management, maintaining and updating the application becomes increasingly difficult.

This project addresses these challenges by:

  • Containerizing the application to ensure consistency across environments

  • Automating infrastructure provisioning using both Terraform and CloudFormation

  • Implementing efficient deployment pipelines using Bash scripting

  • Creating a repeatable and maintainable cloud infrastructure setup

The solution will demonstrate how modern DevOps tools and practices can be applied to create a reliable, scalable, and maintainable application, while serving as a practical example for educational purposes in both mathematics and cloud computing.

💽 Techonology Stack

The project consists of using the following technologies:

  • CloudFormation:

  • EC2:

  • Docker:

  • Terraform:

  • Bash Scripting:

📌 Architecture Diagram

🌟 Project Requirements

Before you get started, make sure you have the following prerequisites in place:

  • AWS IAM credentials configured in your text editor. In this case we will use VSCODE.

  • Git installed on your local machine and Github account set up Github

  • Git for cloning the repository.

  • Understand CloudFormation stack.

  • Familiar with Docker and Bash script commands.

  • Know the Terraform work flow and commands.

📋 Table of Contents

I - CloudFormation Templates

Step 1: Provide the template

Step 2: Launch the Host server

Step 3: Connect to the launched server

II - Terraform Configuration files

Step 1: Provider Configuration

Step 2: Variables Configuration

Step 3: Main Configuration

III - Python Application

Step 1: Provide file app.py

Step 2: Web page file

IV - Dockerfile

Step 1: Writing Dockerfile

V - Bash Scripting

Step 1: Writing the Bash script file

VI - Instructions of Deployment

Step 1: Copy all files in the EC2 server

Step 2: Initialize Folder

Step 3: Format Files

Step 4: Validate Files

Step 5: Plan

Step 6: Apply

Step 7: Bash Scripting execution

Step 8: Review of Resources

Step 9: Destroy

✨CloudFormation

You need to write the template generating EC2 server. We will add User-data that will install Docker and Terraform in the server. This will automate the launch f instance and avoid to login and perform installation manually. The User-data is the piece of the code that will contains all instructions og the Docker and Terraform installation.

Step 1: Provide the template

Here we declare the contains of the server in with we will be working. It is an Amazon linux 2 server with “t2.micro” as instance type and will be launch in an existant VPC. Below is the link to the template.

Step 2: Launch the EC2 server process

Here is the process of launching the server using Cloudformation. You must login in your account via console and navigate to CloudFormation option. Click on “Create Stack”

Then, select the type and the location of the file.this will help CloudFormation to localise the file the upload it to the stack.

You will provide informations such as “stack Name”, “Instance_type”, “key_name”, “SSH Unique IP address which is your personal public IP”. You will select an existing public subnet in the list also the VPC.

Check the acknowledgement option on the bottom of the page then hit next and after on the next page hit “Submit”

The process of creating resources will launch and resources will be on slowly and one after another base of what were declare in the template.

Keep refreshing with the circle arrow in order to see the evolution of the creation.

When completed you will get the get the massege saying “Create Completed”

Step 3: Connect to the launched EC2 server

On the console open another tab where you will navigate till get to EC2. Select the running instance and click on “Connect”

The following windows will appear. On your ligne of command be on the folder that contains your private key pair. Copy each command and type to the command ligne

The two commands will prompt to a validation and then connect securely to your EC2 server.

✨Terraform Configuration files

You need to write different files generating the build of Docker image, run the container base of the image. To perform the task you will need sets of terraform files such as providers, variables and main. Let each of those files.

Step 1: Provider Configuration

Here we declare our cloud provider and we specify the region where we will be launching resources

Step 2: Variables Configuration

This is where we declare all variables and their value. It includes

  • Variables: List of element that can vary or change. They can be reuse values throughout our code without repeating ourselves and help make the code dynamic. Here we have only the Docker username and password.

  • values: values attributed to each variables.

We have

Step 3: Main Configuration

This is where you build the Docker image and run the container with that image created.

✨Python Application

You need to write the application itself using the programming language call Python. The file will contains all instructions for doing the calculation base of coefficients enter by the user. We will also gonna add the layout of the web page by adding the file name index.html.

Step 1: Provide the file app.py

Here we declare the contains of the file in with we will be working.

Step 2: Web page file

Here is the contains of the web page. The file will provide the layout of the web page. This file must be inside a folder name “templates”.

✨Dockerfile

You need to write the step of instructions that will help the application to be display. it will follow instructions to produce image that will help in the creation of the container on top of the where the application will run.

Step 1: Writing Dockerfile

Here we declare the contains of the file in with we will be working.

✨Bash Scripting

You need to write the step of instructions that will help push the Docker image created to the Dockerhub repository.

Step 1: Writing the Bash Scripting file

Here we declare the contains of the file in with we will be working.

  • image_push.sh

    You will get back on this later on in the execution or deployment of the application.

💼 Instructions of Deployment

Follow these steps to deploy the architecture:

Step 1: Copy all files in the server:

You will have to create a folder that will contains all these files. Call the folder “Terraform-Docker”

mkdir Terraform-Docker

cd Terraform-Docker

You will use the “vi” command to create file and then insert the contains directly

Step 2: Initialize Folder

Ounce you done copying files you must Initialize the folder containing configuration files that were clone to Terraform and apply the configuration by typing the following command

terraform init

You must see this image

Step 3: Format Files

Apply any changes on files and Review the changes and confirm the good format with command:

terraform fmt

Step 4: Validate Files

Ensure that every files are syntactically valid and ready to go with the command:

terraform validate

If everything is good you will have something like this

Step 5: Plan

Create an execution plan to provide the achievement of the desired state. It Check and confirm the numbers of resources that will be create. Use command:

terraform plan

The list of all resources in stage of creation will appear and you can see all properties(arguments and attributs) of each resources. here we have only two resources the image and the container.

Step 6: Apply

Bring all desired state resources on life. It Launch and create all resources listed in the configuration files. The command to perform the task is:

terraform apply -auto-approve

Now, the creation will start and you will be able to see which resources is on the way to be create and the time it taking to create.

At the end you will receive a prompt message showing all resources status: created, changed and the numbers of them.

Here is the output :

We now need to go back on the EC2 instance in the console to grab the public ip of the instance.

Copy and paste that Ip on the browser the add colons and port 5000 and hit enter you will get the web page. The application is running in a container which is open on port “5000”. So the IP address to paste in the browser is “public_ip:5000”

After you add some coefficients you will get the result :

Step 7: Bash Scripting execution

Once you are set up and the image is now created and then the container is running you will have to push image to Dockerhub. To complete that you can use the Bash script you wrote before and you will follow those two steps:

- Make the script to be executable by changing modification command. This will give power or privilege to file so it can be executable without error.

chmod +x image_push.sh

- The process of pushing will follow ounce you type command and you will get results succeeded.

./image_push.sh

You will get the image :

Step 8: Review of resources
  • After the image pushed to Dockerhub you can now go to the platform to see the repository or library. There you can see the image built.

    You can pull it to test by using the command:

    docker pull joebaho2/quadratic_solver_image:latest

Step 9: Destroy

Destroy the terraform managed infrastructure meaning all resources created will be shut down. This action can be done with the command "terraform destroy"

terraform destroy -auto-approve

At the end you will receive a prompt message showing all resources has been destroyed

Also you must go back to CloudFormation to delete the stack

🤝 Contributing

Your perspective is valuable! Whether you see potential for improvement or appreciate what's already here, your contributions are welcomed and appreciated. Thank you for considering joining us in making this project even better. Feel free to follow me for updates on this project and others, and to explore opportunities for collaboration. Together, we can create something amazing!

📄 License

This project is licensed under the JoebahoCloud License