diff --git a/.github/actions/smoke-test/test.sh b/.github/actions/smoke-test/test.sh index 1e9ba452a..0f7d78d99 100755 --- a/.github/actions/smoke-test/test.sh +++ b/.github/actions/smoke-test/test.sh @@ -14,3 +14,11 @@ docker images # Clean up docker rm -f $(docker container ls -f "label=${id_label}" -q) + +# Checking size of universal image + +if [ $IMAGE == "test-universal" ]; then + chmod -R 777 $(pwd)/src/$IMAGE/check-size.sh + cd $(pwd)/src/$IMAGE/ + sudo ./check-size.sh $IMAGE +fi \ No newline at end of file diff --git a/src/test-universal/.devcontainer.json b/src/test-universal/.devcontainer.json new file mode 100644 index 000000000..59569d1e9 --- /dev/null +++ b/src/test-universal/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "name": "universal", + "image": "mcr.microsoft.com/devcontainers/universal:dev-linux" +} \ No newline at end of file diff --git a/src/test-universal/check-size.sh b/src/test-universal/check-size.sh new file mode 100755 index 000000000..9af9484fa --- /dev/null +++ b/src/test-universal/check-size.sh @@ -0,0 +1,55 @@ +#!/bin/bash +IMAGE="$1" + +# Function to handle errors +handle_error() { + local exit_code=$? + local line_number=$1 + local command=$2 + echo "Error occurred at line $line_number with exit code $exit_code in command $command" + exit $exit_code +} +trap 'handle_error $LINENO ${BASH_COMMAND%% *}' ERR +echo "This is line $LINENO" +# Check if bc is installed +if ! command -v bc &> /dev/null; then + echo "bc is not installed. Installing..." + # Install bc using apt-get (for Debian-based systems) + sudo apt-get update + sudo apt-get install -y bc +fi + +convert_gb_to_bytes() { + local gb="$1" + local bytes + bytes=$(echo "scale=0; $gb * 1024^3" | bc) + printf "%.0f\n" "$bytes" +} +CONTAINER_ID=$(docker ps -q --filter "label=test-container=$IMAGE") +# Find the image ID of the container +IMAGE_ID=$(docker inspect --format='{{.Image}}' "$CONTAINER_ID") +# Find the size of the image +IMAGE_SIZE=$(docker image inspect --format='{{.Size}}' "$IMAGE_ID") +# Output the size +echo "Size of the image $IMAGE_ID: $IMAGE_SIZE bytes" +# Define the threshold size (in GB) +gb_value=12.5 +threshold=$(convert_gb_to_bytes "$gb_value") +# Retrieve the Docker image size +echo -e "\nThreshold=$threshold" +# Remove the 'MB' from the size string and convert to an integer +image_size=${IMAGE_SIZE%bytes} +image_size=${image_size//.} +# Check if the image size is above the threshold +echo -e "\n🧪 Checking image size of $IMAGE :" +if [ -n $image_size ] && [ $image_size -gt $threshold ]; then + echo -e "\nImage size exceeds the threshold of $gb_value gb" + echo -e "\n❌ Image size check failed." +else + echo -e "\n✅ Passed!" +fi +# Uninstall bc if it was installed temporarily +if [[ $(dpkg-query -l bc | grep -c '^ii ') -eq 1 ]]; then + echo "Removing bc..." + sudo apt-get purge -y bc +fi \ No newline at end of file diff --git a/src/test-universal/test-project/test.sh b/src/test-universal/test-project/test.sh new file mode 100755 index 000000000..43a6972b4 --- /dev/null +++ b/src/test-universal/test-project/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash +cd $(dirname "$0") + +echo -e "\nTest file executed"