This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (135 loc) · 5 KB
/
deployments.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Apply Deployments
on:
workflow_dispatch:
repository_dispatch:
types: [deployment]
jobs:
deploy-k8s:
name: Apply Deployments
runs-on: ubuntu-latest
steps:
- name: AWS Deployment
run: echo "Deploying..."
- name: Checkout code
uses: actions/checkout@v2
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: "us-east-1"
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
- name: Run deploy script
run: |
aws eks update-kubeconfig --name eks-techmedicos --region us-east-1
chmod +x ./k8s/apply-all.sh
./k8s/apply-all.sh
#############################################################
wait_lb:
name: Aguardar criação do Load Balancer
runs-on: ubuntu-latest
needs: deploy-k8s
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: 'us-east-1'
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
- name: Sleep for 3 minutes
run: sleep 180s
#############################################################
tf-test:
name: Terraform Test
runs-on: ubuntu-latest
needs: wait_lb
defaults:
run:
working-directory: src/terraform-api-gateway
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-region: 'us-east-1'
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.6.2
- name: Prepare environment
id: tf-init
run: terraform init
- name: Terraform fmt
id: tf-fmt
run: terraform fmt --recursive
- name: Terraform validate
id: tf-validate
run: terraform validate -no-color
- name: Terraform Plan
id: tf-plan
run: terraform plan -lock=false -no-color -input=false
continue-on-error: true
- name: Pull Request Updates
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: ${{ steps.tf-plan.outputs.stdout }}
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.tf-fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.tf-init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.tf-validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.tf-plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`terraform\n
${process.env.PLAN}
\`\`\`
</details>
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Terraform Plan Status
if: steps.tf-plan.outcome == 'failure'
run: exit 1
tf-deploy:
name: Terraform Deploy
needs:
- tf-test
if: github.ref == 'refs/heads/release' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
defaults:
run:
working-directory: src
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: 'us-east-1'
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
- name: Configure AWS Dotnet CLI
run: dotnet tool install -g Amazon.Lambda.Tools
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Prepare environment
run: terraform -chdir=terraform-api-gateway/ init
- name: Terraform Plan
run: terraform -chdir=terraform-api-gateway/ plan -lock=false -no-color -input=false
- name: Execute terraform apply
run: terraform -chdir=terraform-api-gateway/ apply -lock=false -auto-approve -input=false
#############################################################