简体   繁体   English

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

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

We want to write a shell script to promote docker images from dev to stage container registries for azure.我们想编写一个 shell 脚本来将 docker 映像从开发人员提升到 azure 的暂存容器注册表。

Here is something you can modify and use:以下是您可以修改和使用的内容:

#!/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.

相关问题 如何结合 docker 创建并将其放入 DEV Azure 容器注册表? - How to combine docker creation and putting it in DEV Azure Container Registry? 如何从 Azure 容器注册表中的映像创建 Dockerfile? - How can I create a Dockerfile FROM an Image in Azure Container Registry? 如何从Docker注册表中提取容器映像以部署Azure容器 - How to pull container image from docker registry to deploy azure container Azure - 如何使用 Container Registry 将 Docker 执行到容器中? - Azure - how do I Docker exec into container with a Container Registry? 如何使用 terraform 将 docker 映像推送到 Azure 容器注册表? - How to push a docker image to Azure container registry using terraform? 从Azure容器注册表部署Docker映像 - Deploying a Docker Image from Azure Container Registry 我无法在Azure容器注册表中选择图像 - I can't choose image in Azure Container Registry 更新基本映像时,如何更新 azure 容器注册表中的所有映像 - How can I update all images in azure container registry when base image is updated Azure:如何找到容器注册表的所有者或资源 ID? - Azure: How can I find the owner or resource ID of a container registry? 如何从 Azure 容器注册表中删除映像 - How to delete image from Azure Container Registry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM