Skip to content

Commit a1275d5

Browse files
authored
chore: Automate Releases (#295)
* update image registry * remove `prepare_multi_region` jobs i will use pipeline generation later * refactor pipeline to comply with newer standards * update `build_bottlecap_layer.sh` to stop using `docker` commands, since it will not work on Gitlab * first iteration * add path to build repo image and build in container * update image to build * update `.gitlab-ci.yml` * update `.gitlab/Dockerfile * change layer builder tag * forgot `buildx` * update `.gitlab/Dockerfile` * make `cargo` available * make `cargo` available again * `cd bottlecap` * in `Dockerfile` install `gcc, make, openssl, ...` * update how `c++` is installed * remove installing `openssl-devel` * make `cargo` available * install protobuf in `.gitlab/Dockerfile` * update `.gitlab/Dockerfile` * typo * update arch on `check` job trying to see if its an architecture problem * make `protoc` available * make most jobs to run on `amd64` * use script to install `protoc` also updated a job back to `arm64` to test if it works with any arch * dont specify platform for nightly * make pipeline dynamic * update layer size numbers zipped should be around 15, while unzipped is around 43 w bottlecap * update layer size numbers also added `get_secrets.sh` script * add `regions.yaml` also added `architectures.yaml` * update `.gitlab/Dockerfile` for a dependency * allow build for `go agent` also modified the whole structure so we can run multiple pipelines if needed * pass any path starting with `pipeline-` * specify paths for pipelines * set to include artifact for `go-agent` * typo on pipeline to use * try different cloning strategy * typo on scrip to use to build * fix script to copy stuff from `datadog-agent` * typo * update where the get secrets script comes from * add `sign_layers.sh` * allow signing layers for both environments * abstract scripts to use `LAYER_FILE` for size check and signing * add `awscli` to `Dockerfile` * update templates to use publishing script properly * revert image to be built always * update go template for signing only in prod * allow suffix to be used when publishing * move when we add suffix we were checking the wrong version number for sandbox * eol * allow a new pipeline for combined go+rust extension * add pipeline in `.gitlab.yml` * update `go-agent.yaml.tpl` added arch as variable * make bottlecap dev use another dockerfile * update `build_go_agent.sh` mainly to unzip before removingthe zip * build bottlecap for gitlab * add extension with bottlecap pipeline * typo in `config.yaml` * clone `datadog-agent` before building the go agent facepalm * see if agent branch is defaulted to main * its not printing, try again * disallow specific runtime pipelines to publish to prod * `lambda-extension` to only be triggered through web * fix how version is set for `build_go_agent.sh` * maybe copy isnt finding the right file? * debug ls * forgot to add path to directory including the binaries * update layer size * remove all regions but `sa-east-1` temporarily * increase layer size again * add all regions back * only add permissions on prod
1 parent bf41656 commit a1275d5

19 files changed

+1067
-123
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ local_tests/serverless-init/datadog-agent
2424
local_tests/serverless-init/logs.txt
2525
bottlecap/target
2626
bottlecap/proptest-regressions
27+
28+
.gitlab/pipeline-**

.gitlab-ci.yml

Lines changed: 61 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,82 @@
11
variables:
2-
GIT_DEPTH: 1
3-
REGION_TO_DEPLOY:
4-
description: "use sa-east-1 for dev, us-east-1 for RC, all for all regions"
5-
value: sa-east-1
2+
DOCKER_TARGET_IMAGE: registry.ddbuild.io/ci/datadog-lambda-extension
3+
DOCKER_TARGET_VERSION: latest
4+
# Manual trigger variables
65
AGENT_BRANCH:
7-
description: "datadog-agent branch you want to release"
6+
description: "Branch of the datadog-agent repository to use."
87
value: main
98
LAYER_SUFFIX:
10-
description: "Suffix to be appended to the layer name (default empty)"
9+
description: "Suffix to be appended to the layer name (default empty)."
1110
value: ""
1211

13-
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:20.10-py3
14-
1512
stages:
16-
- build_tools_if_needed
17-
- build_layer
18-
- prepare_multi_region
19-
- trigger
13+
- generate
14+
- build
2015

21-
build_tools:
22-
stage: build_tools_if_needed
23-
variables:
24-
CI_ENABLE_CONTAINER_IMAGE_BUILDS: "true"
25-
TARGET: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-lambda-extension
16+
ci image:
17+
stage: build
18+
image: registry.ddbuild.io/images/docker:20.10
19+
tags: ["arch:arm64"]
2620
rules:
27-
- if: $CI_PIPELINE_SOURCE == "web"
28-
when: never
29-
- changes:
30-
- build-tools/**/*
31-
tags: ["runner:docker"]
32-
script:
33-
- cd build-tools && docker buildx build --tag ${TARGET} --push .
34-
35-
build_and_deploy_layer:
36-
stage: build_layer
37-
rules:
38-
- if: $CI_PIPELINE_SOURCE == "web"
21+
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"'
22+
changes:
23+
- .gitlab/Dockerfile
24+
when: on_success
3925
variables:
40-
CI_ENABLE_CONTAINER_IMAGE_BUILDS: "true"
41-
ROLE_TO_ASSUME: arn:aws:iam::425362996713:role/sandbox-layer-deployer
42-
TARGET: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-lambda-extension
43-
tags: ["runner:docker"]
44-
artifacts:
45-
paths:
46-
- tmp/serverless/datadog_extension_signed.zip
26+
DOCKER_TARGET: ${DOCKER_TARGET_IMAGE}:${DOCKER_TARGET_VERSION}
4727
script:
48-
- mkdir tmp
49-
- git clone --branch ${AGENT_BRANCH} --depth=1 https://github.com/DataDog/datadog-agent.git
50-
- dockerId=$(docker create --platform linux/amd64 ${TARGET})
51-
- docker cp $dockerId:/build_tools .
52-
- EXTERNAL_ID=$(aws ssm get-parameter
53-
--region us-east-1
54-
--name ci.datadog-lambda-extension.externalid
55-
--with-decryption
56-
--query "Parameter.Value"
57-
--out text)
58-
59-
# build
60-
- ./build_tools
61-
build
62-
--version 1
63-
--agent-version 1
64-
--architecture amd64
65-
--context-path .
66-
--destination-path tmp/serverless
67-
--docker-path "scripts_v2/Dockerfile.build"
68-
--artifact-name "datadog_extension.zip"
28+
- docker buildx build --platform linux/amd64,linux/arm64 --no-cache --pull --push --tag ${DOCKER_TARGET} -f .gitlab/Dockerfile .
6929

70-
# sign
71-
- ./build_tools
72-
sign
73-
--layer-path tmp/serverless/datadog_extension.zip
74-
--destination-path tmp/serverless/datadog_extension_signed.zip
75-
--assume-role "$ROLE_TO_ASSUME"
76-
--external-id "$EXTERNAL_ID"
30+
.go-cache: &go-cache
31+
key: datadog-lambda-extension-go-cache
32+
policy: pull
7733

78-
# ls artifacts
79-
- ls tmp/serverless
80-
81-
# deploy to single region if needed
82-
- if [ "${REGION_TO_DEPLOY}" = "all" ]; then exit 0; fi
83-
- ./build_tools
84-
deploy
85-
--layer-path tmp/serverless/datadog_extension_signed.zip
86-
--architecture amd64
87-
--layer-name "Datadog-Extension"
88-
--layer-suffix "$LAYER_SUFFIX"
89-
--region "$REGION_TO_DEPLOY"
90-
--assume-role "$ROLE_TO_ASSUME"
91-
--external-id "$EXTERNAL_ID"
92-
93-
prepare_multi_region:
94-
stage: prepare_multi_region
95-
tags: ["runner:docker"]
34+
generator:
35+
stage: generate
36+
image: registry.ddbuild.io/images/mirror/golang:alpine
37+
tags: ["arch:amd64"]
38+
cache: *go-cache
39+
script:
40+
- apk add --no-cache gomplate
41+
- gomplate --config .gitlab/config.yaml
9642
artifacts:
9743
paths:
98-
- trigger_region.yaml
99-
- tmp/serverless/datadog_extension_signed.zip
44+
- .gitlab/pipeline-bottlecap.yaml
45+
- .gitlab/pipeline-go-agent.yaml
46+
- .gitlab/pipeline-lambda-extension.yaml
47+
48+
bottlecap-only:
49+
stage: build
50+
trigger:
51+
include:
52+
- artifact: .gitlab/pipeline-bottlecap.yaml
53+
job: generator
54+
strategy: depend
55+
rules:
56+
- when: on_success
57+
58+
go-agent-only:
59+
stage: build
60+
trigger:
61+
include:
62+
- artifact: .gitlab/pipeline-go-agent.yaml
63+
job: generator
64+
strategy: depend
10065
rules:
101-
- if: $REGION_TO_DEPLOY != "all"
102-
when: never
10366
- if: $CI_PIPELINE_SOURCE == "web"
104-
- if: $CI_PIPELINE_SOURCE == "external"
105-
- if: $CI_PIPELINE_SOURCE == "trigger"
106-
- if: $CI_PIPELINE_SOURCE == "pipeline"
107-
- if: $CI_PIPELINE_SOURCE == "parent_pipeline"
10867
variables:
109-
TARGET: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-lambda-extension
110-
ROLE_TO_ASSUME: arn:aws:iam::425362996713:role/sandbox-layer-deployer
111-
script:
112-
- echo $CI_PIPELINE_SOURCE
113-
- if [ "${REGION_TO_DEPLOY}" != "all" ]; then exit 0; fi
114-
- EXTERNAL_ID=$(aws ssm get-parameter
115-
--region us-east-1
116-
--name ci.datadog-lambda-extension.externalid
117-
--with-decryption
118-
--query "Parameter.Value"
119-
--out text)
120-
- dockerId=$(docker create --platform linux/amd64 ${TARGET})
121-
- docker cp $dockerId:/build_tools .
122-
- regions=$(./build_tools list_region --assume-role "$ROLE_TO_ASSUME" --external-id "$EXTERNAL_ID")
123-
- sed "s/xxx_layer_sufix_xxx/${LAYER_SUFFIX}/" trigger_region.orig.yaml > trigger_region.tmp.yaml
124-
- sed "s/xxx_aws_regions_xxx/${regions}/" trigger_region.tmp.yaml > trigger_region.yaml
125-
- cat trigger_region.yaml
68+
AGENT_BRANCH: $AGENT_BRANCH
69+
LAYER_SUFFIX: $LAYER_SUFFIX
12670

127-
multi_region:
128-
rules:
129-
- if: $REGION_TO_DEPLOY == "all"
130-
stage: trigger
71+
lambda-extension:
72+
stage: build
13173
trigger:
13274
include:
133-
- artifact: trigger_region.yaml
134-
job: prepare_multi_region
75+
- artifact: .gitlab/pipeline-lambda-extension.yaml
76+
job: generator
77+
strategy: depend
78+
rules:
79+
- if: $CI_PIPELINE_SOURCE == "web"
80+
variables:
81+
AGENT_BRANCH: $AGENT_BRANCH
82+
LAYER_SUFFIX: $LAYER_SUFFIX

.gitlab/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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
5+
6+
# Install AWS CLI
7+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
8+
RUN unzip awscliv2.zip && ./aws/install
9+
10+
# Install Protocol Buffers compiler by hand
11+
COPY ./scripts/install-protoc.sh /
12+
RUN chmod +x /install-protoc.sh && /install-protoc.sh
13+
14+
# Install Rust
15+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
16+
sh -s -- --profile minimal --default-toolchain nightly -y
17+
18+
RUN source $HOME/.cargo/env
19+
ENV PATH /root/.cargo/bin/:$PATH
20+
21+
RUN rustup component add rust-src --toolchain nightly
22+
23+

.gitlab/config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# gomplate template generation pipeline
2+
3+
inputFiles:
4+
- .gitlab/templates/bottlecap.yaml.tpl
5+
- .gitlab/templates/go-agent.yaml.tpl
6+
- .gitlab/templates/lambda-extension.yaml.tpl
7+
8+
outputFiles:
9+
- .gitlab/pipeline-bottlecap.yaml
10+
- .gitlab/pipeline-go-agent.yaml
11+
- .gitlab/pipeline-lambda-extension.yaml
12+
13+
datasources:
14+
architectures:
15+
url: .gitlab/datasources/architectures.yaml
16+
17+
environments:
18+
url: .gitlab/datasources/environments.yaml
19+
20+
regions:
21+
url: .gitlab/datasources/regions.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
architectures:
2+
- name: amd64
3+
- name: arm64
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
environments:
2+
- name: sandbox
3+
external_id: sandbox-publish-externalid
4+
role_to_assume: sandbox-layer-deployer
5+
account: 425362996713
6+
- name: prod
7+
external_id: prod-publish-externalid
8+
role_to_assume: dd-serverless-layer-deployer-role
9+
account: 464622532012

.gitlab/datasources/regions.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
regions:
2+
- code: "us-east-1"
3+
- code: "us-east-2"
4+
- code: "us-west-1"
5+
- code: "us-west-2"
6+
- code: "af-south-1"
7+
- code: "ap-east-1"
8+
- code: "ap-south-1"
9+
- code: "ap-south-2"
10+
- code: "ap-southeast-1"
11+
- code: "ap-southeast-2"
12+
- code: "ap-southeast-3"
13+
- code: "ap-southeast-4"
14+
- code: "ap-northeast-1"
15+
- code: "ap-northeast-2"
16+
- code: "ap-northeast-3"
17+
- code: "ca-central-1"
18+
- code: "ca-west-1"
19+
- code: "eu-central-1"
20+
- code: "eu-central-2"
21+
- code: "eu-north-1"
22+
- code: "eu-west-1"
23+
- code: "eu-west-2"
24+
- code: "eu-west-3"
25+
- code: "eu-south-1"
26+
- code: "eu-south-2"
27+
- code: "il-central-1"
28+
- code: "me-south-1"
29+
- code: "me-central-1"
30+
- code: "sa-east-1"

.gitlab/scripts/build_bottlecap.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# Unless explicitly stated otherwise all files in this repository are licensed
4+
# under the Apache License Version 2.0.
5+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
6+
# Copyright 2024 Datadog, Inc.
7+
8+
set -e
9+
10+
if [ -z "$ARCHITECTURE" ]; then
11+
printf "[ERROR]: ARCHITECTURE not specified\n"
12+
exit 1
13+
fi
14+
15+
if [ -z "$ALPINE" ]; then
16+
printf "Building bottlecap"
17+
else
18+
echo "Building bottlecap for alpine"
19+
BUILD_SUFFIX="-alpine"
20+
fi
21+
22+
prepare_folders() {
23+
# Move into the root directory, so this script can be called from any directory
24+
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
25+
ROOT_DIR=$SCRIPTS_DIR/../..
26+
cd $ROOT_DIR
27+
28+
echo $ROOT_DIR
29+
30+
EXTENSION_DIR=".layers"
31+
TARGET_DIR=$(pwd)/$EXTENSION_DIR
32+
33+
rm -rf $EXTENSION_DIR/datadog_bottlecap-${ARCHITECTURE}${BUILD_SUFFIX} 2>/dev/null
34+
rm -rf $EXTENSION_DIR/datadog_bottlecap-${ARCHITECTURE}${BUILD_SUFFIX}.zip 2>/dev/null
35+
36+
cd $ROOT_DIR
37+
}
38+
39+
40+
docker_build() {
41+
local arch=$1
42+
if [ "$arch" == "amd64" ]; then
43+
PLATFORM="x86_64"
44+
else
45+
PLATFORM="aarch64"
46+
fi
47+
48+
docker buildx build --platform linux/${arch} \
49+
-t datadog/build-bottlecap-${arch} \
50+
-f ./scripts/Dockerfile.bottlecap.build \
51+
--build-arg PLATFORM=$PLATFORM \
52+
--build-arg GO_AGENT_PATH="datadog_extension-${arch}${BUILD_SUFFIX}" \
53+
. -o $TARGET_DIR/datadog_bottlecap-${arch}${BUILD_SUFFIX}
54+
55+
cp $TARGET_DIR/datadog_bottlecap-${arch}${BUILD_SUFFIX}/datadog_extension.zip $TARGET_DIR/datadog_bottlecap-${arch}${BUILD_SUFFIX}.zip
56+
57+
unzip $TARGET_DIR/datadog_bottlecap-${arch}${BUILD_SUFFIX}/datadog_extension.zip -d $TARGET_DIR/datadog_bottlecap-${arch}${BUILD_SUFFIX}
58+
rm -rf $TARGET_DIR/datadog_bottlecap-${arch}${BUILD_SUFFIX}/datadog_extension.zip
59+
rm -rf $TARGET_DIR/datadog_extension-${arch}${BUILD_SUFFIX}
60+
rm -rf $TARGET_DIR/datadog_extension-${arch}${BUILD_SUFFIX}.zip
61+
}
62+
63+
prepare_folders
64+
docker_build $ARCHITECTURE

0 commit comments

Comments
 (0)