-
Notifications
You must be signed in to change notification settings - Fork 13
/
bp-tf-ci.yaml
284 lines (259 loc) · 10.4 KB
/
bp-tf-ci.yaml
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Copyright (c) CloudBees, Inc.
apiVersion: automation.cloudbees.io/v1alpha1
kind: workflow
name: ci
on:
# Enable once Issue #83 is solved (Disable Manual trigger. workflow_dispatch)
# It requires
# pull_request:
# branches:
# - 'main'
workflow_dispatch:
env:
BUCKET_NAME_TF_STATE: cbci-eks-addon-bp
AWS_REGION_TF_BUCKET: us-east-1
TAGS_TF_BUCKET: '[{Key=cb-owner,Value=professional-services},{Key=cb-user,Value=cb-platform},{Key=cb-purpose,Value=production shared cluster}]'
AWS_ROLE_TO_ASSUME: "infra-admin-ci"
TF_VAR_suffix: "ci"
TF_VAR_aws_region: "us-west-2"
TF_AUTO_VARS_FILE: |
tags = {
"cb-owner" : "professional-services"
"cb-user" : "cb-platform"
"cb-purpose" : "ci"
}
trial_license = {
first_name = "CloudBees.io"
last_name = "Platform"
email = "[email protected]"
company = "CloudBees Inc."
}
ci = true
jobs:
init:
steps:
- name: Configure AWS Credentials
uses: cloudbees-io/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION_TF_BUCKET }}
aws-access-key-id: ${{ secrets.AWS_TF_CBCI_EKS_AccessKeyID }}
aws-secret-access-key: ${{ secrets.AWS_TF_CBCI_EKS_SecretAccessKey }}
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
role-external-id: cloudbees
role-duration-seconds: "3600"
#TODO: Add tags for the bucket
- name: Create Terraform Backend Bucket if not exists
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
shell: bash
run: |
set -x
if aws s3api head-bucket --bucket ${{ env.BUCKET_NAME_TF_STATE }} 2>/dev/null; then
echo "Bucket ${{ env.BUCKET_NAME_TF_STATE }} already exists."
else
echo "Bucket ${{ env.BUCKET_NAME_TF_STATE }} does not exist. Creating now..."
aws s3api create-bucket --bucket ${{ env.BUCKET_NAME_TF_STATE }} \
--region ${{ env.AWS_REGION_TF_BUCKET }}
fi
aws s3api put-bucket-tagging --bucket ${{ env.BUCKET_NAME_TF_STATE }} \
--tagging 'TagSet=${{ env.TAGS_TF_BUCKET }}'
bp01:
env:
# Stages
# CI: deploy,validate,destroy
# Troubleshooting: deploy,validate,onboarding
# Nuke (Delete Dangling resource): wipeout
STAGES: "deploy,validate,destroy"
ROOT: 01-getting-started
TF_VAR_hosted_zone: bp01-ci.aws.ps.beescloud.com
needs:
- init
steps:
- name: Configure AWS Credentials
uses: cloudbees-io/configure-aws-credentials@v1
with:
aws-region: ${{ env.TF_VAR_aws_region }}
aws-access-key-id: ${{ secrets.AWS_TF_CBCI_EKS_AccessKeyID }}
aws-secret-access-key: ${{ secrets.AWS_TF_CBCI_EKS_SecretAccessKey }}
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
role-external-id: cloudbees
role-duration-seconds: "3600"
- name: Checkout code
uses: cloudbees-io/checkout@v1
- name: 01-getting-started - Set
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
shell: bash
run : |
cat <<EOT >> blueprints/${{ env.ROOT }}/.auto.tfvars
${{ env.TF_AUTO_VARS_FILE }}
EOT
cat blueprints/${{ env.ROOT }}/.auto.tfvars
cat <<EOT >> blueprints/${{ env.ROOT }}/backend.tf
terraform {
backend "s3" {
bucket = "${{ env.BUCKET_NAME_TF_STATE }}"
key = "${{ env.ROOT }}/ci/terraform.tfstate"
region = "${{ env.AWS_REGION_TF_BUCKET }}"
}
}
EOT
echo "Environment Variables:"
printenv
- name: 01-getting-started - Deploy
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'deploy')
kind: build
shell: bash
run : |
set -x
# It Resolves Issue #66
aliases=("alias/eks/cbci-bp02-${{ env.TF_VAR_suffix }}-eks" "alias/eks/cbci-bp02-${{ env.TF_VAR_suffix }}")
for alias in "${aliases[@]}"; do
aws kms delete-alias \
--alias-name $alias \
--region ${{ env.TF_VAR_aws_region }} || echo "$alias does not exist"
done
CI=true make deploy
aws s3api put-object \
--bucket "${{ env.BUCKET_NAME_TF_STATE }}" \
--region "${{ env.AWS_REGION_TF_BUCKET }}" \
--body blueprints/${{ env.ROOT }}/terraform.output \
--key ${{ env.ROOT }}/ci/${{ env.ROOT }}.terraform.output || echo "Failed to put $body object in ${{ env.BUCKET_NAME_TF_STATE }}"
- name: 01-getting-started - Validate
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'validate')
kind: test
shell: bash
run : |
CI=true make validate
- name: 01-getting-started - Destroy
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'destroy')
shell: bash
run : |
CI=true make destroy
- name: 01-getting-started - Wipeout
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'wipeout')
shell: bash
run : |
terraform -chdir=blueprints/${{ env.ROOT }} init -reconfigure && CI=true make destroy
- name: 01-getting-started - Role Onboarding
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'onboarding')
env:
TARGET_ROLE: arn:aws:iam::324005994172:role/AWSReservedSSO_infra-admin_256addbf79cfacd1
shell: bash
run : |
set -x
cd blueprints/${{ env.ROOT }} && eval $(terraform output --raw kubeconfig_export)
kubectl describe configmap aws-auth -n kube-system
eksctl create iamidentitymapping \
--cluster $(terraform output --raw eks_cluster_name) \
--region ${{ env.TF_VAR_aws_region }} \
--arn ${{ env.TARGET_ROLE }} \
--username k8s-admin-rol \
--group system:masters
kubectl describe configmap aws-auth -n kube-system
bp02:
env:
# Stages
# CI: deploy,validate,destroy
# Troubleshooting: deploy,validate,onboarding
# Nuke (Delete Dangling resource): wipeout
STAGES: "deploy,validate,destroy"
ROOT: 02-at-scale
TF_VAR_hosted_zone: bp02-ci.aws.ps.beescloud.com
needs:
- init
steps:
- name: Configure AWS Credentials
uses: cloudbees-io/configure-aws-credentials@v1
with:
aws-region: ${{ env.TF_VAR_aws_region }}
aws-access-key-id: ${{ secrets.AWS_TF_CBCI_EKS_AccessKeyID }}
aws-secret-access-key: ${{ secrets.AWS_TF_CBCI_EKS_SecretAccessKey }}
role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }}
role-external-id: cloudbees
role-duration-seconds: "3600"
- name: Checkout code
uses: cloudbees-io/checkout@v1
- name: 02-at-scale - Set
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
shell: bash
run : |
cat <<EOT >> blueprints/${{ env.ROOT }}/.auto.tfvars
${{ env.TF_AUTO_VARS_FILE }}
dh_reg_secret_auth = {
username = "${{ secrets.AWS_TF_CBCI_EKS_DHUser }}"
password = "${{ secrets.AWS_TF_CBCI_EKS_DHPass }}"
email = "${{ secrets.AWS_TF_CBCI_EKS_DHMail }}"
}
EOT
cat blueprints/${{ env.ROOT }}/.auto.tfvars
cat <<EOT >> blueprints/${{ env.ROOT }}/backend.tf
terraform {
backend "s3" {
bucket = "${{ env.BUCKET_NAME_TF_STATE }}"
key = "${{ env.ROOT }}/ci/terraform.tfstate"
region = "${{ env.AWS_REGION_TF_BUCKET }}"
}
}
EOT
echo "Environment Variables:"
printenv
- name: 02-at-scale - Deploy
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'deploy')
kind: build
shell: bash
run : |
set -x
# It Resolves Issue #66
aliases=("alias/eks/cbci-bp02-${{ env.TF_VAR_suffix }}-eks" "alias/eks/cbci-bp02-${{ env.TF_VAR_suffix }}")
for alias in "${aliases[@]}"; do
aws kms delete-alias \
--alias-name $alias \
--region ${{ env.TF_VAR_aws_region }} || echo "$alias does not exist"
done
CI=true make deploy
aws s3api put-object \
--bucket "${{ env.BUCKET_NAME_TF_STATE }}" \
--region "${{ env.AWS_REGION_TF_BUCKET }}" \
--body blueprints/${{ env.ROOT }}/terraform.output \
--key ${{ env.ROOT }}/ci/${{ env.ROOT }}.terraform.output || echo "Failed to put $body object in ${{ env.BUCKET_NAME_TF_STATE }}"
- name: 02-at-scale - Validate
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'validate')
kind: test
shell: bash
run : |
CI=true make validate
- name: 02-at-scale - Destroy
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'destroy')
shell: bash
run : |
CI=true make destroy
- name: 02-at-scale - Wipeout
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'wipeout')
shell: bash
run : |
terraform -chdir=blueprints/${{ env.ROOT }} init -reconfigure && CI=true make destroy
- name: 02-at-scale - Role Onboarding
uses: docker://public.ecr.aws/r1n1q0e5/cloudbees-labs/tf-aws-cb-ci-eks-addon-agent:latest
if: contains(env.STAGES, 'onboarding')
env:
TARGET_ROLE: arn:aws:iam::324005994172:role/AWSReservedSSO_infra-admin_256addbf79cfacd1
shell: bash
run : |
set -x
eval $(terraform -chdir="blueprints/${{ env.ROOT }}" output --raw --raw kubeconfig_export)
kubectl describe configmap aws-auth -n kube-system
eksctl create iamidentitymapping \
--cluster $(terraform -chdir="blueprints/${{ env.ROOT }}" output --raw eks_cluster_name) \
--region ${{ env.TF_VAR_aws_region }} \
--arn ${{ env.TARGET_ROLE }} \
--username k8s-admin-rol \
--group system:masters
kubectl describe configmap aws-auth -n kube-system