Skip to content

Commit

Permalink
feat(cd): add CD pipeline for automated infra provisioning & deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
B3ns44d committed Sep 16, 2024
1 parent 4ac3309 commit 1ce8731
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CD Pipeline

on:
workflow_dispatch:

jobs:
plan-infrastructure:
name: Terraform Plan AWS Infrastructure
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Set up Terraform
uses: hashicorp/setup-terraform@v1

- name: Initialize Terraform
run: terraform init -upgrade

- name: Terraform Plan
run: terraform plan -lock-timeout=600s -compact-warnings -out=plan.tfplan

- name: Save Terraform Plan as an artifact
uses: actions/upload-artifact@v2
with:
name: plan
path: plan.tfplan

apply-infrastructure:
name: Terraform Apply AWS Infrastructure (Manual)
runs-on: ubuntu-latest
needs: plan-infrastructure

steps:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Download Terraform Plan
uses: actions/download-artifact@v2
with:
name: plan

- name: Set up Terraform
uses: hashicorp/setup-terraform@v1

- name: Wait for Manual Approval
uses: peter-evans/wait-for-approval@v2
with:
custom-message: "Please approve to apply the Terraform changes."

- name: Terraform Apply
id: terraform_apply
run: terraform apply "plan.tfplan"

- name: Get EC2 instance public IP
id: get_ip
run: echo "::set-output name=ec2_public_ip::$(terraform output -raw ec2_public_ip)"

deploy-stack:
name: Deploy Monitoring Stack with Ansible
runs-on: ubuntu-latest
needs: apply-infrastructure

steps:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Install Ansible
run: sudo apt-get install -y ansible

- name: Create Ansible inventory
run: |
echo "[gbfs]" > inventory.ini
echo "gbfs-instance ansible_host=${{ steps.get_ip.outputs.ec2_public_ip }} ansible_user=ec2-user ansible_ssh_private_key_file=${{ secrets.SSH_PRIVATE_KEY }} ansible_ssh_common_args='-o StrictHostKeyChecking=no'" >> inventory.ini
- name: Deploy GBFS Monitoring Stack
run: ansible-playbook infra/deployment/playbooks/gbfs.yaml -i inventory.ini
env:
ANSIBLE_HOST_KEY_CHECKING: false

0 comments on commit 1ce8731

Please sign in to comment.