forked from pnp/powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublish-UnpublishedImage.ps1
More file actions
65 lines (65 loc) · 2.49 KB
/
Copy pathPublish-UnpublishedImage.ps1
File metadata and controls
65 lines (65 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Param(
[Parameter(Position = 0,
Mandatory = $true,
ValueFromPipeline = $false)]
[String]
$PS_MODULE_NAME,
[Parameter(Position = 1,
Mandatory = $true,
ValueFromPipeline = $false)]
[String]
$DOCKER_USERNAME,
[Parameter(Position = 2,
Mandatory = $true,
ValueFromPipeline = $false)]
[String]
$DOCKER_ORG,
[Parameter(Position = 3,
Mandatory = $true,
ValueFromPipeline = $false)]
[String]
$DOCKER_IMAGE_NAME,
[Parameter(Position = 4,
Mandatory = $true,
ValueFromPipeline = $false)]
[Security.SecureString]
$DOCKER_PASSWORD,
[Parameter(Position = 5,
Mandatory = $false,
ValueFromPipeline = $false)]
[String]
$DOCKER_INSTALL_USER = "ContainerAdministrator",
[Parameter(Position = 6,
Mandatory = $false,
ValueFromPipeline = $false)]
[bool]
$SKIP_PUBLISHER_CHECK = $false,
[Parameter(Position = 7,
Mandatory = $false,
ValueFromPipeline = $false)]
[String]
$DOCKER_IMAGE_SUFFIX_ARRAY = "nanoserver-ltsc2022"
)
$publishedImageVersions = (Invoke-RestMethod https://registry.hub.docker.com/v2/repositories/$DOCKER_ORG/$DOCKER_IMAGE_NAME/tags?page_size=10240).results | % {
$_.name
}
$moduleVersions = Find-Module $PS_MODULE_NAME -AllVersions;
[array]::Reverse($moduleVersions);
$moduleVersions | % {
$moduleVersion = $_.Version;
$DOCKER_IMAGE_SUFFIX_ARRAY.Split( "," ) | % {
$baseImageSuffix = $_;
$imageVersion = "$moduleVersion-$baseImageSuffix";
Write-Host "Checking $imageVersion"
if ( !( $publishedImageVersions -contains $imageVersion ) ) {
docker build --build-arg "PNP_MODULE_VERSION=$moduleVersion" --build-arg "BASE_IMAGE_SUFFIX=$baseImageSuffix" --build-arg "INSTALL_USER=$DOCKER_INSTALL_USER" --build-arg "SKIP_PUBLISHER_CHECK=$SKIP_PUBLISHER_CHECK" ./docker -f ./docker/pnppowershell.dockerFile --tag $DOCKER_ORG/$DOCKER_IMAGE_NAME`:$imageVersion;
$plainStringPassword = [System.Net.NetworkCredential]::new("", $DOCKER_PASSWORD).Password;
docker login -u $DOCKER_USERNAME -p "$plainStringPassword";
docker push $DOCKER_ORG/$DOCKER_IMAGE_NAME`:$imageVersion;
if ( $baseImageSuffix -eq "alpine-3.20") {
docker image tag $DOCKER_ORG/$DOCKER_IMAGE_NAME`:$imageVersion $DOCKER_ORG/$DOCKER_IMAGE_NAME`:latest;
docker push $DOCKER_ORG/$DOCKER_IMAGE_NAME`:latest;
}
}
}
}