- Introduction
- Project Structure
- Current Features
- Workflow Overview
- Reusable GitHub Actions
- Requirements
- How to Use
- Future Plans
This project is an effort to automate a complete CI/CD pipeline from the infrastructure to the configuration using Terraform, Ansible, and GitHub Actions. Currently, there is one GitHub Action that deploys an AWS EC2 instance, configures it to run Docker, and launches an NGINX server in a container. Additionally, the project includes a microservices-based application with components for authentication and poll management. These microservices are built as Docker containers and automatically pushed to my Docker Hub repository using dedicated GitHub Actions workflows. The project showcases the integration of modern CI/CD practices with microservices architecture and containerization.
.github/
└── actions/
├── build-push-image/ # Action to build and push Docker images
├── initialize-terraform/ # Action to set up Terraform
├── set-inventory-and-key/ # Action to configure Ansible inventory and SSH keys
└── setup-ansible/ # Action to set up Ansible
└── workflows/
├── deploy-compose.yml # Deploys and manages Docker Compose setup
├── deploy-infrastructure.yml # Provisions infrastructure and sets up Ansible
├── destroy.yml # Destroys the deployed infrastructure
├── publish-auth.yml # Publishes the auth microservice container
├── publish-poll.yml # Publishes the poll microservice container
└── restart-compose.yml # Restarts Docker Compose setup
ansible/
├── install_docker.yml # Install and configure Docker
├── run_apache.yml # Deploy and run nginx in a container
├── restart_compose.yml # Restarts the Docker Compose setup
└── ansible.cfg # Configuration file
application/
├── auth # Authentication microservice source code
└── poll # Polling microservice source code
terraform/
├── infrastructure/
│ ├── main.tf # Provision machine and security groups + rules
│ └── outputs.tf # Outputs the IP of the machine
├── backend/
└── main.tf # Deploys backend used by the infrastructure (RUN SEPARATELY)For details about changes and updates, refer to the changelog.
-
Authentication Microservice
- Readme: application/auth/readme.md
- Handles user signup, login, and password resets.
- Utilizes JWT tokens with RS256 algorithm for secure authentication.
- Packaged and deployed as a Docker container via CI/CD pipeline.
-
Poll Microservice
- Readme: application/poll/readme.md
- Manages polls, including creating and voting.
- Integrated with a Postgres database using Docker Compose.
- Fully automated build and deployment pipeline using GitHub Actions.
- File: deploy-infrastructure.yml
- Purpose: Provisions an AWS EC2 instance and configures it with required software.
- Key Steps:
- Initialize and apply Terraform configurations.
- Set up the SSH private key and Ansible inventory.
- Install Docker using Ansible.
- Uses Actions:
- File: destroy.yml
- Purpose: Cleans up the provisioned AWS infrastructure.
- Key Steps:
- Initializes Terraform.
- Destroys the infrastructure.
- Uses Actions:
- File: deploy-compose.yml
- Purpose: Deploys and manages the Docker Compose setup for microservices.
- Key Steps:
- Configures Ansible using the provisioned infrastructure.
- Executes the Docker Compose playbook via Ansible.
- Uses Actions:
- File: publish-auth.yml
- Purpose: Builds and pushes the authentication microservice Docker image.
- Key Steps:
- Builds the Docker image from the
authdirectory. - Publishes the image to Docker Hub.
- Triggers the
restart-composeworkflow.
- Builds the Docker image from the
- Uses Actions:
- File: publish-poll.yml
- Purpose: Builds and pushes the polling microservice Docker image.
- Key Steps:
- Builds the Docker image from the
polldirectory. - Publishes the image to Docker Hub.
- Triggers the
restart-composeworkflow.
- Builds the Docker image from the
- Uses Actions:
- File: restart-compose.yml
- Purpose: Re-deploys the Docker Compose setup to reflect updated microservices.
- Key Steps:
- Configures Ansible.
- Runs the
restart_compose.ymlplaybook to restart services.
- Uses Actions:
- File: build-push-image/action.yml
- Builds a Docker image and pushes it to Docker Hub.
- Inputs include DockerHub credentials, image name, and tag.
- File: initialize-terraform/action.yml
- Sets up and initializes Terraform for infrastructure management.
- Inputs include Terraform directory and version.
- File: set-inventory-and-key/action.yml
- Configures Ansible inventory and SSH keys for the provisioned machine.
- Inputs include SSH private key.
- File: setup-ansible/action.yml
- Prepares the environment for Ansible by integrating Terraform and SSH configurations.
- Inputs include SSH private key.
-
AWS Account
- Full Access to EC2, S3 buckets and DynamoDB.
- The security credentials of the account needed by terraform.
- EC2 security key pair private key.
-
GitHub Secrets
- AWS credentials:
AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEY - EC2 security private key:
RSA_SECRET_KEY - DB connection values:
DB_HOST,DB_NAME,DB_PASSWORD,DB_PORT&DB_USERNAME - DockerHub credentials:
DOCKERHUB_TOKEN&DOCKERHUB_USERNAME - JWT key pair:
JWT_PRIVATE_KEY&JWT_PUBLIC_KEY
- AWS credentials:
-
GitHub Variables
WHITELIST_IP, this can be either0.0.0.0/0(ALL IPs) or your home/personal IP.
-
Fork or Clone the repository
- Fork it directly from GitHub.
- Clone the repository and push it to your own.
-
Set up the Terraform Backend
- Install terraform.
- Perform AWS CLI login or set the
AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEYvalues in your local environment. - Navigate to the
terraform/backenddirectory. - Initialize Terraform and apply the backend configuration:
terraform init terraform apply --auto-approve
-
Set up GitHub Secrets and Variables
-
AWS Secrets:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYRSA_SECRET_KEY
-
Database Secrets:
DB_HOSTDB_NAMEDB_PASSWORDDB_PORTDB_USERNAME
-
Docker Hub Secrets:
DOCKERHUB_TOKENDOCKERHUB_USERNAME
-
JWT Secrets:
JWT_PRIVATE_KEYJWT_PUBLIC_KEY
-
Add GitHub variables:
WHITELIST_IP.
-
-
Trigger the Action
- Navigate to the Actions tab in your repository on GitHub.
- Manually dispatch the
Deploy the infrastructureworkflow. - Manually dispatch the
Deploy docker composeworkflow.
-
Access the deployed server
- Use the public IP outputted by terraform to verify the nginx server.
- Build an Email Microservice to handle notifications and communications.
- Develop a Frontend Application for user interaction, including signup/login, poll creation, voting, and results visualization.
- Integrate Automated Testing for all microservices, linked to the CI/CD pipeline.
This README will continue to evolve as the project grows and new features are added.