-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
187 lines (172 loc) · 5.79 KB
/
.gitlab-ci.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
image: ${CI_REGISTRY}/rey/debian-ci:${DEBIAN_CI_VERSION}
variables:
SERVERLESS_SERVICE_NAME: "alexa-skill-dark-pebble"
QA_INVOCATION: "Black Sky Qa"
PROD_INVOCATION: "Black Sky"
AWS_REGION: "us-east-1"
KMS_ALIAS: "alias/serverless-${SERVERLESS_SERVICE_NAME}"
stages:
- infrastructure
- unittest
- deploy-to-qa
- ui-test-qa
- deploy-to-prod
- ui-test-prod
before_script:
- echo ${CI_JOB_TOKEN} | docker login -u gitlab-ci-token --password-stdin ${CI_REGISTRY}
- echo "${GPS_POSITIONS}" > gps_positions.json
cache:
key: ${CI_COMMIT_REF_NAME}
untracked: true
paths:
- node_modules
unit-test:
stage: unittest
script:
- npm install
- npm audit
- python3 -m nose
.cleanup-skills: &cleanup-skills |
echo Deleting spurious ${INVOCATION} skills
for skillId in $(ask api list-skills |
jq -r '.skills[] |
select ((.nameByLocale."en-US"|ascii_downcase) == ("'"${INVOCATION}"'"|ascii_downcase)) | .skillId');
do
echo Deleting skill ${skillId}
ask api delete-skill --skill-id $skillId
done
.encrypt-secrets: &encrypt-secrets |
echo Encrypt secrets
export encDarkSkySecretKey=$(aws kms encrypt --key-id ${KMS_ALIAS} --plaintext "${DARK_SKY_SECRET_KEY}" |
jq -r '.CiphertextBlob')
.get-kms: &get-kms |
echo Creating KMS if needed
export awsKmsKeyId=$(aws kms list-aliases |
jq -r '.Aliases[] |
select(.AliasName=="'$KMS_ALIAS'") |
.TargetKeyId')
if [[ -z "${awsKmsKeyId}" ]]; then
masterKeyId=$(aws kms create-key --description "Master Key for ${SERVERLESS_SERVICE_NAME}"
--region ${AWS_REGION} |
jq -r '.KeyMetadata.KeyId');
aws kms create-alias --alias-name "$KMS_ALIAS" --target-key-id $masterKeyId;
export awsKmsKeyId=$(aws kms list-aliases |
jq -r '.Aliases[] |
select(.AliasName=="'$KMS_ALIAS'") |
.TargetKeyId');
fi
export awsKmsKeyArn=$(aws kms list-keys |
jq -r '.Keys[] | select(.KeyId=="'"${awsKmsKeyId}"'") | .KeyArn')
.deploy-skill: &deploy-skill |
echo Serverless and ASK
export Security="unsecure"
npm run deploy:$SERVERLESS_STAGE
cd skill
export functionArn=$(aws lambda list-functions |
tee aws_lambda_list-functions.json |
jq -r '.Functions[] |
select(.FunctionName=="'$SERVERLESS_STAGE'-'$SERVERLESS_SERVICE_NAME'") |
.FunctionArn')
echo Identified lambda function as ${functionArn}
rm -rf .ask && mkdir .ask
jq -n '.deploy_settings.default.was_cloned = false |
.deploy_settings.default.merge.manifest.apis.custom.endpoint.uri = "'$functionArn'"' > .ask/config
cat ../etc/en-US.json |
jq '.interactionModel.languageModel.invocationName=("'"${INVOCATION}"'"|ascii_downcase)' > models/en-US.json
cat ../etc/skill.json |
jq '.manifest.publishingInformation.locales."en-US".summary="'"${INVOCATION}"'" |
.manifest.publishingInformation.locales."en-US".name="'"${INVOCATION}"'"' > skill.json
ask deploy
cd ..
export skillId=$(ask api list-skills |
jq -r '.skills[] | select ((.nameByLocale."en-US"|ascii_downcase) == ("'"${INVOCATION}"'"|ascii_downcase)) | .skillId')
export Security="secure"
npm run deploy:$SERVERLESS_STAGE
echo Enabling skill-id=${skillId}
ask api enable-skill --skill-id $skillId
deploy-to-qa:
stage: deploy-to-qa
script:
- export INVOCATION="${QA_INVOCATION}"
- export SERVERLESS_STAGE="qa"
- npm install
- *cleanup-skills
- *get-kms
- *encrypt-secrets
- *deploy-skill
only:
- develop
environment:
name: qa
url: https://developer.amazon.com/alexa/console/ask
artifacts:
paths:
- .serverless
- skill
- aws_lambda_list-functions.json
expire_in: 2 day
when: always
.ask-test: &ask-test |
echo Test the skill through ASK
skillId=$(ask api list-skills |
jq -r '.skills[] | select ((.nameByLocale."en-US"|ascii_downcase) == ("'"${INVOCATION}"'"|ascii_downcase)) | .skillId')
simulationId=$(ask simulate -l en-US -s ${skillId} -t "open ${INVOCATION}" 2>&1 | strings | sed -n -e 's/Simulation created for simulation id: \([-0-9a-zA-Z]*\)$/\1/p')
echo simulationId is ${simulationId}
simulation=$(ask api get-simulation -i ${simulationId} -s ${skillId})
mkdir -p artifacts
echo $simulation > "artifacts/simulation-${INVOCATION}.json"
#npm run logs-tail-${SERVERLESS_STAGE} > "artifacts/simulation-${INVOCATION}.log"
echo $simulation
#[[ $(echo $simulation | jq '.result.skillExecutionInfo.invocationResponse.body.response.outputSpeech.text' | wc -w) -gt 5 ]]
test-ui-qa:
stage: ui-test-qa
script:
- export INVOCATION="${QA_INVOCATION}"
- export SERVERLESS_STAGE="qa"
- *get-kms
- *encrypt-secrets
- *ask-test
only:
- develop
artifacts:
paths:
- artifacts
expire_in: 1 month
when: always
deploy-to-production:
stage: deploy-to-prod
script:
- export INVOCATION="${PROD_INVOCATION}"
- export SERVERLESS_STAGE="prod"
- npm install
- *cleanup-skills
- *get-kms
- *encrypt-secrets
- *deploy-skill
only:
- master
environment:
name: production
url: https://developer.amazon.com/alexa/console/ask
artifacts:
paths:
- .serverless
- skill
- aws_lambda_list-functions.json
expire_in: 2 day
when: always
test-ui-prod:
stage: ui-test-prod
script:
- export INVOCATION="${PROD_INVOCATION}"
- export SERVERLESS_STAGE="prod"
- *get-kms
- *encrypt-secrets
- *ask-test
only:
- master
artifacts:
paths:
- artifacts
expire_in: 1 month
when: always