1 # Implements the equivalent of ci-templates container-ifnot-exists, using
2 # Docker directly as we don't have buildah/podman/skopeo available under
3 # Windows, nor can we execute Docker-in-Docker
4 $registry_uri = $args[0]
5 $registry_username = $args[1]
6 $registry_password = $args[2]
7 $registry_user_image = $args[3]
8 $registry_central_image = $args[4]
10 Set-Location -Path ".\.gitlab-ci\windows"
12 docker login -u "$registry_username" -p "$registry_password" "$registry_uri"
14 Write-Host "docker login failed to $registry_uri"
18 # if the image already exists, don't rebuild it
19 docker pull "$registry_user_image"
21 Write-Host "User image $registry_user_image already exists; not rebuilding"
22 docker logout "$registry_uri"
26 # if the image already exists upstream, copy it
27 docker pull "$registry_central_image"
29 Write-Host "Copying central image $registry_central_image to user image $registry_user_image"
30 docker tag "$registry_central_image" "$registry_user_image"
31 docker push "$registry_user_image"
33 docker logout "$registry_uri"
35 Write-Host "Pushing image to $registry_user_image failed"
41 Write-Host "No image found at $registry_user_image or $registry_central_image; rebuilding"
42 docker build --no-cache -t "$registry_user_image" .
44 Write-Host "Container build failed"
45 docker logout "$registry_uri"
50 docker push "$registry_user_image"
52 docker logout "$registry_uri"
54 Write-Host "Pushing image to $registry_user_image failed"