Skip to content

Commit e84f017

Browse files
authored
feat: update gitlab pipeline (#578)
* add `ap-southeast-5` * revamp pipeline * build image first * awscli is already installed * only build image on changes on dockerfile * see if cli updates * build image and check latest `aws-cli` version * specify aws cli version * update image building and aws cli install
1 parent 9e4af12 commit e84f017

12 files changed

+96
-71
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ package-lock.json
1010
**/.serverless
1111
/.idea/
1212

13-
ci/build-*.yaml
13+
.gitlab/build-*.yaml

.gitlab-ci.yml

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1+
variables:
2+
DOCKER_TARGET_IMAGE: registry.ddbuild.io/ci/datadog-lambda-js
3+
DOCKER_TARGET_VERSION: latest
4+
15
stages:
26
- pre
37
- build
48

9+
ci image:
10+
stage: build
11+
image: registry.ddbuild.io/images/docker:20.10
12+
tags: ["arch:arm64"]
13+
needs: []
14+
rules:
15+
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"'
16+
changes:
17+
- .gitlab/Dockerfile
18+
when: on_success
19+
variables:
20+
DOCKER_TARGET: ${DOCKER_TARGET_IMAGE}:${DOCKER_TARGET_VERSION}
21+
script:
22+
- docker buildx build --platform linux/amd64,linux/arm64 --no-cache --pull --push --tag ${DOCKER_TARGET} -f .gitlab/Dockerfile .
23+
524
.go-cache: &go-cache
625
key: datadog-lambda-js-go-cache
726
policy: pull
@@ -13,16 +32,16 @@ generator:
1332
cache: *go-cache
1433
script:
1534
- apk add --no-cache gomplate
16-
- gomplate --config ci/config.yaml
35+
- gomplate --config .gitlab/config.yaml
1736
artifacts:
1837
paths:
19-
- ci/*-pipeline.yaml
38+
- .gitlab/*-pipeline.yaml
2039

2140
build-layers:
2241
stage: build
2342
trigger:
2443
include:
25-
- artifact: ci/build-pipeline.yaml
44+
- artifact: .gitlab/build-pipeline.yaml
2645
job: generator
2746
strategy: depend
2847
rules:

.gitlab/Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM registry.ddbuild.io/images/docker:24.0.5
2+
3+
RUN apt-get update && apt-get install -y --fix-missing --no-install-recommends \
4+
curl gcc gnupg g++ make cmake unzip openssl g++ uuid-runtime xxd ca-certificates
5+
6+
# Install NodeJS 18.x
7+
RUN mkdir -p /etc/apt/keyrings
8+
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
9+
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
10+
RUN apt-get update && apt-get install -y nodejs
11+
12+
# Install Yarn and Typescript globally
13+
RUN npm install --global yarn typescript
14+
RUN yarn global add serverless@^3 --prefix /usr/local
15+
16+
# Install AWS CLI
17+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
18+
RUN unzip awscliv2.zip && ./aws/install

.gitlab/config.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
inputFiles:
2+
- .gitlab/input_files/build.yaml.tpl
3+
4+
outputFiles:
5+
- .gitlab/build-pipeline.yaml
6+
7+
datasources:
8+
runtimes:
9+
url: .gitlab/datasources/runtimes.yaml
10+
regions:
11+
url: .gitlab/datasources/regions.yaml
12+
environments:
13+
url: .gitlab/datasources/environments.yaml
File renamed without changes.

ci/datasources/regions.yaml .gitlab/datasources/regions.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ regions:
1111
- code: "ap-southeast-2"
1212
- code: "ap-southeast-3"
1313
- code: "ap-southeast-4"
14+
- code: "ap-southeast-5"
1415
- code: "ap-northeast-1"
1516
- code: "ap-northeast-2"
1617
- code: "ap-northeast-3"
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
variables:
2+
CI_DOCKER_TARGET_IMAGE: registry.ddbuild.io/ci/datadog-lambda-js
3+
CI_DOCKER_TARGET_VERSION: latest
4+
15
stages:
26
- build
37
- test
@@ -11,18 +15,6 @@ default:
1115
# Retry when the runner fails to start
1216
- runner_system_failure
1317

14-
.install-node: &install-node
15-
- apt-get update
16-
- apt-get install -y ca-certificates curl gnupg xxd
17-
- mkdir -p /etc/apt/keyrings
18-
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
19-
# We are explicitly setting the node_18.x version for the installation
20-
- echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
21-
- apt-get update
22-
- apt-get install nodejs -y
23-
- npm install --global yarn
24-
- npm install --global typescript
25-
2618
.node-before-script: &node-before-script
2719
- echo 'yarn-offline-mirror ".yarn-cache/"' >> .yarnrc
2820
- echo 'yarn-offline-mirror-pruning true' >> .yarnrc
@@ -36,10 +28,10 @@ default:
3628
- $CI_PROJECT_DIR/.yarn-cache
3729
policy: pull
3830

39-
build-layer ({{ $runtime.name }}):
31+
build layer ({{ $runtime.name }}):
4032
stage: build
4133
tags: ["arch:amd64"]
42-
image: registry.ddbuild.io/images/docker:20.10
34+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
4335
artifacts:
4436
expire_in: 1 hr # Unsigned zips expire in 1 hour
4537
paths:
@@ -49,14 +41,14 @@ build-layer ({{ $runtime.name }}):
4941
script:
5042
- NODE_VERSION={{ $runtime.node_version }} ./scripts/build_layers.sh
5143

52-
check-layer-size ({{ $runtime.name }}):
44+
check layer size ({{ $runtime.name }}):
5345
stage: test
5446
tags: ["arch:amd64"]
55-
image: registry.ddbuild.io/images/docker:20.10
47+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
5648
needs:
57-
- build-layer ({{ $runtime.name }})
49+
- build layer ({{ $runtime.name }})
5850
dependencies:
59-
- build-layer ({{ $runtime.name }})
51+
- build layer ({{ $runtime.name }})
6052
script:
6153
- NODE_VERSION={{ $runtime.node_version }} ./scripts/check_layer_size.sh
6254

@@ -66,122 +58,119 @@ lint ({{ $runtime.name }}):
6658
image: registry.ddbuild.io/images/mirror/node:{{ $runtime.node_major_version }}-bullseye
6759
cache: &{{ $runtime.name }}-cache
6860
before_script: *node-before-script
61+
needs: []
6962
script:
7063
- yarn check-formatting
7164
- yarn lint
7265

73-
unit-test ({{ $runtime.name }}):
66+
unit test ({{ $runtime.name }}):
7467
stage: test
7568
tags: ["arch:amd64"]
7669
image: registry.ddbuild.io/images/mirror/node:{{ $runtime.node_major_version }}-bullseye
7770
cache: &{{ $runtime.name }}-cache
7871
before_script: *node-before-script
72+
needs: []
7973
script:
8074
- yarn build
8175
- yarn test --ci --forceExit --detectOpenHandles
8276
- bash <(curl -s https://codecov.io/bash)
8377

84-
integration-test ({{ $runtime.name }}):
78+
integration test ({{ $runtime.name }}):
8579
stage: test
8680
tags: ["arch:amd64"]
87-
image: registry.ddbuild.io/images/docker:20.10-py3
81+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
8882
needs:
89-
- build-layer ({{ $runtime.name }})
83+
- build layer ({{ $runtime.name }})
9084
dependencies:
91-
- build-layer ({{ $runtime.name }})
85+
- build layer ({{ $runtime.name }})
9286
cache: &{{ $runtime.name }}-cache
9387
variables:
9488
CI_ENABLE_CONTAINER_IMAGE_BUILDS: "true"
9589
before_script:
96-
- *install-node
97-
- EXTERNAL_ID_NAME=integration-test-externalid ROLE_TO_ASSUME=sandbox-integration-test-deployer AWS_ACCOUNT=425362996713 source ./ci/get_secrets.sh
98-
- yarn global add serverless@^3.38.0 --prefix /usr/local
90+
- EXTERNAL_ID_NAME=integration-test-externalid ROLE_TO_ASSUME=sandbox-integration-test-deployer AWS_ACCOUNT=425362996713 source .gitlab/scripts/get_secrets.sh
9991
- cd integration_tests && yarn install && cd ..
10092
script:
10193
- RUNTIME_PARAM={{ $runtime.node_major_version }} ./scripts/run_integration_tests.sh
10294

10395
{{ range $environment := (ds "environments").environments }}
10496

10597
{{ if or (eq $environment.name "prod") }}
106-
sign-layer ({{ $runtime.name }}):
98+
sign layer ({{ $runtime.name }}):
10799
stage: sign
108100
tags: ["arch:amd64"]
109-
image: registry.ddbuild.io/images/docker:20.10-py3
101+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
110102
rules:
111103
- if: '$CI_COMMIT_TAG =~ /^v.*/'
112104
when: manual
113105
needs:
114-
- build-layer ({{ $runtime.name }})
115-
- check-layer-size ({{ $runtime.name }})
106+
- build layer ({{ $runtime.name }})
107+
- check layer size ({{ $runtime.name }})
116108
- lint ({{ $runtime.name }})
117-
- unit-test ({{ $runtime.name }})
118-
- integration-test ({{ $runtime.name }})
109+
- unit test ({{ $runtime.name }})
110+
- integration test ({{ $runtime.name }})
119111
dependencies:
120-
- build-layer ({{ $runtime.name }})
112+
- build layer ({{ $runtime.name }})
121113
artifacts: # Re specify artifacts so the modified signed file is passed
122114
expire_in: 1 day # Signed layers should expire after 1 day
123115
paths:
124116
- .layers/datadog_lambda_node{{ $runtime.node_version }}.zip
125117
before_script:
126-
- apt-get update
127-
- apt-get install -y uuid-runtime
128-
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source ./ci/get_secrets.sh
118+
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
129119
script:
130120
- LAYER_FILE=datadog_lambda_node{{ $runtime.node_version }}.zip ./scripts/sign_layers.sh {{ $environment.name }}
131121
{{ end }}
132122

133-
publish-layer-{{ $environment.name }} ({{ $runtime.name }}):
123+
publish layer {{ $environment.name }} ({{ $runtime.name }}):
134124
stage: publish
135125
tags: ["arch:amd64"]
136-
image: registry.ddbuild.io/images/docker:20.10-py3
126+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
137127
rules:
138128
- if: '"{{ $environment.name }}" =~ /^(sandbox|staging)/'
139129
when: manual
140130
allow_failure: true
141131
- if: '$CI_COMMIT_TAG =~ /^v.*/'
142132
needs:
143133
{{ if or (eq $environment.name "prod") }}
144-
- sign-layer ({{ $runtime.name }})
134+
- sign layer ({{ $runtime.name }})
145135
{{ else }}
146-
- build-layer ({{ $runtime.name }})
147-
- check-layer-size ({{ $runtime.name }})
136+
- build layer ({{ $runtime.name }})
137+
- check layer size ({{ $runtime.name }})
148138
- lint ({{ $runtime.name }})
149-
- unit-test ({{ $runtime.name }})
150-
- integration-test ({{ $runtime.name }})
139+
- unit test ({{ $runtime.name }})
140+
- integration test ({{ $runtime.name }})
151141
{{ end }}
152142
dependencies:
153143
{{ if or (eq $environment.name "prod") }}
154-
- sign-layer ({{ $runtime.name }})
144+
- sign layer ({{ $runtime.name }})
155145
{{ else }}
156-
- build-layer ({{ $runtime.name }})
146+
- build layer ({{ $runtime.name }})
157147
{{ end }}
158148
parallel:
159149
matrix:
160150
- REGION: {{ range (ds "regions").regions }}
161151
- {{ .code }}
162152
{{- end}}
163153
before_script:
164-
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source ./ci/get_secrets.sh
154+
- EXTERNAL_ID_NAME={{ $environment.external_id }} ROLE_TO_ASSUME={{ $environment.role_to_assume }} AWS_ACCOUNT={{ $environment.account }} source .gitlab/scripts/get_secrets.sh
165155
script:
166-
- STAGE={{ $environment.name }} NODE_VERSION={{ $runtime.node_version }} ./ci/publish_layers.sh
156+
- STAGE={{ $environment.name }} NODE_VERSION={{ $runtime.node_version }} .gitlab/scripts/publish_layers.sh
167157

168158
{{- end }}
169159

170160
{{- end }}
171161

172-
publish-npm-package:
162+
publish npm package:
173163
stage: publish
174164
tags: ["arch:amd64"]
175-
image: registry.ddbuild.io/images/docker:20.10-py3
165+
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
176166
cache: []
177167
rules:
178168
- if: '$CI_COMMIT_TAG =~ /^v.*/'
179169
when: manual
180170
needs: {{ range $runtime := (ds "runtimes").runtimes }}
181-
- sign-layer ({{ $runtime.name }})
171+
- sign layer ({{ $runtime.name }})
182172
{{- end }}
183173
before_script:
184-
- *install-node
185174
- *node-before-script
186175
script:
187-
- ./ci/publish_npm.sh
176+
- .gitlab/scripts/publish_npm.sh
File renamed without changes.

ci/publish_layers.sh .gitlab/scripts/publish_layers.sh

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ NODE_VERSIONS=("16.14" "18.12" "20.9")
1717
STAGES=('prod', 'sandbox', 'staging')
1818

1919
printf "Starting script...\n\n"
20-
printf "Installing dependencies\n"
21-
pip install awscli
2220

2321
publish_layer() {
2422
region=$1
File renamed without changes.

ci/config.yaml

-13
This file was deleted.

0 commit comments

Comments
 (0)