This project automates the setup and deployment process using the following tools:
- Terraform to create an EC2 instance on AWS.
- Ansible to install Docker and Jenkins on the EC2 instance.
- Jenkins for Continuous Integration/Continuous Deployment (CI/CD) to automate the Dockerization and deployment of a Flask Python application.
- Create VPC and define the networking structure (subnets, route tables, security groups, etc..).
- Outputs:
- Capture the public IP of Ec2.
- The EC2 instance IP will be in the inventory file for Ansible.
Ansible will handle the installation of Docker and Jenkins on the EC2 instance.
- Create Ansible Playbook:
- Create playbook to install jenkins and docker on Ec2 Instance.
- Run Ansible Playbook:
- Run the playbook
ansible-playbook -i inventory.yml playbook.yml
- Create Dockerfile:
- Inside your Flask app directory, create Dockerfile:
- Build and Run Docker Container:
- Build the Docker image
docker build -t flask_app .
- Run the container:
docker run -p 5000:5000 flask_app
- push it to DockerHub
- push your image to Docker Hub
- create a new repository in DockerHub.
- push the image by
docker push
.
- push your image to Docker Hub
- Create Jenkins Pipeline:
- In Jenkins, configure a new pipeline job for the Flask app.
- Add the following Jenkinsfile in your project repository.
- Set Up Jenkins Webhook:
- Go to your GitHub repository settings.
- set up a webhook to trigger the Jenkins pipeline when code is pushed or updated.
- Run the Pipeline:
- Jenkins will automatically
- detect changes in the repository
- build the Docker image
- test and deploy the Flask application.
Dockerization and deployment of a Flask app. Jenkins ensures that any updates to the repository trigger the CI/CD pipeline, keeping the application deployment automated and up-to-date. - Jenkins will automatically