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] 9 10 Set-Location -Path ".\.gitlab-ci\windows" 11 12 docker --config "windows-docker.conf" login -u "$registry_username" -p "$registry_password" "$registry_uri" 13 if (!$?) { 14 Write-Host "docker login failed to $registry_uri" 15 Exit 1 16 } 17 18 # if the image already exists, don't rebuild it 19 docker --config "windows-docker.conf" pull "$registry_user_image" 20 if ($?) { 21 Write-Host "User image $registry_user_image already exists; not rebuilding" 22 docker --config "windows-docker.conf" logout "$registry_uri" 23 Exit 0 24 } 25 26 # if the image already exists upstream, copy it 27 docker --config "windows-docker.conf" pull "$registry_central_image" 28 if ($?) { 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" 32 $pushstatus = $? 33 docker --config "windows-docker.conf" logout "$registry_uri" 34 if (!$pushstatus) { 35 Write-Host "Pushing image to $registry_user_image failed" 36 Exit 1 37 } 38 Exit 0 39 } 40 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" . 43 if (!$?) { 44 Write-Host "Container build failed" 45 docker --config "windows-docker.conf" logout "$registry_uri" 46 Exit 1 47 } 48 Get-Date 49 50 docker --config "windows-docker.conf" push "$registry_user_image" 51 $pushstatus = $? 52 docker --config "windows-docker.conf" logout "$registry_uri" 53 if (!$pushstatus) { 54 Write-Host "Pushing image to $registry_user_image failed" 55 Exit 1 56 } 57