🧑‍🏫
liualexiang
  • Introduction
  • Azure
    • AKS Basic
    • AKS Spark
    • AZ ACR SYNC
    • Azure CMI SDWAN
    • Azure LB DeepDive
      • Azure LB DeepDive
    • Azure Service Principal Basic
    • Azure Internal VM Network Connectivity
      • Azure Internal VM Network Connectivity
    • Azure Cli Build
    • Azure Vm Memory Monitor
  • Blockchain
    • BTC
  • CRISPR
    • 使用Parallel_Cluster提升CRISPA效率
  • OpenSource
    • ElasticSearch
      • ES Get Started
      • ES Search Query
      • Kibana 可视化
      • Logstash配置
    • Ansible 基础
    • Infra As Code
      • Pulumi Get Started
      • Terraform Basic
    • ZooKeeper 基础
    • RPC与REST
    • 使用Python申请大量内存测试
    • 使用TPC_DS产生压测数据
    • Superset
      • Superset部署手册
    • 代码扫描
    • Git
      • Git Basic
      • Github Action Basic
      • Gitlab与AzureAD集成
      • Gitbook 基础教程
    • K8S
      • enter_node
      • K8s X509 Client Cert
      • K8s Basic
      • K8s Oidc
      • Docker 基础
      • helm基础
      • K8S_Secrets管理
      • 深入了解K8S
      • 混沌工程
      • Istio
      • 生态
      • CRD开发
      • k8s网络
    • Cloud_Custodian
    • Jenkins Basic
    • Nginx
    • ETCD
    • 正则
    • VictoriaMetrics
    • Kafka
  • MySQL
    • MySQL 调优
  • Linux
    • SSH Tunnel 上网
    • 内存管理
    • 在Linux系统中通过LUKS加密磁盘
    • 量子计算 Basic
    • IO多路复用
    • Iptables
    • tmux和screen
    • Systemd
    • OS 基础
    • jq基础
    • yum
    • neovim
  • Web
    • Html Css
    • Web部署
    • 缓存
  • Programming
    • 算法
      • 返回list中最大生序子序列长度
    • Python技巧
      • Python的语法糖
      • Python常用装饰器
      • AsyncIO基础
      • 自动化测试pytest
      • python中的下划线
      • 面向对象
      • Python的坑
      • Python配置文件管理
      • HTTP Stream Response
      • Python项目管理
    • 设计模式
      • 设计模式
      • 面向对象的思想
      • 编程概念
    • Go
      • Go 基础
      • Go常用功能
      • 结构体入门
    • 前端
    • Vue
    • NodeJS
  • Math
    • 多项式插值法
  • Security
    • HTTP常见攻击
    • 加密与签名
    • RSA
    • ECDSA
  • Solidity
    • Solidity基础
    • Blockchain Testnet Faucet
  • Tools
    • 视频处理ffmpeg
    • IDE配置
    • iTerm2美化
    • 密码管理
    • FRP配置
    • 工具集
由 GitBook 提供支持
在本页
  • 创建Azure Function
  • 配置 VS Code Extension
  • 上传代码到Function
  • 代码实现
  • 同一个region内,不同的ACR Repo之间的copy
  1. Azure

AZ ACR SYNC

创建Azure Function

配置 VS Code Extension

上传代码到Function

func azure functionapp publish xiangacrcopy

代码实现

同一个region内,不同的ACR Repo之间的copy

import logging,json
import azure.functions as func

from msrestazure.azure_active_directory import MSIAuthentication
credentials = MSIAuthentication()

SUBSCRIPTION_ID = '5fb605ab-c16c-4184-8a02-fee38cc11b8c'
SRC_RESOURCE_GROUP = 'xiangliu_csa'

import  azure.mgmt.containerregistry as acr
acrclient = acr.ContainerRegistryManagementClient(credentials=credentials, subscription_id=SUBSCRIPTION_ID)

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    acr_event=json.loads(req.get_body())
    SRC_REGISTRY_NAME = acr_event['request']['host'].split('.')[0]
    SOURCE_IMG = acr_event["target"]['repository'] + ':' + acr_event["target"]['tag']
    SRC_REGISTRY_URI = acr_event['request']['host']
    TARGET_IMG_TAG = [SOURCE_IMG]
    TARGET_RESOURCE_GROUP = 'xiangliu_csa'
    TAEGET_IMG_REPO = 'xiangliurepo2'

    src_image_url = acr_event['request']['host'] + '/' + acr_event["target"]['repository'] + ':' + acr_event["target"]['tag']

    passwd = acrclient.registries.list_credentials(registry_name= SRC_REGISTRY_NAME , resource_group_name= SRC_RESOURCE_GROUP).passwords[0].value
    imp_src_cred = acrclient.models().ImportSourceCredentials(password= passwd, username= SRC_REGISTRY_NAME)
    import_img_src = acrclient.models().ImportSource(source_image = SOURCE_IMG ,registry_uri= SRC_REGISTRY_URI , credentials = imp_src_cred)
    img_mode = acrclient.models().ImportMode.force
    import_img_para=acrclient.models().ImportImageParameters(source=import_img_src, target_tags = TARGET_IMG_TAG, mode= img_mode)
    imp_img = acrclient.registries.import_image(resource_group_name= TARGET_RESOURCE_GROUP, registry_name =TAEGET_IMG_REPO, parameters=import_img_para)
    return func.HttpResponse(src_image_url + " copied successfully")
    # return func.HttpResponse(result)
上一页AKS Spark下一页Azure CMI SDWAN

最后更新于3年前