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
--config
"windows-docker.conf" 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
--config
"windows-docker.conf" pull
"$registry_user_image"
21 Write-Host "User image $registry_user_image already exists; not rebuilding"
22 docker
--config
"windows-docker.conf" logout
"$registry_uri"
26 # if the image already exists upstream, copy it
27 docker
--config
"windows-docker.conf" pull
"$registry_central_image"
29 Write-Host "Copying central image $registry_central_image to user image $registry_user_image"
30 docker
--config
"windows-docker.conf" tag
"$registry_central_image" "$registry_user_image"
31 docker
--config
"windows-docker.conf" push
"$registry_user_image"
33 docker
--config
"windows-docker.conf" 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
--config
"windows-docker.conf" build
--no-cache
-t
"$registry_user_image" .
44 Write-Host "Container build failed"
45 docker
--config
"windows-docker.conf" logout
"$registry_uri"
50 docker
--config
"windows-docker.conf" push
"$registry_user_image"
52 docker
--config
"windows-docker.conf" logout
"$registry_uri"
54 Write-Host "Pushing image to $registry_user_image failed"