Skip to content

Instantly share code, notes, and snippets.

@avtar
Created October 26, 2024 18:02
Show Gist options
  • Select an option

  • Save avtar/bc97382db0d7c4da5ca647b1bb8e64f4 to your computer and use it in GitHub Desktop.

Select an option

Save avtar/bc97382db0d7c4da5ca647b1bb8e64f4 to your computer and use it in GitHub Desktop.

Revisions

  1. avtar created this gist Oct 26, 2024.
    26 changes: 26 additions & 0 deletions docker-build.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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"