From b0b08b59684a1025fe74dda830ec8ae4822a67f9 Mon Sep 17 00:00:00 2001 From: Kevin Jimenez <56909942+KevJimenez@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:41:33 +0800 Subject: [PATCH 1/2] Update README.md --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dddfd2c..0385098 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,77 @@ An automated setup of infrastracture with configuration for a web server (uses A ![iac](/images/iac.png) -- Whole CI/CD Pipeline of the Project [(Link to the Hugo Static Repository)](https://github.com/KevJimenez/Hugo-Static) +- Whole CI/CD Pipeline of the Project [(Link to the Personal-Portfolio Repository)](https://github.com/KevJimenez/Hugo-Static) ![whole](/images/whole.png) +## The Workflow + +### Preparation + +1. Terraform Configuration Files + - Made 3 tf files: + - main.tf - contains all code related to AWS, Terraform Cloud, required providers (EC2 instance provisioning, ssh http https access, ssh key pair for host pc) + - dnset.tf - cloudflare configuration (A-NAME Record, Cloudflare Account) + - variables.tf - variables for referencing (variable values checked in to Terraform Cloud for security purposes) +2. Ansible Configuration Files: + - Made 3 yaml files: + - playbook.yml - contains code for the whole CaC in the infrastructure provisioned by Terraform (Update Instance, Installing Docker, Login to Docker, Running Docker Container Watchtower and Docker Image of Personal-Portfolio) + - destroyinf.yml - code for the uninstallation of files present in the instance (Clean apt directories and cache, Uninstall Docker) + - aws_ec2.yml - contains code for a dynamic inventory in my AWS account +3. GitHub Action Workflows: + - Made 4 workflows: + - ansiblelint.yml - workflow for ansible-lint (triggers per push into the repository) + - tflint.yml - workflow for terraform-lint (triggers per push into the repository) + - deploy.yml - workflow for deploying ec2 instance (triggers on dispatch) + - destroy.yml - workflow for destroying ec2 instance (triggers on dispatch) + + +### Workflow Process +> Note: Workflow runners for deploy and destroy is not running on a GitHub Container. Runs on my Local Ubuntu Instance with permissions from AWS. GitHub Container runners also can't detect yaml as an inventory for ansible, hence used a local runner instead. + +**Deploy Infrastructure** (deploy.yml) + 1. Terraform Init (Checks for Terraform Files) + ```bash + terraform init + ``` + 2. Terraform Apply (Building of the Instance) + ```bash + terraform apply -auto-approve -input=false + ``` + 3. Delay for 7s (Added delay because EC2 dynamic inventory takes time to detect newly built instance for the ansible playbook) + ```bash + sleep 7s + ``` + 4. Run Ansible Playbook (referenced github secrets for docker access key) + ```bash + ansible-playbook -i aws_ec2.yml playbook.yml -e "docker_key=${{ secrets.DOCKER_KEY }}" + ``` +*Output:* +- AWS Instance running docker with [Watchtower](https://github.com/containrrr/watchtower) and Containerized [Personal-Portfolio](https://github.com/KevJimenez/Personal-Portfolio). +- Personal portfolio website that can be accessed from https://kojimenez.site + +**Destroy Infrastructure** (destroy.yml) + 1. Run Ansible Playbook for Uninstallation (Removes installed programs) + ```bash + ansible-playbook -i aws_ec2.yml destroyinf.yml + ``` + 2. Terraform Init (Checks Terraform Files) + ```bash + terraform init + ``` + 3. Terraform Destroy (Destroys running instance) + ```bash + terraform destroy -auto-approve -input=false + ``` +*Output:* +- Destroys instance that is made with deploy.yml + + +**Ansible and Terraform Linter** (ansiblelint.yml and tflint.yml) + - Runs linter for every push made into the main branch. Workflows is copied from https://github.com/ansible/ansible-lint-action for Ansible Lint and https://github.com/marketplace/actions/setup-tflint for TFlint. + + + From 3a824c597d038e7581d640a181fd35ebf14c2755 Mon Sep 17 00:00:00 2001 From: Kevin Jimenez <56909942+KevJimenez@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:44:41 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0385098..8a72a17 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ An automated setup of infrastracture with configuration for a web server (uses A ansible-playbook -i aws_ec2.yml playbook.yml -e "docker_key=${{ secrets.DOCKER_KEY }}" ``` *Output:* -- AWS Instance running docker with [Watchtower](https://github.com/containrrr/watchtower) and Containerized [Personal-Portfolio](https://github.com/KevJimenez/Personal-Portfolio). +- AWS EC2 Instance running docker with [Watchtower](https://github.com/containrrr/watchtower) and Containerized [Personal-Portfolio](https://github.com/KevJimenez/Personal-Portfolio). - Personal portfolio website that can be accessed from https://kojimenez.site **Destroy Infrastructure** (destroy.yml)