-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (64 loc) · 2.58 KB
/
cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: CD Pipeline
on:
workflow_dispatch:
jobs:
provision-infrastructure:
name: Provision AWS Infrastructure with Terraform
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.8.5"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Initialize Terraform
run: terraform init -backend-config="bucket=${{ secrets.S3_BUCKET }}" -backend-config="region=${{ secrets.AWS_DEFAULT_REGION }}"
working-directory: infra/provisioning
- name: Terraform Plan
run: terraform plan -lock-timeout=600s -compact-warnings -out=plan.tfplan
working-directory: infra/provisioning
env:
TF_VAR_key_pair: ${{ secrets.TF_VAR_KEY_PAIR }}
- name: Apply Terraform Plan
run: terraform apply "plan.tfplan"
working-directory: infra/provisioning
- name: Get EC2 instance public IP
id: get_ip
run: |
echo "Terraform output:"
terraform output -raw ec2_public_ip
EC2_PUBLIC_IP=$(terraform output -raw ec2_public_ip)
echo "EC2_PUBLIC_IP=$EC2_PUBLIC_IP"
echo "EC2_PUBLIC_IP=$EC2_PUBLIC_IP" >> $GITHUB_ENV
working-directory: infra/provisioning
deploy-stack:
name: Deploy Monitoring Stack with Ansible
runs-on: ubuntu-latest
needs: provision-infrastructure
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Install Ansible
run: sudo apt-get install -y ansible
- name: Create SSH Key File
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ssh_key.pem
chmod 600 ssh_key.pem
working-directory: infra/deployment
- name: Create Ansible inventory
run: |
echo "[gbfs]" > inventory.ini
echo "gbfs-instance ansible_host=${{ env.EC2_PUBLIC_IP }} ansible_user=ec2-user ansible_ssh_private_key_file=ssh_key.pem ansible_ssh_common_args='-o StrictHostKeyChecking=no'" >> inventory.ini
working-directory: infra/deployment
- name: Deploy GBFS Monitoring Stack
run: ansible-playbook playbooks/gbfs.yaml -i inventory.ini
working-directory: infra/deployment
env:
ANSIBLE_HOST_KEY_CHECKING: false