This project demonstrates a simple Python Flask application containerized with Docker and deployed using Terraform.
- Containerization: The application is packaged using Docker for consistent execution across different environments.
- Infrastructure as Code (IaC): Terraform is used to provision and manage the infrastructure required for deployment.
- Simple Web Application: A basic "Hello World" Flask application serves as a starting point.
- Remote State Management: Terraform state is stored remotely for collaboration and consistency.
- Continuous Integration: A Jenkinsfile is provided for potential integration with a CI/CD pipeline.
Before you begin, ensure you have the following installed:
- Docker: https://www.docker.com/get-started
- Python 3.9+: https://www.python.org/downloads/
- Terraform: https://www.terraform.io/downloads
- AWS CLI: https://aws.amazon.com/cli/ (configured with appropriate credentials)
-
Clone the repository:
git clone <repository_url> cd devops-project
-
Build the Docker image:
docker build -t devops-app . -
Run the Docker container (optional - for local testing):
docker run -p 5000:5000 devops-app
Visit
http://localhost:5000in your browser to see the application. -
Initialize Terraform:
cd Terraform ./install-dependencies.sh terraform init -backend-config="Remote-backend/s3.tf" -reconfigure
Note: You need to setup s3 bucket and dynamo db as specified in
Terraform/Remote-backendfolder. Please check the documentation here.- Ensure you have an AWS S3 bucket and DynamoDB table configured for Terraform remote state management as defined in
Terraform/Remote-backend/s3.tfandTerraform/Remote-backend/dynamodb.tf. Replace the placeholder values in these files with your actual bucket name and DynamoDB table name. - AWS Credentials must be properly configured using
aws configure.
- Ensure you have an AWS S3 bucket and DynamoDB table configured for Terraform remote state management as defined in
-
Apply Terraform Configuration:
terraform apply
Confirm the changes by typing
yeswhen prompted. Terraform will provision the infrastructure on AWS.
The application exposes a single endpoint at the root path (/).
- Endpoint:
/ - Method: GET
- Response:
"Hello bhai from Docker on AWS!"
After deploying the infrastructure with Terraform, you can access the application at the public IP address of the EC2 instance created. The public IP address will be displayed in the Terraform output.
app.py: The Flask application code can be modified to implement custom logic.Dockerfile: Customize the Docker image build process by modifying theDockerfile.terraform.tfvars: (Not included, but recommended) Define variables such as instance type, region, and security group rules in aterraform.tfvarsfile to avoid hardcoding them in the Terraform files. This is best practice.- Terraform Variables: Adjust variables defined in
main.tfas needed to customize the infrastructure (e.g., instance type, AMI). Remember to update the variables interraform.tfvarsfile or through-varoption.
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive messages.
- Submit a pull request.
- This project utilizes the following open-source software:
- Python
- Flask
- Docker
- Terraform