Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/check-size.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/build_layers.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
39 changes: 39 additions & 0 deletions scripts/check_layer_size.sh
Original file line number Diff line number Diff line change
@@ -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 16 \* 1024)


LAYER_FILES_PREFIX="datadog_lambda_py"
LAYER_DIR=".layers"
VERSIONS=("2.7" "3.6" "3.7" "3.8")

for version in "${VERSIONS[@]}"
do
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"
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