From 6aa5d3704e1fd983ae09c23a11f9c468992cfcbd Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov <47745270+al-cheb@users.noreply.github.com> Date: Fri, 10 Dec 2021 13:10:45 +0300 Subject: [PATCH] Delete image before push (#4713) --- images.CI/macos/anka/Anka.Helpers.psm1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/images.CI/macos/anka/Anka.Helpers.psm1 b/images.CI/macos/anka/Anka.Helpers.psm1 index 56fc54c0..d076625f 100644 --- a/images.CI/macos/anka/Anka.Helpers.psm1 +++ b/images.CI/macos/anka/Anka.Helpers.psm1 @@ -13,7 +13,16 @@ function Push-AnkaTemplateToRegistry { [string] $TemplateName ) - $command = "anka registry -a $RegistryUrl push -t $TagVersion $TemplateName" + # if registry uuid doesn't match than delete an image in registry + $images = anka --machine-readable registry --registry-path $RegistryUrl list | ConvertFrom-Json | ForEach-Object body + $images | Where-Object name -eq $TemplateName | ForEach-Object { + $id = $_.id + Show-StringWithFormat "Deleting '$TemplateName[$id]' VM and '$TagVersion' tag" + $uri = '{0}/registry/vm?id={1}' -f $RegistryUrl, $id + Invoke-WebRequest -Uri $uri -Method Delete | Out-Null + } + + $command = "anka registry --registry-path $RegistryUrl push --force --tag $TagVersion $TemplateName" Invoke-AnkaCommand -Command $command }