diff --git a/etc/DockerHelper.sh b/etc/DockerHelper.sh index ec1d97f710..79740ae220 100755 --- a/etc/DockerHelper.sh +++ b/etc/DockerHelper.sh @@ -26,6 +26,7 @@ usage: $0 [CMD] [OPTIONS] -threads Max number of threads to use if compiling. -sha Use git commit sha as the tag image. Default is 'latest'. + -cache Use remote registry cache when building the image. -h -help Show this message and exits EOF @@ -60,12 +61,20 @@ _setup() { fromImage="${FROM_IMAGE_OVERRIDE:-"${org}/flow-${os}-dev"}:${imageTag}" context="." buildArgs="--build-arg numThreads=${numThreads}" + cacheArgs="" + if [[ "${useCache}" == "yes" ]]; then + cacheArgs="--cache-from type=registry,ref=ghcr.io/antmicro/openroad-flow-scripts-test-cache/${os}" + fi ;; "dev" ) fromImage="${FROM_IMAGE_OVERRIDE:-$osBaseImage}" cp tools/OpenROAD/etc/DependencyInstaller.sh etc/InstallerOpenROAD.sh context="etc" buildArgs="" + cacheArgs="" + if [[ "${useCache}" == "yes" ]]; then + cacheArgs="--cache-from type=registry,ref=ghcr.io/antmicro/openroad-flow-scripts-test-cache-deps/${os}" + fi ;; *) echo "Target ${target} not found" >&2 @@ -79,7 +88,11 @@ _setup() { _create() { echo "Create docker image ${imagePath} using ${file}" - docker build --file "${file}" --tag "${imagePath}" ${buildArgs} "${context}" + if docker buildx version > /dev/null 2>&1; then + docker buildx build --load=true --file "${file}" ${cacheArgs} --tag "${imagePath}" ${buildArgs} "${context}" + else + docker build --file "${file}" ${cacheArgs} --tag "${imagePath}" ${buildArgs} "${context}" + fi rm -f etc/InstallerOpenROAD.sh } @@ -143,6 +156,7 @@ fi os="centos7" target="dev" useCommitSha="no" +useCache="no" numThreads="-1" while [ "$#" -gt 0 ]; do @@ -166,6 +180,9 @@ while [ "$#" -gt 0 ]; do echo "${1} requires an argument" >&2 _help ;; + -cache ) + useCache=yes + ;; *) echo "unknown option: ${1}" >&2 _help