-
Notifications
You must be signed in to change notification settings - Fork 38
/
.gitlab-ci.yml
220 lines (198 loc) · 6.72 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
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
# Official framework image. Look for the different tagged releases at: https://hub.docker.com/r/library/node/tags/
variables:
CONFIG_PACKAGE_NAME: cdf-infrastructure-demo
RUSH_PARALLELISM: 8
APP_CONFIG_DIR: common/build/configdir
BRANCH: main
.staging-variables: &staging-variables
ENVIRONMENT: development-staging
AWS_REGION: us-west-2
.live-variables: &live-variables
ENVIRONMENT: development
AWS_REGION: us-west-2
.default-run-condition: &default-run-condition
- if: ($CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE != /.*\[skip ci\].*/)
.branch-run-condition: &branch-run-condition
- if: ($CI_COMMIT_BRANCH != "main")
.common-build-steps: &common-build-steps # install dependencies
- cd ${CI_PROJECT_DIR}/source
- rush install
# build
- rush build
.common-install-deployment-dependencies: &common-install-deployment-dependencies
- env | sort
- yum update -y
# install tool dependencies (required to test some services)
- yum install -y git tar openssl zip unzip
# install specific version of pnpm needed by rush
- curl -f https://get.pnpm.io/v5.js | node - add --global pnpm@5
- npm install -g @microsoft/rush
# install aws cli
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip -qq awscliv2.zip
- ./aws/install && rm -rf ./aws && rm awscliv2.zip
# install jq
- curl -s -qL -o /usr/bin/jq https://stedolan.github.io/jq/download/linux64/jq
- chmod +x /usr/bin/jq
.common-install-node-dependencies: &common-install-node-dependencies # install dependencies
- curl -f https://get.pnpm.io/v5.js | node - add --global pnpm@5
- npm install -g @microsoft/rush
.common-git-steps: &common-git-steps # install dependencies
- git config --global user.name "gitlab-ci-token"
- git config --global user.email "gitlab-ci-token"
- git remote set-url origin https://gitlab-ci-token:$PROJECT_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git
.common-artifacts: &common-artifacts
artifacts:
paths:
- source/common/
- source/infrastructure/**/build.zip
- source/packages/**/.rush/
- source/packages/**/dist/
- source/packages/**/tsconfig.tsbuildinfo
- source/packages/**/bundle.zip
stages:
- build
- test
- deployStage
- integrationTest
- deployLive
- release
### not working at the moment, therefore using artifacts as a temp workaround
# cache:
# # enable per-branch caching
# key: "$CI_COMMIT_REF_SLUG"
# paths:
# - *common-artifacts
default:
image:
name: public.ecr.aws/lambda/nodejs:18
entrypoint: [""]
before_script:
- *common-install-deployment-dependencies
- *common-git-steps
tags:
- arch:amd64
- size:large
downloadInfastructureConfig:
rules:
- *default-run-condition
stage: build
before_script:
- env | sort
- echo 'download jq'
- curl -s -qL -o /usr/bin/jq https://stedolan.github.io/jq/download/linux64/jq
- chmod +x /usr/bin/jq
- echo 'download wget'
- yum install -y wget unzip
image:
name: public.ecr.aws/amazonlinux/amazonlinux:2
entrypoint: [""]
script:
- 'CONFIG_PACKAGE_VERSION=$(curl -H "PRIVATE-TOKEN: $CDF_INFRASTRUCTURE_GIT_TOKEN" "${CI_API_V4_URL}/projects/${CONFIG_REPO_PROJECT_ID}/packages?sort=desc" | jq -r ".[0].version")'
- 'wget --header="PRIVATE-TOKEN: $CDF_INFRASTRUCTURE_GIT_TOKEN" ${CI_API_V4_URL}/projects/${CONFIG_REPO_PROJECT_ID}/packages/generic/${CONFIG_PACKAGE_NAME}/${CONFIG_PACKAGE_VERSION}/config.zip'
- mkdir -p common/build
- cp config.zip common/build/config.zip
- unzip -d $APP_CONFIG_DIR common/build/config.zip
artifacts:
paths:
- $APP_CONFIG_DIR/
buildLambaLayersZip:
rules:
- *default-run-condition
stage: build
before_script:
- yum update -y && yum install -y openssl zip
image:
name: public.ecr.aws/amazonlinux/amazonlinux:2
entrypoint: [""]
script:
- cd ${CI_PROJECT_DIR}/source && mkdir -p common/build
- cd common/build && mkdir -p bin lib && cp /bin/openssl bin/ && cp /usr/lib64/libbz2.so.1 lib/ && zip -r build.zip * && rm -rf bin lib
- cd ${CI_PROJECT_DIR}/source && mkdir -p infrastructure/lambdaLayers/openssl/build && cp common/build/build.zip infrastructure/lambdaLayers/openssl/build/build.zip
artifacts:
paths:
- source/infrastructure/lambdaLayers/openssl/build/build.zip
branchTest:
rules:
- *default-run-condition
stage: test
script:
- *common-build-steps
# build
- rush build
- export RUSH_PARALLELISM=1
- rush test
# Bundling the node project when it past
- export RUSH_PARALLELISM=8
- cd ${CI_PROJECT_DIR}
- bash -c source/cicd/buildproject_postbuild.bash
#
<<: *common-artifacts
test:
rules:
- *branch-run-condition
stage: test
script:
- *common-build-steps
- rush build
- export RUSH_PARALLELISM=1
- rush test
deployStage:
rules:
- *default-run-condition
stage: deployStage
variables:
<<: *staging-variables
script:
- pushd source
- rush install --purge
- popd
# export the location of the config
- export CODEBUILD_SRC_DIR_source_infrastructure="${CI_PROJECT_DIR}/${APP_CONFIG_DIR}"
# deploy to staging environment
- bash -c source/cicd/deployproject_build.bash
after_script:
- bash -c source/cicd/deployproject_postbuild.bash
integrationTest:
rules:
- *default-run-condition
stage: integrationTest
before_script:
- *common-install-deployment-dependencies
variables:
<<: *staging-variables
script:
- pushd source
- rush install --purge
- popd
# export the location of the config
- export CODEBUILD_SRC_DIR_source_infrastructure="${CI_PROJECT_DIR}/${APP_CONFIG_DIR}"
# run in the integration tests
- bash -c source/cicd/integrationtestsproject_build.bash
deployLive:
rules:
- *default-run-condition
stage: deployLive
variables:
<<: *live-variables
script:
# deploy to live environment
- pushd source
- rush install --purge
- popd
- export CODEBUILD_SRC_DIR_source_infrastructure="${CI_PROJECT_DIR}/${APP_CONFIG_DIR}"
- bash -c source/cicd/deployproject_build.bash
after_script:
- bash -c source/cicd/deployproject_postbuild.bash
release:
image:
name: public.ecr.aws/lambda/nodejs:18
entrypoint: [""]
stage: release
before_script:
- *common-install-deployment-dependencies
rules:
- *default-run-condition
script:
# Create release package
- tar -cvf ../aws-connected-device-framework.tar --exclude=.git --exclude=node_modules --exclude=deploy --exclude=.history --exclude=temp .
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ../aws-connected-device-framework.tar "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/aws-connected-device-framework/${CI_JOB_ID}/aws-connected-device-framework.tar"'