-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cd): add CD pipeline for automated infra provisioning & deployment
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |