From f79937ed429f14c5029e834dab36caf0e927d487 Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Wed, 31 Mar 2021 10:07:59 -0400 Subject: [PATCH 1/4] Add PR size checking script --- .github/workflows/check-size.yml | 28 +++++++++++++++++++++++ scripts/check_layer_size.sh | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/workflows/check-size.yml create mode 100755 scripts/check_layer_size.sh diff --git a/.github/workflows/check-size.yml b/.github/workflows/check-size.yml new file mode 100644 index 00000000..2ce7e816 --- /dev/null +++ b/.github/workflows/check-size.yml @@ -0,0 +1,28 @@ +name: check-size + +on: pull_request + +jobs: + check-size: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Install dependencies + run: | + pip install virtualenv + virtualenv venv + source venv/bin/activate + pip install .[dev] + + - name: Build Layers + run: ./scripts/build_layers.sh + + - name: Check Size + run: ./scripts/check_layer_size.sh diff --git a/scripts/check_layer_size.sh b/scripts/check_layer_size.sh new file mode 100755 index 00000000..175ebce8 --- /dev/null +++ b/scripts/check_layer_size.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Unless explicitly stated otherwise all files in this repository are licensed +# under the Apache License Version 2.0. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019 Datadog, Inc. + +# Compares layer size to threshold, and fails if below that threshold + +# 5 mb size limit +MAX_LAYER_COMPRESSED_SIZE_KB=$(expr 5 \* 1024) +MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 15 \* 1024) + + +LAYER_FILES_PREFIX="datadog_lambda_py" +LAYER_DIR=".layers" +VERSIONS=("2.7" "3.6" "3.7" "3.8") + +for node_version in "${VERSIONS[@]}" +do + FILE=$LAYER_DIR/${LAYER_FILES_PREFIX}${node_version}.zip + FILE_SIZE=$(stat --printf="%s" $FILE) + FILE_SIZE_KB="$(( ${FILE_SIZE%% *} / 1024))" + echo "Layer file ${FILE} has zipped size ${FILE_SIZE_KB} kb" + if [ "$FILE_SIZE_KB" -gt "$MAX_LAYER_COMPRESSED_SIZE_KB" ]; then + echo "Zipped size exceeded limit $MAX_LAYER_COMPRESSED_SIZE_KB kb" + exit 1 + fi + mkdir tmp + unzip -q $FILE -d tmp + UNZIPPED_FILE_SIZE=$(du -shb tmp/ | cut -f1) + UNZIPPED_FILE_SIZE_KB="$(( ${UNZIPPED_FILE_SIZE%% *} / 1024))" + rm -rf tmp + echo "Layer file ${FILE} has unzipped size ${UNZIPPED_FILE_SIZE_KB} kb" + if [ "$UNZIPPED_FILE_SIZE_KB" -gt "$MAX_LAYER_UNCOMPRESSED_SIZE_KB" ]; then + echo "Unzipped size exceeded limit $MAX_LAYER_UNCOMPRESSED_SIZE_KB kb" + exit 1 + fi +done \ No newline at end of file From 6e71c993e7fd2a132778dc354679b6d8c213f9f8 Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Wed, 31 Mar 2021 13:41:35 -0400 Subject: [PATCH 2/4] Use /bin/bash for build_layers script --- scripts/build_layers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 83d44c39..0c4f80d9 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Unless explicitly stated otherwise all files in this repository are licensed # under the Apache License Version 2.0. From 46b607ced225ae7677114f54beeb38eae088cca0 Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Wed, 31 Mar 2021 13:48:46 -0400 Subject: [PATCH 3/4] Bump miminum layer size --- scripts/check_layer_size.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_layer_size.sh b/scripts/check_layer_size.sh index 175ebce8..6f510019 100755 --- a/scripts/check_layer_size.sh +++ b/scripts/check_layer_size.sh @@ -9,7 +9,7 @@ # 5 mb size limit MAX_LAYER_COMPRESSED_SIZE_KB=$(expr 5 \* 1024) -MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 15 \* 1024) +MAX_LAYER_UNCOMPRESSED_SIZE_KB=$(expr 16 \* 1024) LAYER_FILES_PREFIX="datadog_lambda_py" From 4cba13dff06c36017f114b45cb4f93b4d20a42c3 Mon Sep 17 00:00:00 2001 From: DarcyRaynerDD Date: Wed, 31 Mar 2021 16:01:45 -0400 Subject: [PATCH 4/4] Fix typo --- scripts/check_layer_size.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check_layer_size.sh b/scripts/check_layer_size.sh index 6f510019..ad807416 100755 --- a/scripts/check_layer_size.sh +++ b/scripts/check_layer_size.sh @@ -16,9 +16,9 @@ LAYER_FILES_PREFIX="datadog_lambda_py" LAYER_DIR=".layers" VERSIONS=("2.7" "3.6" "3.7" "3.8") -for node_version in "${VERSIONS[@]}" +for version in "${VERSIONS[@]}" do - FILE=$LAYER_DIR/${LAYER_FILES_PREFIX}${node_version}.zip + FILE=$LAYER_DIR/${LAYER_FILES_PREFIX}${version}.zip FILE_SIZE=$(stat --printf="%s" $FILE) FILE_SIZE_KB="$(( ${FILE_SIZE%% *} / 1024))" echo "Layer file ${FILE} has zipped size ${FILE_SIZE_KB} kb"