From e227c3d47645faa12b3a828f7d67ffef135b69a5 Mon Sep 17 00:00:00 2001 From: Vitor Bandeira Date: Wed, 3 Jul 2024 14:04:18 -0300 Subject: [PATCH] docker: use shorter tags Signed-off-by: Vitor Bandeira --- etc/DockerHelper.sh | 62 +++++++++++++++++++-------------------------- etc/DockerTag.sh | 23 +++++++++++++++++ 2 files changed, 49 insertions(+), 36 deletions(-) create mode 100755 etc/DockerTag.sh diff --git a/etc/DockerHelper.sh b/etc/DockerHelper.sh index 83e1198684..d8831e0dee 100755 --- a/etc/DockerHelper.sh +++ b/etc/DockerHelper.sh @@ -24,8 +24,7 @@ usage: $0 [CMD] [OPTIONS] 'builder': os + packages to compile app + copy source code and build app -threads Max number of threads to use if compiling. - -sha Use git commit sha as the tag image. Default is - 'latest'. + Default = \$(nproc) -ci Install CI tools in image -h -help Show this message and exits -username Docker Username @@ -36,7 +35,6 @@ EOF } _setup() { - commitSha="$(git rev-parse HEAD | tr -cd 'a-zA-Z0-9-')" case "${os}" in "ubuntu20.04") osBaseImage="ubuntu:20.04" @@ -50,9 +48,10 @@ _setup() { ;; esac imageName="${IMAGE_NAME_OVERRIDE:-"${org}/flow-${os}-${target}"}" - imageTag="${commitSha}" - if [[ "${tag}" != "NONE" ]]; then + if [[ "${tag}" != "" ]]; then imageTag="${tag}" + else + imageTag=$(./etc/DockerTag.sh -dev) fi case "${target}" in "builder" | "master") @@ -95,43 +94,34 @@ _push() { echo "Missing required -password= argument" _help fi - docker login --username ${username} --password ${password} - if [[ "${tag}" == "NONE" ]]; then - tag="latest" + if [[ "${target}" != "dev" ]] && [[ "${target}" != "master" ]]; then + echo "Target ${target} is not valid candidate for push to Docker Hub." >&2 + _help fi - mkdir -p build - case "${target}" in - "dev" ) - ./etc/DockerHelper.sh create -os=${os} -ci -target=${target} \ - 2>&1 | tee build/create-${os}-${target}-${tag}.log - docker push ${imagePath} - ;; - "master" ) - # Create dev image needed as a base for builder image - ./etc/DockerHelper.sh create -os=${os} -target=dev \ - 2>&1 | tee build/create-${os}-dev-${target}-${tag}.log - # Create builder image - ./etc/DockerHelper.sh create -os=${os} -target=builder \ - 2>&1 | tee build/create-${os}-${target}-${tag}.log + docker login --username "${username}" --password "${password}" - docker push ${org}/flow-${os}-dev:${commitSha} + if [[ "${tag}" == "" ]]; then + tag=$(./etc/DockerTag.sh -dev) + fi - docker tag ${org}/flow-${os}-dev:${commitSha} ${org}/flow-${os}-dev:latest - docker push ${org}/flow-${os}-dev:latest + mkdir -p build + ./etc/DockerHelper.sh create -os=${os} -target=dev -tag=${tag} -ci \ + 2>&1 | tee build/create-${os}-dev-${tag}.log - docker tag ${org}/flow-${os}-builder:${commitSha} ${org}/orfs:${commitSha} - docker push ${org}/orfs:${commitSha} + docker push "${imageName}:${tag}" - docker tag ${org}/flow-${os}-builder:${commitSha} ${org}/orfs:${tag} - docker push ${org}/orfs:${tag} - ;; + if [[ "${target}" == "master" ]]; then + tag=$(./etc/DockerTag.sh -master) + # Create builder image + ./etc/DockerHelper.sh create -os=${os} -target=builder -tag=${tag} \ + 2>&1 | tee build/create-${os}-${target}-${tag}.log - *) - echo "Target ${target} is not valid candidate for push to Docker Hub." >&2 - _help - ;; - esac + docker tag ${org}/flow-${os}-builder:${tag} ${org}/orfs:${tag} + docker push ${org}/orfs:${tag} + docker tag ${org}/flow-${os}-builder:${tag} ${org}/orfs:${tag} + docker push ${org}/orfs:${tag} + fi } # @@ -161,7 +151,7 @@ fi os="ubuntu22.04" target="dev" numThreads="-1" -tag="NONE" +tag="" options="" while [ "$#" -gt 0 ]; do diff --git a/etc/DockerTag.sh b/etc/DockerTag.sh new file mode 100755 index 0000000000..d8718e769a --- /dev/null +++ b/etc/DockerTag.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +cd $(dirname $(realpath $0))/../ + +if [[ "$@" == "-dev" ]]; then + file_list=( + "./build_openroad.sh" + "./docker/Dockerfile.builder" + "./docker/Dockerfile.dev" + "./etc/DependencyInstaller.sh" + "./etc/DockerHelper.sh" + "./tools/OpenROAD/docker/Dockerfile.builder" + "./tools/OpenROAD/docker/Dockerfile.dev" + "./tools/OpenROAD/docker/Dockerfile.binary" + "./tools/OpenROAD/etc/DependencyInstaller.sh" + ) + cat "${file_list[@]}" | sha256sum | awk '{print substr($1, 1, 6)}' +elif [[ "$@" == "-master" ]]; then + git describe +else + echo "Usage: $0 {-dev|-master}" + exit 1 +fi