Skip to content

Instantly share code, notes, and snippets.

@avtar
Created October 26, 2024 18:02
Show Gist options
  • Save avtar/bc97382db0d7c4da5ca647b1bb8e64f4 to your computer and use it in GitHub Desktop.
Save avtar/bc97382db0d7c4da5ca647b1bb8e64f4 to your computer and use it in GitHub Desktop.
Report average docker build time
#!/bin/sh
set -e
total_time=0
for i in 1 2 3
do
echo "==> Cleaning up Docker environment before build #$i..."
docker system prune --all --volumes --force > /dev/null 2>&1
echo "==> Running build #$i..."
start_time=$(date +%s)
docker build --platform linux/amd64 . > /dev/null 2>&1
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo "==> Time taken for build #$i: ${elapsed_time}s"
total_time=$((total_time + elapsed_time))
done
average_time=$((total_time / 3))
git_hash=$(git log -n 1 --pretty=format:"%h" -- Dockerfile)
echo ""
echo "==> Dockerfile $git_hash average build time: ${average_time}s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment