gpt4 book ai didi

azure - 如何编写 docker 镜像开发来为 Azure 容器注册表暂存升级脚本?

转载 作者:行者123 更新时间:2023-12-03 02:11:07 34 4
gpt4 key购买 nike

我们想要编写一个 shell 脚本来将 docker 镜像从开发人员提升到 Azure 的暂存容器注册表。

最佳答案

以下是您可以修改和使用的内容:

#!/usr/bin/env bash
BASE_DIR=.
LOG_FILE=${BASE_DIR}/PromotionImageScriptLog.log

log()
{
echo "`date +'%m-%d-%Y: %X'` - $@" >> ${BASE_DIR}/${LOG_FILE} 2>>${BASE_DIR}/${LOG_FILE}
echo "`date +'%m-%d-%Y: %X'` - $@"
}

echo "Choose the environments for docker image promotions"
echo "Enter option 1: For dev to stage promotions"
echo "Enter option 2: For stage to prod promotions"

read promotion_env_option
echo "You chose:$promotion_env_option"


echo "Enter the docker image to be promoted with path: (zippy-backend/zippy-webhook-processor:2.1.1-SNAPSHOT)"
read source_image_with_path
echo "Image to be promoted:$source_image_with_path"

source_repo=$source_image_with_path
target_repo=$source_image_with_path



if [ $promotion_env_option = "1" ]
then
source_registry="/subscriptions/-----YOUR-SOURCE-SUBSCRIPTION-ID----/resourceGroups/----YOUR-SOURCE-RG----/providers/Microsoft.ContainerRegistry/registries/----YOUR-SOURCE-CONTAINER-REGISTRY----"
target_subscription="-----YOUR-TARGET-SUBSCRIPTION-NAME----"
target_registry_name="----YOUR-TARGET-CONTAINER-REGISTRY----"
elif [ $promotion_env_option = "2" ]
then
source_registry="/subscriptions/YOUR-SOURCE-SUBSCRIPTION-ID/resourceGroups/----YOUR-SOURCE-RG----/providers/Microsoft.ContainerRegistry/registries/----YOUR-SOURCE-CONTAINER-REGISTRY----"
target_subscription="-----YOUR-TARGET-SUBSCRIPTION-NAME----"
target_registry_name="----YOUR-TARGET-CONTAINER-REGISTRY----"
else
echo "Please choose 1 or 2 option for promtion."
fi



echo "source_registry:$source_registry"
echo "target_subscription:$target_subscription"
echo "target_registry_name:$target_registry_name"



log "az account set --subscription ${target_subscription}"
az account set --subscription "${target_subscription}"
RC=$?
if [[ ${RC} -ne 0 ]]; then
log "ERROR: Failed to set subscription. RC=${RC}"
exit 1
fi

log "az acr import --name $target_registry_name --subscription "$target_subscription" --source $source_repo --image $target_repo --registry $source_registry"
az acr import --name $target_registry_name --subscription "$target_subscription" --source $source_repo --image $target_repo --registry $source_registry
RC=$?
if [[ ${RC} -ne 0 ]]; then
log "ERROR: Failed to promote ${target_registry_name}:${target_repo} to Production ACR. RC=${RC}"
else
log "Image promted to $target_registry_name"
fi

关于azure - 如何编写 docker 镜像开发来为 Azure 容器注册表暂存升级脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73334902/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com