Skip to content

Commit

Permalink
Enable to set latest tag in the helper_to_push CI scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
shay-berman committed May 3, 2018
1 parent 551cb44 commit f8fbc99
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 32 deletions.
43 changes: 38 additions & 5 deletions scripts/helper_to_push_internal_images_2hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,71 @@

function usage()
{
echo $0 [internal-image-path] [external-image-path]
echo $0 [internal-image-path] [external-image-path] [latest-tag-optional]
exit 1
}

[ $# != 2 ] && { usage; }
[ $# -eq 2 -o $# -eq 3 ] || { usage; }

internal_image=$1
external_image=$2
latest="$3"

echo "1. Validate no external_image exist yet before pushing it."
# if also latest, then define latest_external_image (replace the external tag with the $latest wanted tag)
if [ -n "$latest" ]; then
latest_external_image=`echo $external_image | sed "s|^\(.*/.*:\)\(.*\)$|\1$latest|"`
latest_str_msg=" And latest tag image [$latest_external_image]"
fi

echo "Preparing to push internal_image --> external_image:"
echo " internal_image=[$internal_image]"
echo " external_image=[$external_image]"
[ -n "$latest" ] && echo " latest_image =[$latest_external_image]"


echo "1. Validate no external_image exist yet before pushing it." # Note: no need to test latest tag since its already exist
docker pull $external_image && { echo "Error : the $external_image exist in remote. Cannot overwrite it."; exit 1; } || { echo "$external_image is not exist on the remote."; }
echo ""


echo "2. Validate internal_image not exist yet on local."
docker images $internal_image
docker rmi $internal_image && { echo "Remove the internal_image image to pull it again"; } || { echo "internal_image not exist on local. Continue."; }
echo ""


echo "3. Pull internal_image to local"
docker pull $internal_image
echo ""

echo "4. Tag internal_image to external_image and remove the internal_image"

echo "4. Tag internal_image to external_image (and latest=[$latest_external_image]) and remove the internal_image"
docker tag $internal_image $external_image
[ -n "$latest_external_image" ] && docker tag $internal_image $latest_external_image
docker rmi $internal_image
docker push $external_image
[ -n "$latest_external_image" ] && docker push $latest_external_image
echo ""


echo "5. Test pushed image by delete the local and pull it back"
docker rmi $external_image
docker pull $external_image
docker rmi $external_image


if [ -n "$latest_external_image" ]; then
echo "6. Test pushed [latest] image by delete the local and pull it back"
docker rmi $latest_external_image
docker pull $latest_external_image
docker rmi $latest_external_image
fi

set +x
echo ""
echo "Succeeded to push [$internal_image] ---> [$external_image]"
echo "Succeeded to push internal_image --> external_image"
echo " internal_image=[$internal_image]"
echo " external_image=[$external_image]"
[ -n "$latest" ] && echo " latest_image =[$latest_external_image]"
set -x

35 changes: 26 additions & 9 deletions scripts/helper_to_push_manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# The script create, inspect and push new docker manifest.
# The script validates the whole process. If something gets wrong the script will fail with error.
# Pre-requisites:
# 1. Assume docker login to the external registry was already done.
# 2. Assume the multi architecture images were already pushed.
# 1. Run docker login to the external registry in advance.
# 2. The internal images should be exist in advance.
# 3. The designated manifest should NOT be exist (the script will create it).
# 4. "docker manifest" is enabled.
# ----------------------------------------------------------------

function abort()
Expand All @@ -17,14 +19,22 @@ function abort()
exit $exitcode
}

USAGE="Usage : $0 [manifest-path] [image-amd64-path] [image-ppc64le-path]"
USAGE="Usage : $0 [manifest-path] [image-amd64-path] [image-ppc64le-path] [fail-if-exist-optional]"

[ $# -ne 3 ] && abort 1 $USAGE
[ $# -eq 3 -o $# -eq 4 ] || abort 1 $USAGE

expected_manifest_arch_number=2
manifest=$1
image_amd64=$2
image_ppc64le=$3
fail_if_exist="${4:-true}" # by default fail if external manifest already exist

echo "Preparing to create and push manifest for image_amd64 and image_ppc64le:"
echo " manifest=[$manifest]"
echo " image_amd64=[$image_amd64]"
echo " image_ppc64le=[$image_ppc64le]"


manifest_dirname="~/.docker/manifests"
dockerhub_prefix_manifest="docker.io_"
convert_manifest_filename=`echo "$manifest" | sed -e 's|/|_|g' -e 's|:|-|g'`
Expand All @@ -37,8 +47,11 @@ echo "1. Make sure architecture images are not exist locally and if so remove th

echo "2. Manifest validation \(manifest should not exit, not local nor remote\)..."
ls -ld "$specific_manifest_dirname $specific_manifest_dirname_with_prefix" && abort 1 "local manifest dir should NOT exist before creating the manifest. Please clean it and rerun."
docker manifest inspect $manifest && abort 1 "manifest inspect should NOT exist before pushing it. Please clean it and rerun." || :

if [ "$fail_if_exist" = "true" ]; then
docker manifest inspect $manifest && abort 1 "manifest inspect should NOT exist before pushing it. Please clean it and rerun." || :
else
docker manifest inspect $manifest && echo "manifest inspect should NOT exist before pushing it. BUT fail_if_exist is not true so skip validation." || :
fi

echo "3. Manifest creation and push..."
docker manifest create $manifest ${image_amd64} ${image_ppc64le} || abort 2 "fail to create manifest."
Expand All @@ -54,13 +67,17 @@ echo "4. Remote manifest validation..."
docker manifest inspect $manifest || abort 3 "fail to inspect remote manifest."
docker pull $manifest || abort 3 "fail pull remote manifest."
expected_arch=`uname -m`
docker run -it --rm $manifest uname -m | grep $expected_arch || abort 3 "The manifest run did not bring the expected arch"
docker run --rm $manifest uname -m | grep $expected_arch || abort 3 "The manifest run did not bring the expected arch"
docker rmi $manifest # just remove the local manifest that was pulled for testing
actual_manifest_arch_number=`docker manifest inspect $manifest | grep architecture | wc -l`
[ $actual_manifest_arch_number -ne $expected_manifest_arch_number ] && abort 3 "Manifest pushed but its not contain [$expected_manifest_arch_number] architectures as expected."



set +x
echo "================================================================================"
echo "Successfully created and pushed a manifest [$manifest] with [$expected_arch] architectures. "
echo "Succeeded to create and push manifest for image_amd64 and image_ppc64le:"
echo " manifest=[$manifest]"
echo " image_amd64=[$image_amd64]"
echo " image_ppc64le=[$image_ppc64le]"
set -x

56 changes: 38 additions & 18 deletions scripts/helper_to_push_ubiquity_images_and_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,68 @@
# 2. The internal images should be exist in advance.
# 3. The external images should NOT be exist (the script will creates them).
# 4. Helper scripts should be accessible: ./helper_to_push_internal_images_2hub.sh and ./helper_to_push_manifest.sh
# 5. Scripts input comes from environment variables, see ubiquity_*_envs
# 5. Scripts input comes from environment variables, see ubiquity_*_envs and optional TAG_LATEST
# ----------------------------------------------------------------

ubiquity_envs="in_UBIQUITY_IMAGE_AMD64 out_UBIQUITY_IMAGE_AMD64 in_UBIQUITY_IMAGE_PPC64LE out_UBIQUITY_IMAGE_PPC64LE out_UBIQUITY_IMAGE_MULTIARCH"
ubiquity_db_envs="in_UBIQUITY_DB_IMAGE_AMD64 out_UBIQUITY_DB_IMAGE_AMD64 in_UBIQUITY_DB_IMAGE_PPC64LE out_UBIQUITY_DB_IMAGE_PPC64LE out_UBIQUITY_DB_IMAGE_MULTIARCH"
ubiquity_provisioner_envs="in_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 out_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 in_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE out_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE out_UBIQUITY_K8S_PROVISIONER_IMAGE_MULTIARCH"
ubiquity_flex_envs="in_UBIQUITY_IMAGE_K8S_FLEX_AMD64 out_UBIQUITY_K8S_FLEX_IMAGE_AMD64 in_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE out_UBIQUITY_K8S_FLEX_IMAGE_MULTIARCH"
ubiquity_flex_envs="in_UBIQUITY_K8S_FLEX_IMAGE_AMD64 out_UBIQUITY_K8S_FLEX_IMAGE_AMD64 in_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE out_UBIQUITY_K8S_FLEX_IMAGE_MULTIARCH"

date
# Validations
[ -f ./helper_to_push_internal_images_2hub.sh -a -f ./helper_to_push_manifest.sh ] && : || exit 1
for expected_env in $ubiquity_envs $ubiquity_db_envs $ubiquity_provisioner_envs $ubiquity_flex_envs; do
[ -z "`printenv $expected_env`" ] && { echo "Error: expected env [$expected_env] does not exist. Please set it first."; exit 1; } || :
echo "$expected_env=`printenv $expected_env`"
done

echo "TAG_LATEST=$TAG_LATEST"

echo ""
echo "Start to push Ubiquity..."
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_IMAGE_AMD64 $out_UBIQUITY_IMAGE_AMD64
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_IMAGE_PPC64LE $out_UBIQUITY_IMAGE_PPC64LE
echo "Start to push Ubiquity images and manifests..."
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_IMAGE_AMD64 $out_UBIQUITY_IMAGE_AMD64 $TAG_LATEST
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_IMAGE_PPC64LE $out_UBIQUITY_IMAGE_PPC64LE $TAG_LATEST
./helper_to_push_manifest.sh $out_UBIQUITY_IMAGE_MULTIARCH $out_UBIQUITY_IMAGE_AMD64 $out_UBIQUITY_IMAGE_PPC64LE
if [ -n "$TAG_LATEST" ]; then
latest_external_image=`echo $out_UBIQUITY_IMAGE_MULTIARCH | sed "s|^\(.*/.*:\)\(.*\)$|\1$TAG_LATEST|"` # replace tag with $TAG_LATEST
./helper_to_push_manifest.sh $latest_external_image $out_UBIQUITY_IMAGE_AMD64 $out_UBIQUITY_IMAGE_PPC64LE
fi

echo ""
echo "Start to push Ubiquity DB :"
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_DB_IMAGE_AMD64 $out_UBIQUITY_DB_IMAGE_AMD64
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_DB_IMAGE_PPC64LE $out_UBIQUITY_DB_IMAGE_PPC64LE
./helper_to_push_manifest.sh $out_UBIQUITY_DB_IMAGE_MULTIARCH $out_UBIQUITY_DB_IMAGE_AMD64 $out_UBIQUITY_DB_IMAGE_PPC64LE
echo "Start to push Ubiquity DB images and manifests..."
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_DB_IMAGE_AMD64 $out_UBIQUITY_DB_IMAGE_AMD64 $TAG_LATEST
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_DB_IMAGE_PPC64LE $out_UBIQUITY_DB_IMAGE_PPC64LE $TAG_LATEST
./helper_to_push_manifest.sh $out_UBIQUITY_DB_IMAGE_MULTIARCH $out_UBIQUITY_DB_IMAGE_AMD64 $out_UBIQUITY_DB_IMAGE_PPC64LE $TAG_LATEST
if [ -n "$TAG_LATEST" ]; then
latest_external_image=`echo $out_UBIQUITY_DB_IMAGE_MULTIARCH | sed "s|^\(.*/.*:\)\(.*\)$|\1$TAG_LATEST|"` # replace tag with $TAG_LATEST
./helper_to_push_manifest.sh $latest_external_image $out_UBIQUITY_DB_IMAGE_AMD64 $out_UBIQUITY_DB_IMAGE_PPC64LE $TAG_LATEST
fi


echo ""
echo "Start to push Ubiquity provisioner :"
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 $out_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE $out_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE
./helper_to_push_manifest.sh $out_UBIQUITY_K8S_PROVISIONER_IMAGE_MULTIARCH $out_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 $out_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE
echo "Start to push Ubiquity provisioner images and manifests..."
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 $out_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 $TAG_LATEST
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE $out_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE $TAG_LATEST
./helper_to_push_manifest.sh $out_UBIQUITY_K8S_PROVISIONER_IMAGE_MULTIARCH $out_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 $out_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE $TAG_LATEST
if [ -n "$TAG_LATEST" ]; then
latest_external_image=`echo $out_UBIQUITY_K8S_PROVISIONER_IMAGE_MULTIARCH | sed "s|^\(.*/.*:\)\(.*\)$|\1$TAG_LATEST|"` # replace tag with $TAG_LATEST
./helper_to_push_manifest.sh $latest_external_image $out_UBIQUITY_K8S_PROVISIONER_IMAGE_AMD64 $out_UBIQUITY_K8S_PROVISIONER_IMAGE_PPC64LE $TAG_LATEST
fi

echo ""
echo "Start to push Ubiquity flex :"
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_FLEX_IMAGE_AMD64 $out_UBIQUITY_K8S_FLEX_IMAGE_AMD64
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE $out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE
./helper_to_push_manifest.sh $out_UBIQUITY_K8S_FLEX_IMAGE_MULTIARCH $out_UBIQUITY_K8S_FLEX_IMAGE_AMD64 $out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE

echo ""
echo "Start to push Ubiquity flex images and manifests..."
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_FLEX_IMAGE_AMD64 $out_UBIQUITY_K8S_FLEX_IMAGE_AMD64 $TAG_LATEST
./helper_to_push_internal_images_2hub.sh $in_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE $out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE $TAG_LATEST
./helper_to_push_manifest.sh $out_UBIQUITY_K8S_FLEX_IMAGE_MULTIARCH $out_UBIQUITY_K8S_FLEX_IMAGE_AMD64 $out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE $TAG_LATEST
if [ -n "$TAG_LATEST" ]; then
latest_external_image=`echo $out_UBIQUITY_K8S_FLEX_IMAGE_MULTIARCH | sed "s|^\(.*/.*:\)\(.*\)$|\1$TAG_LATEST|"` # replace tag with $TAG_LATEST
./helper_to_push_manifest.sh $latest_external_image $out_UBIQUITY_K8S_FLEX_IMAGE_AMD64 $out_UBIQUITY_K8S_FLEX_IMAGE_PPC64LE $TAG_LATEST
fi


date
echo "######################################"
echo "Finish to push successfully all images"
echo "######################################"
Expand Down

0 comments on commit f8fbc99

Please sign in to comment.