Skip to content

Commit feeb4e4

Browse files
committed
Add CODEOWNERS
1 parent ec58a78 commit feeb4e4

File tree

12 files changed

+567
-0
lines changed

12 files changed

+567
-0
lines changed

.github/bug_report_template.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bug Report
3+
about: Create a report to help us improve
4+
---
5+
6+
## Expected Behavior
7+
8+
9+
## Actual Behavior
10+
11+
12+
## Steps to Reproduce the Problem
13+
14+
1.
15+
1.
16+
1.
17+
18+
## Specifications
19+
20+
- Datadog Lambda Layer version:
21+
- Python version:
22+
23+
## Stacktrace
24+
25+
```
26+
Paste here
27+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Feature Request
3+
about: Suggest an idea
4+
---
5+
6+
## Expected Behavior
7+
8+
9+
## Actual Behavior
10+
11+
12+
## Steps to Reproduce the Problem
13+
14+
1.
15+
1.
16+
1.
17+
18+
## Specifications
19+
20+
- Datadog Lambda Layer version:
21+
- Python version:
22+
23+
## Stacktrace
24+
25+
```
26+
Paste here
27+
```

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @DataDog/serverless

scripts/serverless/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM scratch
2+
COPY datadog-agent opt/extensions/datadog-agent
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 2020 Datadog, Inc.
7+
8+
# Copy layers from us-east-1 to new region
9+
# args: [new-region]
10+
11+
set -e
12+
13+
FROM_REGION='us-east-1'
14+
15+
LAYER_NAMES=("Datadog-Extension")
16+
17+
NEW_REGION=$1
18+
19+
get_max_version() {
20+
layer_name=$1
21+
region=$2
22+
last_layer_version=$(aws lambda list-layer-versions --layer-name $layer_name --region $region | jq -r ".LayerVersions | .[0] | .Version")
23+
if [ "$last_layer_version" == "null" ]; then
24+
echo 0
25+
else
26+
echo $last_layer_version
27+
fi
28+
}
29+
30+
if [ -z "$1" ]; then
31+
echo "Region parameter not specified, exiting"
32+
exit 1
33+
fi
34+
35+
for layer_name in "${LAYER_NAMES[@]}"; do
36+
# get latest version
37+
last_layer_version=$(get_max_version $layer_name $FROM_REGION)
38+
starting_version=$(get_max_version $layer_name $NEW_REGION)
39+
starting_version=$(expr $starting_version + 1)
40+
41+
# exit if region is already all caught up
42+
if [ $starting_version -ge $last_layer_version ]; then
43+
echo "INFO: $NEW_REGION is already up to date for $layer_name"
44+
continue
45+
fi
46+
47+
# run for each version of layer
48+
for i in $(seq 1 $last_layer_version); do
49+
layer_path=$layer_name"_"$i.zip
50+
51+
# download layer versions
52+
URL=$(AWS_REGION=$FROM_REGION aws lambda get-layer-version --layer-name $layer_name --version-number $i --query Content.Location --output text)
53+
curl $URL -o $layer_path
54+
55+
# publish layer to new region
56+
./publish_layer
57+
58+
publish_layer $NEW_REGION
59+
rm $layer_path
60+
done
61+
done
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
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 2020 Datadog, Inc.
7+
8+
# Builds Datadogpy layers for lambda functions, using Docker
9+
set -e
10+
11+
# Move into the root directory, so this script can be called from any directory
12+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
13+
cd $DIR/..
14+
15+
LAYER_DIR=".layers"
16+
LAYER_FILE="datadog_extension"
17+
EXTENSION_DIR="extensions"
18+
TMP_DIR='./var/task'
19+
20+
rm -rf $LAYER_DIR
21+
rm -rf $EXTENSION_DIR
22+
rm -rf $TMP_DIR
23+
mkdir $LAYER_DIR
24+
mkdir $EXTENSION_DIR
25+
mkdir -p $TMP_DIR
26+
27+
TARGET_DIR=$(pwd)/$EXTENSION_DIR
28+
29+
echo "Building Lambda extension binary"
30+
cd ~/dd/datadog-agent/cmd/serverless
31+
GOOS=linux go build -ldflags="-s -w" -tags serverless -o $TARGET_DIR/datadog-agent
32+
if [ "$COMPRESS" = true ]; then
33+
upx --brute $TARGET_DIR/datadog-agent
34+
fi
35+
36+
cd -
37+
rm -rf "./var"
38+
39+
echo "Building Lambda layer"
40+
zip -q -r "${LAYER_DIR}/${LAYER_FILE}" -r $EXTENSION_DIR
41+
42+
echo "Done!"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Use with `VERSION=<DESIRED_VERSION> ./build_docker_image.sh`
4+
5+
# Unless explicitly stated otherwise all files in this repository are licensed
6+
# under the Apache License Version 2.0.
7+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
8+
# Copyright 2020 Datadog, Inc.
9+
10+
set -e
11+
12+
DOCKER_REPOSITORY_NAME="datadog/lambda-extension"
13+
DOCKERFILE_LOCATION="build-scripts/serverless/Dockerfile"
14+
15+
# Move into the root directory, so this script can be called from any directory
16+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
17+
cd $DIR/..
18+
19+
if [ -z "$VERSION" ]; then
20+
echo "Version not specified"
21+
echo ""
22+
echo "EXITING SCRIPT."
23+
exit 1
24+
fi
25+
26+
# Build the image, tagged with the version
27+
echo "Building the Docker image"
28+
docker build extensions \
29+
-f $DOCKERFILE_LOCATION \
30+
-t $DOCKER_REPOSITORY_NAME:$VERSION \
31+
--no-cache
32+
33+
# Also tag the image with :latest
34+
docker tag $DOCKER_REPOSITORY_NAME:$VERSION $DOCKER_REPOSITORY_NAME:latest

scripts/serverless/list_layers.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 2020 Datadog, Inc.
7+
8+
# Lists most recent layers ARNs across regions to STDOUT
9+
# Optionals args: [layer-name] [region]
10+
11+
set -e
12+
13+
LAYERS=("Datadog-Extension")
14+
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
15+
LAYERS_MISSING_REGIONS=()
16+
17+
# Check region arg
18+
if [ -z "$2" ]; then
19+
>&2 echo "Region parameter not specified, running for all available regions."
20+
REGIONS=$AVAILABLE_REGIONS
21+
else
22+
23+
>&2 echo "Region parameter specified: $2"
24+
if [[ ! "$AVAILABLE_REGIONS" == *"$2"* ]]; then
25+
>&2 echo "Could not find $2 in available regions:" $AVAILABLE_REGIONS
26+
>&2 echo ""
27+
>&2 echo "EXITING SCRIPT."
28+
exit 1
29+
fi
30+
REGIONS=($2)
31+
fi
32+
33+
for region in $REGIONS
34+
do
35+
for layer_name in "${LAYERS[@]}"
36+
do
37+
last_layer_arn=$(aws lambda list-layer-versions --layer-name $layer_name --region $region | jq -r ".LayerVersions | .[0] | .LayerVersionArn")
38+
if [ "$last_layer_arn" == "null" ]; then
39+
>&2 echo "No layer found for $region, $layer_name"
40+
if [[ ! " ${LAYERS_MISSING_REGIONS[@]} " =~ " ${region} " ]]; then
41+
LAYERS_MISSING_REGIONS+=( $region )
42+
fi
43+
else
44+
echo $last_layer_arn
45+
fi
46+
done
47+
done
48+
49+
if [ ${#LAYERS_MISSING_REGIONS[@]} -gt 0 ]; then
50+
echo "WARNING: Following regions missing layers: ${LAYERS_MISSING_REGIONS[@]}"
51+
echo "Please run ./add_new_region.sh <new_region> to add layers to the missing regions"
52+
exit 1
53+
fi
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 2020 Datadog, Inc.
7+
8+
# Publish the datadog lambda layer across regions, using the AWS CLI
9+
# Usage: VERSION=5 REGIONS=us-east-1 publish_layers.sh
10+
# VERSION is required.
11+
set -e
12+
13+
# Move into the root directory, so this script can be called from any directory
14+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
15+
cd $DIR/..
16+
17+
LAYER_PATH=".layers/datadog_extension.zip"
18+
LAYER_NAME="Datadog-Extension"
19+
AVAILABLE_REGIONS=$(aws ec2 describe-regions | jq -r '.[] | .[] | .RegionName')
20+
21+
# Check that the layer files exist
22+
if [ ! -f $LAYER_PATH ]; then
23+
echo "Could not find $LAYER_PATH."
24+
exit 1
25+
fi
26+
27+
# Determine the target regions
28+
if [ -z "$REGIONS" ]; then
29+
echo "Region not specified, running for all available regions."
30+
REGIONS=$AVAILABLE_REGIONS
31+
else
32+
echo "Region specified: $REGIONS"
33+
if [[ ! "$AVAILABLE_REGIONS" == *"$REGIONS"* ]]; then
34+
echo "Could not find $REGIONS in available regions: $AVAILABLE_REGIONS"
35+
echo ""
36+
echo "EXITING SCRIPT."
37+
exit 1
38+
fi
39+
fi
40+
41+
# Determine the target layer version
42+
if [ -z "$VERSION" ]; then
43+
echo "Layer version not specified"
44+
echo ""
45+
echo "EXITING SCRIPT."
46+
exit 1
47+
else
48+
echo "Layer version specified: $VERSION"
49+
fi
50+
51+
read -p "Ready to publish layer $LAYER_NAME version $VERSION to regions ${REGIONS[*]} (y/n)?" CONT
52+
if [ "$CONT" != "y" ]; then
53+
echo "Exiting"
54+
exit 1
55+
fi
56+
57+
publish_layer() {
58+
region=$1
59+
version_nbr=$(aws lambda publish-layer-version --layer-name $LAYER_NAME \
60+
--description "Datadog Lambda Extension" \
61+
--zip-file "fileb://$LAYER_PATH" \
62+
--region $region | jq -r '.Version')
63+
64+
permission=$(aws lambda add-layer-version-permission --layer-name $LAYER_NAME \
65+
--version-number $version_nbr \
66+
--statement-id "release-$version_nbr" \
67+
--action lambda:GetLayerVersion --principal "*" \
68+
--region $region)
69+
70+
echo $version_nbr
71+
}
72+
73+
for region in $REGIONS
74+
do
75+
echo "Starting publishing layer for region $region..."
76+
77+
latest_version=$(aws lambda list-layer-versions --region $region --layer-name $LAYER_NAME --query 'LayerVersions[0].Version || `0`')
78+
if [ $latest_version -ge $VERSION ]; then
79+
echo "Layer $LAYER_NAME version $VERSION already exists in region $region, skipping..."
80+
continue
81+
elif [ $latest_version -lt $((VERSION-1)) ]; then
82+
read -p "WARNING: The latest version of layer $LAYER_NAME in region $region is $latest_version, publish all the missing versions including $VERSION or EXIT the script (y/n)?" CONT
83+
if [ "$CONT" != "y" ]; then
84+
echo "Exiting"
85+
exit 1
86+
fi
87+
fi
88+
89+
while [ $latest_version -lt $VERSION ]; do
90+
latest_version=$(publish_layer $region)
91+
echo "Published version $latest_version for layer $LAYER_NAME in region $region"
92+
93+
# This shouldn't happen unless someone manually deleted the latest version, say 28, and
94+
# then tries to republish 28 again. The published version would actually be 29, because
95+
# Lambda layers are immutable and AWS will skip deleted version and use the next number.
96+
if [ $latest_version -gt $VERSION ]; then
97+
echo "ERROR: Published version $latest_version is greater than the desired version $VERSION!"
98+
echo "Exiting"
99+
exit 1
100+
fi
101+
done
102+
done
103+
104+
echo "Done !"

0 commit comments

Comments
 (0)