-
Notifications
You must be signed in to change notification settings - Fork 7
/
Taskfile.sample-app.yml
239 lines (210 loc) · 7.01 KB
/
Taskfile.sample-app.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
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
version: '3'
vars:
# need to use 2 folders to ensure each relative path is correct after moving from samples to development
DEVELOPMENT_DIR: "development/project"
SAMPLES_APP_DIR: "samples"
# Default sample app to use
SAMPLE_APP: '{{.SAMPLE_APP | default "cdk-ts-example"}}'
STAGES_ENABLED: "DEV"
tasks:
dev:info:
desc: Prints information about the pipeline
summary: Prints information about the pipeline
dir: '{{.DEVELOPMENT_DIR}}'
silent: true
cmds:
- echo "Information:"
- 'echo "AWS Region: ${AWS_REGION}"'
- 'echo "AWS RES Account: ${ACCOUNT_RES}"'
- 'echo "AWS Profile: $RES_ACCOUNT_AWS_PROFILE"'
- 'echo "CDK Qualifier: ${CDK_QUALIFIER}"'
- 'echo "Git Repository: ${GIT_REPOSITORY}"'
- echo "Accounts:"
- for: { var: STAGES_ENABLED, split: "," }
cmd: 'echo " - {{.ITEM}}: ${ACCOUNT_{{.ITEM}}} -- profile: ${{.ITEM}}_ACCOUNT_AWS_PROFILE"'
- echo "===================================================="
- npm run cdkls
list:
desc: List all available sample apps
dir: '{{.SAMPLES_APP_DIR}}'
silent: true
cmds:
- echo "Available sample apps:"
- echo "-----------------------"
- ls
dev:clean:
desc: Clean the build directory
silent: true
cmds:
- rm -rf {{.DEVELOPMENT_DIR}}
dev:create-development-dir:
desc: Create the development directory
internal: true
silent: true
cmds:
- mkdir -p {{.DEVELOPMENT_DIR}}
status:
- test -d {{.DEVELOPMENT_DIR}}
dev:init:
desc: Initialize the development with {{.SAMPLE_APP}}
requires:
vars:
- SAMPLE_APP
cmds:
- task: dev:clean
- task: dev:create-development-dir
- cp -a {{.SAMPLES_APP_DIR}}/{{.SAMPLE_APP}}/. {{.DEVELOPMENT_DIR}}
- task: dev:npm:install
dev:npm:install:
desc: Install the dependencies for {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npx projen install
- npm run default
- npm run projen
dev:update:
desc: Update the wrapper for {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npm run upgrade
dev:synth:
desc: Synthesize the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npm run build
- npm exec -- cdk synth
dev:deploy:
desc: Deploy the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npm run build
- npm exec -- cdk deploy --all --require-approval never
dev:destroy:
desc: Destroy the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
interactive: true
cmds:
- npm exec -- cdk --version
- for: { var: STAGES_ENABLED, split: "," }
task: dev:destroy:stage
vars:
STAGE: '{{.ITEM}}'
- npm exec -- cdk destroy --all --profile {{.RES_ACCOUNT_AWS_PROFILE}}
dev:destroy:stage:
desc: Destroy the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
interactive: true
cmds:
- npm exec -- cdk ls
- npm exec -- cdk destroy --profile ${{.STAGE}}_ACCOUNT_AWS_PROFILE {{.STAGE}}/*
dev:bootstrap:
desc: Bootstrap the development for {{.SAMPLE_APP}}
summary: |
This task will bootstrap the AWS accounts to be able to deploy CDK applications.
Get more information about CDK bootstrapping: https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html
dir: '{{.DEVELOPMENT_DIR}}'
silent: true
cmds:
- echo "==============================================================="
- echo "# Bootstrapping CDK for the pipeline {{.GIT_REPOSITORY}} "
- echo "==============================================================="
- task: dev:info
- task: dev:bootstrap:internal
- echo "================================================================"
dev:workbench:deploy:
desc: Deploy the development with {{.SAMPLE_APP}} in a workbench
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npm run build
- npm run workbench -- --all --require-approval never --profile {{.DEV_ACCOUNT_AWS_PROFILE}}
dev:bootstrap:internal:
internal: true
desc: Internal task to bootstrap the AWS accounts to be able to deploy CDK applications
dir: '{{.DEVELOPMENT_DIR}}'
preconditions:
- sh: '[ `jq -r ''.context."@aws-cdk/core:bootstrapQualifier"'' cdk.json` = "$CDK_QUALIFIER" ]'
msg: 'The bootstrap qualifier does not match the CDK_QUALIFIER variable. Please update the cdk.json file.'
cmds:
- task: dev:bootstrap:RES
- for: { var: STAGES_ENABLED, split: "," }
task: dev:bootstrap:account
vars:
STAGE: '{{.ITEM}}'
OPTS: --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess --trust ${ACCOUNT_RES}
dev:bootstrap:RES:
internal: true
cmds:
- task: dev:bootstrap:account
vars:
STAGE: RES
dev:bootstrap:account:
internal: true
dir: '{{.DEVELOPMENT_DIR}}'
requires:
vars:
- CDK_QUALIFIER
- AWS_REGION
- STAGE
preconditions:
- sh: '[[ ! -z "${{.STAGE}}_ACCOUNT_AWS_PROFILE" ]]'
msg: 'The environment {{.STAGE}} does not have an AWS profile defined. Please define it in the .env file.'
cmds:
- cdk bootstrap --profile ${{.STAGE}}_ACCOUNT_AWS_PROFILE --qualifier $CDK_QUALIFIER {{.OPTS}} aws://$ACCOUNT_{{.STAGE}}/${AWS_REGION}
dev:build:
desc: Build the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npm run build
dev:prepare:
desc: Prepare the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- npx projen install:ci
- npm run validate -- --fix
- npm run lint -- --fix
- npm run license -- --fix
dev:git:push:
desc: Push the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
deps:
- dev:git:init
- dev:prepare
status:
- '[ ! `git status` ]'
cmds:
- git add .
- 'git commit -m "chore: Init"'
- git push -u -f sample-origin main
dev:git:init:
desc: Initialize the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
status:
- 'git remote get-url sample-origin'
requires:
vars:
- GIT_REPOSITORY
- AWS_REGION
- RES_ACCOUNT_AWS_PROFILE
cmds:
- git init .
- git remote add sample-origin codecommit::{{.AWS_REGION}}://{{.RES_ACCOUNT_AWS_PROFILE}}@{{.GIT_REPOSITORY}}
- task: dev:git:defender
dev:git:defender:
desc: Configure the development with {{.SAMPLE_APP}} with GIT Defender
dir: '{{.DEVELOPMENT_DIR}}'
interactive: true
cmds:
- command -v git-defender && git-defender --setup || echo "Nothing to do..."
dev:loop:
desc: Loop the development with {{.SAMPLE_APP}}
dir: '{{.DEVELOPMENT_DIR}}'
cmds:
- task codeartifact:publish
- task: dev:update
- task: dev:deploy
- task: dev:git:push
upgrade:
desc: Upgrade sample project
dir: '{{.SAMPLES_APP_DIR}}/{{.SAMPLE_APP}}'
cmds:
- npm run upgrade