From 6fc63e5d2207715a4c22227648b17e94783a0d7b Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Fri, 17 Feb 2023 12:59:53 +0000 Subject: [PATCH] docker/ci: Add debugging info Signed-off-by: Ryan Northey --- ci/docker_ci.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/ci/docker_ci.sh b/ci/docker_ci.sh index 0a82770ba36e2..6c0534702ed28 100755 --- a/ci/docker_ci.sh +++ b/ci/docker_ci.sh @@ -4,6 +4,26 @@ # CI logs. set -e +## DEBUGGING (NB: Set these in your env to avoided unwanted changes) +## Set this to _not_ build/push just print what would be +# DOCKER_CI_DRYRUN=true +# +## Set these to tag/push images to your own repo +# DOCKER_IMAGE_PREFIX=mydocker/repo +# DOCKERHUB_USERNAME=me +# DOCKERHUB_PASSWORD=mypassword +# +## Set these to simulate types of CI run +# AZP_SHA1=MOCKSHA +# AZP_BRANCH=refs/heads/main +# AZP_BRANCH=refs/heads/release/v1.43 +# AZP_BRANCH=refs/tags/v1.77 +## + +if [[ -n "$DOCKER_CI_DRYRUN" ]]; then + AZP_SHA1="${AZP_SHA1:-MOCKSHA}" +fi + function is_windows() { [[ "$(uname -s)" == *NT* ]] } @@ -73,7 +93,15 @@ build_images() { args+=("-o" "type=oci,dest=${ENVOY_DOCKER_IMAGE_DIRECTORY}/envoy${TYPE}.tar") fi + echo ">> BUILD: ${BUILD_TAG}" + echo "> docker ${BUILD_COMMAND[*]} --platform ${PLATFORM} ${args[*]} -t ${BUILD_TAG} ." + if [[ -n "$DOCKER_CI_DRYRUN" ]]; then + echo "" + return + fi + echo "..." docker "${BUILD_COMMAND[@]}" --platform "${PLATFORM}" "${args[@]}" -t "${BUILD_TAG}" . + echo "" } push_images() { @@ -85,9 +113,19 @@ push_images() { _args=$(build_args "${TYPE}") read -ra args <<<"$_args" PLATFORM="$(build_platforms "${TYPE}")" + + echo ">> PUSH: ${BUILD_TAG}" + echo "> docker ${BUILD_COMMAND[*]} --platform ${PLATFORM} ${args[*]} -t ${BUILD_TAG} . --push || + docker push ${BUILD_TAG}" + if [[ -n "$DOCKER_CI_DRYRUN" ]]; then + echo "" + return + fi + echo "..." # docker buildx doesn't do push with default builder docker "${BUILD_COMMAND[@]}" --platform "${PLATFORM}" "${args[@]}" -t "${BUILD_TAG}" . --push || docker push "${BUILD_TAG}" + echo "" } MAIN_BRANCH="refs/heads/main" @@ -118,7 +156,9 @@ else # Configure docker-buildx tools BUILD_COMMAND=("buildx" "build") - config_env + if [[ -z "$DOCKER_CI_DRYRUN" ]]; then + config_env + fi fi # Test the docker build in all cases, but use a local tag that we will overwrite before push in the @@ -136,7 +176,9 @@ if [[ "${AZP_BRANCH}" != "${MAIN_BRANCH}" ]] && exit 0 fi -docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_PASSWORD" +if [[ -z "$DOCKER_CI_DRYRUN" ]]; then + docker login -u "$DOCKERHUB_USERNAME" -p "$DOCKERHUB_PASSWORD" +fi for BUILD_TYPE in "${BUILD_TYPES[@]}"; do push_images "${BUILD_TYPE}" "${DOCKER_IMAGE_PREFIX}${BUILD_TYPE}${IMAGE_POSTFIX}:${IMAGE_NAME}"