繁体   English   中英

如何为 Azure 容器注册表编写 docker 映像开发以暂存升级脚本?

[英]How can I write a docker image dev to stage promotion script for Azure container registry?

我们想编写一个 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM