From 61397840c86f19d9ddf9b74a5923dbe4cfcb4f20 Mon Sep 17 00:00:00 2001 From: Illia Vysochyn Date: Fri, 28 Jun 2024 17:45:06 +0200 Subject: [PATCH] [#61287] WIP: etc: DockerHelper.sh: Build with registry cache Adds an option to use remote GitHub registry cache. Signed-off-by: Illia Vysochyn --- etc/DockerHelper.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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