![](/img/trans.png)
[英]How to combine docker creation and putting it in DEV Azure Container Registry?
[英]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.