Skip to content

Instantly share code, notes, and snippets.

# Prerequisite
# 1) Install azure-cli, curl
# 2) Grant the identity AcrPull role on the registry

az login --identity

Powershell script to get total compute (vmss and vm) usage (vm and core count)

<#
.SYNOPSIS
    Get Compute Usage (VMSS + VM) and output the details in CSV format to compute-usage.csv file
 
.EXAMPLE
    .\GetComputeUsage.ps1 -targetSubscriptionName "My Subscription Name"
# Prerequisite
# 1) Install azure-cli curl, jq

registry="myregistry.azurecr.io"
scope_catalog="registry:catalog:*"
scope_repo_metadata="repository:*:metadata_read"

# az login --identity
acr_refresh_token=$(az acr login --name $registry --expose-token | jq -r ".accessToken")

Pull Simple Linux or Windows Image (Single Region)

  • [NOTE] Windows image by default has one or two base layers hosted in Azure CDN seperately (a.k.a foreign layers). The client will download these foreign layers from Azure CDN directly.
sequenceDiagram
    Docker->>+ACR: [Head] <registry>.azurecr.io/v2/library/hello-world/manifests/latest
    Note right of ACR: All manifest request accept-header includes <br>application/vnd.oci.image.manifest.v1+json,<br>application/vnd.docker.distribution.manifest.v2+json,<br>application/vnd.docker.distribution.manifest.list.v2+json,<br>application/vnd.oci.image.index.v1+json,<br>application/vnd.docker.distribution.manifest.v1+prettyjws,<br>application/json
    ACR->>Docker: Manifest Digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4
    Docker->>+ACR: [GET] <registry>.azurecr.io/v2/library/hello-world/manifests/sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4

Prepare

Create a placeholder task resource in the registry with the following acb.yaml and enable trusted service access to the registry. It is one-time setup.

  • acb.yaml
version: v1.1.0
steps:
 - build: -t $Registry/{{.Values.image} -f {{.Values.dockerfile}} .
 - push:

Docker

data_direcotry_host_path=~/connected-regsitry-data
data_direcotry_container_path=/var/acr/data

# Dry Run
docker run -v $data_direcotry_host_path:$data_direcotry_container_path \
  acronpremdemo.azurecr.io/acr/crgc:latest --dry-run $data_direcotry_container_path
# Prerequisite
# 1) Install azure-cli, oras

import_artifact_tree()
{
  local reference=$1
  local artifacts
  local artifact

ACR Example

# Prerequisite
# 1) Install azure-cli, curl, jq

repo="hello-world"
tag="latest"
registry="myregistry.azurecr.io"
scope="repository:$repo:pull"
#!/bin/bash

# Prerequisite
# 1) Install azure-cli

registry="myregistry"
repo="myimage"
tag="mytag"
# Prerequisite
# 1) Install az-cli, docker, oras (0.16+), jq

registry="myregistry.azurecr.io"
repo="myimage"
tag="mytag"
reference=$registry/$myimage:$mytag

az login