I have to write bash script which :
connect azure pipeline to azure portal through managed identity.
get the image tag form ACR whcih I have to update.
check for the latest image availability on dockerhub, if latest image is available then change the current tag to latest.
how can i do this thing in single script.
al1
March 28, 2024, 10:56am
#2
Which part are you stuck on?
I need full script for the same. I tried many scripts but didnt go through this.if possible please help me
al1
March 28, 2024, 11:03am
#4
So first login to Azure with AZ CLI. Then pull the image and get the hash of the docker image:
docker inspect --format='{{.RepoDigests}}' nginx
Pull the other image and get the hash for that.
Compare if different, update the tag and push.
ACR_NAME=“kacr”
Define the image name including repository and tag
IMAGE_NAME=“email/mgageemailinterface-test”
Log in to Azure using the Azure CLI (if not logged in already)
az login
Get the tag of the repository from the ACR image
TAG=$(az acr repository show-tags --name $ACR_NAME --repository $IMAGE_NAME --output tsv --query ‘[0]’)
Output the retrieved tag
echo “Tag of $IMAGE_NAME in $ACR_NAME: $TAG”
#FROM DockerHUB
Trivy image name
image_name=“aquasec/trivy”
Fetch tags from Docker Hub API
tags=$(curl -s “https://registry.hub.docker.com/v2/repositories/${image_name}/tags/ ” | jq -r ‘.results[].name’)
Extract latest tag
latest_tag=$(echo “$tags” | grep -v -E ‘alpha|beta’ | head -n 1)
Extract latest -1 tag
latest_minus_one_tag=$(echo “$tags” | grep -v -E ‘alpha|beta’ | head -n 2 | tail -n 1)
Output the results
echo “Latest tag of $image_name: $latest_tag”
echo “Latest -1 tag of $image_name: $latest_minus_one_tag”
In this i am not able to get the digest of the tag and comapre it.
al1
April 1, 2024, 2:14pm
#6
Post scripts in:
Code Blocks
I didn’t see a question in your post.
Thanks for your reply ,now I am getting the output as per my requirements.