forked from DataDog/datadog-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
265 lines (246 loc) · 10.5 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
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
image: registry.ddbuild.io/images/mirror/golang:1.18.6-bullseye
variables:
GO111MODULE: "on"
PROJECTNAME: "datadog-operator"
PROJECTNAME_CHECK: "datadog-operator-check"
GOPATH: "$CI_PROJECT_DIR/.cache"
BUILD_DOCKER_REGISTRY: "486234852809.dkr.ecr.us-east-1.amazonaws.com/ci"
JOB_DOCKER_IMAGE: "486234852809.dkr.ecr.us-east-1.amazonaws.com/ci-containers-project:v13932656-a1b1db4-v1.0.0"
DOCKER_REGISTRY_LOGIN_SSM_KEY: docker_hub_login
DOCKER_REGISTRY_PWD_SSM_KEY: docker_hub_pwd
DOCKER_REGISTRY_URL: docker.io
RH_PARTNER_SCAN_OPERATOR_TOKEN_SSM_KEY: redhat_operator_token
RH_PARTNER_SCAN_REGISTRY: scan.connect.redhat.com
RH_PARTNER_API_KEY_SSM_KEY: redhat_api_key
cache: &global_cache
key: ${CI_COMMIT_REF_SLUG}
paths:
- .cache
policy: pull-push
stages:
- build
- test
- image
- test-image
- release
- post-release
build:
stage: build
tags: ["runner:main", "size:large"]
before_script:
- mkdir -p .cache
- make install-tools
script:
- make build
unit_tests:
stage: test
tags: ["runner:main", "size:large"]
before_script:
- mkdir -p .cache
- make install-tools
script:
- make test
generate_code:
stage: test
tags: ["runner:main", "size:large"]
before_script:
- mkdir -p .cache
- make install-tools
script:
- make generate manifests
- git diff --exit-code
build_operator_image_amd64:
stage: image
tags: ["runner:docker", "size:large"]
image: $JOB_DOCKER_IMAGE
variables:
GOARCH: amd64
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-amd64
RELEASE_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-amd64
script:
# DockerHub login for build to limit rate limit when pulling base images
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin "$DOCKER_REGISTRY_URL"
- IMG=$TARGET_IMAGE make docker-build-ci docker-push-ci
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi
build_operator_image_arm64:
stage: image
tags: ["runner:docker-arm", "platform:arm64"]
image: $JOB_DOCKER_IMAGE
variables:
GOARCH: arm64
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-arm64
RELEASE_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-arm64
script:
# DockerHub login for build to limit rate limit when pulling base images
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin "$DOCKER_REGISTRY_URL"
- IMG=$TARGET_IMAGE make docker-build-ci docker-push-ci
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi
build_operator_check_image_amd64:
stage: image
tags: ["runner:docker", "size:large"]
image: $JOB_DOCKER_IMAGE
variables:
GOARCH: amd64
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME_CHECK:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-amd64
RELEASE_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME_CHECK:$CI_COMMIT_TAG-amd64
script:
# DockerHub login for build to limit rate limit when pulling base images
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin "$DOCKER_REGISTRY_URL"
- IMG_CHECK=$TARGET_IMAGE make docker-build-check-ci docker-push-check-ci
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi
build_operator_check_image_arm64:
stage: image
tags: ["runner:docker-arm", "platform:arm64"]
image: $JOB_DOCKER_IMAGE
variables:
GOARCH: arm64
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME_CHECK:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-arm64
RELEASE_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME_CHECK:$CI_COMMIT_TAG-arm64
script:
# DockerHub login for build to limit rate limit when pulling base images
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin "$DOCKER_REGISTRY_URL"
- IMG_CHECK=$TARGET_IMAGE make docker-build-check-ci docker-push-check-ci
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi
build_bundle_image:
stage: image
tags: ["runner:docker", "size:large"]
image: $JOB_DOCKER_IMAGE
variables:
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-bundle
RELEASE_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-bundle
script:
- BUNDLE_IMG=$TARGET_IMAGE make bundle-build
- if [ -n "$CI_COMMIT_TAG" ]; then docker tag $TARGET_IMAGE $RELEASE_IMAGE && docker push $RELEASE_IMAGE; fi
preflight_redhat_image_amd64:
stage: test-image
rules:
- if: $CI_COMMIT_TAG
when: on_success
- when: never
tags: ["runner:docker", "size:large"]
image: $JOB_DOCKER_IMAGE
variables:
TARGET_IMAGE: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-amd64
script:
- apt-get update && apt-get -y install --no-install-recommends build-essential git awscli && apt-get -y clean && rm -rf /var/lib/apt/lists/*
- DOCKER_REGISTRY_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_LOGIN_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$DOCKER_REGISTRY_PWD_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "$DOCKER_REGISTRY_LOGIN" --password-stdin "$DOCKER_REGISTRY_URL"
- IMG=$TARGET_IMAGE make preflight-redhat-container
publish_public_main:
stage: release
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: on_success
- when: never
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-amd64,$BUILD_DOCKER_REGISTRY/$PROJECTNAME:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}-arm64
IMG_DESTINATIONS: operator:main
IMG_SIGNING: "false"
publish_public_tag:
stage: release
rules:
- if: $CI_COMMIT_TAG
when: manual
- when: never
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-amd64,$BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-arm64
IMG_DESTINATIONS: operator:$CI_COMMIT_TAG
IMG_DESTINATIONS_REGEX: ':v'
IMG_DESTINATIONS_REGEX_REPL: ':'
IMG_SIGNING: "false"
# RedHat does not support multi-arch images
publish_redhat_public_tag:
stage: release
rules:
- if: $CI_COMMIT_TAG
when: manual
- when: never
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-amd64
IMG_DESTINATIONS: operator:$CI_COMMIT_TAG
IMG_DESTINATIONS_REGEX: ':v'
IMG_DESTINATIONS_REGEX_REPL: ':'
IMG_REGISTRIES: redhat-operator
publish_public_latest:
stage: release
rules:
- if: $CI_COMMIT_TAG
when: manual
- when: never
trigger:
project: DataDog/public-images
branch: main
strategy: depend
variables:
IMG_SOURCES: $BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-amd64,$BUILD_DOCKER_REGISTRY/$PROJECTNAME:$CI_COMMIT_TAG-arm64
IMG_DESTINATIONS: operator:latest
IMG_SIGNING: "false"
trigger_internal_operator_image:
stage: release
rules:
- if: $CI_COMMIT_TAG
- when: never
trigger:
project: DataDog/images
branch: master
strategy: depend
variables:
IMAGE_VERSION: tmpl-v1
IMAGE_NAME: datadog-operator
RELEASE_TAG: ${CI_COMMIT_REF_SLUG}
BUILD_TAG: ${CI_COMMIT_REF_SLUG}
TMPL_SRC_IMAGE: v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}
RELEASE_STAGING: "true"
RELEASE_PROD: "true"
trigger_internal_operator_check_image:
stage: release
rules:
- if: $CI_COMMIT_TAG
- when: never
trigger:
project: DataDog/images
branch: master
strategy: depend
variables:
IMAGE_VERSION: tmpl-v1
IMAGE_NAME: $PROJECTNAME_CHECK
RELEASE_TAG: ${CI_COMMIT_REF_SLUG}
BUILD_TAG: ${CI_COMMIT_REF_SLUG}
TMPL_SRC_IMAGE: v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA}
RELEASE_STAGING: "true"
RELEASE_PROD: "true"
submit_preflight_redhat_public_tag:
stage: post-release
rules:
- if: $CI_COMMIT_TAG
when: manual
- when: never
needs:
- "publish_redhat_public_tag"
tags: ["runner:docker", "size:large"]
image: $JOB_DOCKER_IMAGE
variables:
RH_PARTNER_PROJECT_ID: 5e7c8ebc1c86a3163d1a69be
RH_PARTNER_SCAN_REGISTRY_PATH: /ospid-e18c96b6-0524-4c5c-8ada-ce2fca845c8c/operator
script:
- apt-get update && apt-get -y install --no-install-recommends build-essential git awscli && apt-get -y clean && rm -rf /var/lib/apt/lists/*
- aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$RH_PARTNER_SCAN_OPERATOR_TOKEN_SSM_KEY --with-decryption --query "Parameter.Value" --out text | docker login --username "unused" --password-stdin "$RH_PARTNER_SCAN_REGISTRY"
- RH_PARTNER_API_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.datadog-operator.$RH_PARTNER_API_KEY_SSM_KEY --with-decryption --query "Parameter.Value" --out text)
- IMG=${RH_PARTNER_SCAN_REGISTRY}/${RH_PARTNER_SCAN_REGISTRY_PATH}:${CI_COMMIT_TAG:1}
- make preflight-redhat-container-submit