Commit e7df8f5b authored by Stefan Scherer's avatar Stefan Scherer

Refactor install-docker and docker-pull

parent 304705dc
Set-ExecutionPolicy Bypass -scope Process
New-Item -Type Directory -Path "$($env:ProgramFiles)\docker"
Write-Host "Downloading docker ..."
wget -outfile $env:TEMP\docker.zip "https://download.docker.com/win/static/edge/x86_64/docker-17.07.0-ce.zip"
Expand-Archive -Path $env:TEMP\docker.zip -DestinationPath $env:TEMP -Force
copy $env:TEMP\docker\*.exe $env:ProgramFiles\docker
Remove-Item $env:TEMP\docker.zip
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($env:ProgramFiles)\docker", [EnvironmentVariableTarget]::Machine)
$env:Path = $env:Path + ";$($env:ProgramFiles)\docker"
Write-Host "Registering docker service ..."
. dockerd --register-service -H npipe:// -H 0.0.0.0:2375 -G docker
Start-Service Docker
Write-Host "Install-PackageProvider ..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Write-Host "Install-Module ..."
Install-Module -Name DockerProvider -Force
Write-Host "Install-Package ..."
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
$ErrorActionStop = 'SilentlyContinue'
Install-Package -Name docker -ProviderName DockerProvider -RequiredVersion preview -Force
Set-PSRepository -InstallationPolicy Untrusted -Name PSGallery
Start-Service docker
Write-Host "Install-PackageProvider ..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Write-Host "Install-Module ..."
Install-Module -Name DockerMsftProviderInsider -Force
Write-Host "Install-Package ..."
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
Install-Package -Name docker -ProviderName DockerMsftProviderInsider -Force
Set-PSRepository -InstallationPolicy Untrusted -Name PSGallery
Start-Service docker
function DockerPull {
Param ([string]$image)
Write-Host Installing $image ...
$j = Start-Job -ScriptBlock { docker pull $args[0] } -ArgumentList $image
while ( $j.JobStateInfo.state -ne "Completed" -And $j.JobStateInfo.state -ne "Failed" ) {
Write-Host $j.JobStateInfo.state
Start-Sleep 10
}
$results = Receive-Job -Job $j
$results
}
DockerPull microsoft/windowsservercore:1709
DockerPull microsoft/nanoserver:1709
function DockerPull {
Param ([string]$image)
Write-Host Installing $image ...
$j = Start-Job -ScriptBlock { docker pull $args[0] } -ArgumentList $image
while ( $j.JobStateInfo.state -ne "Completed" -And $j.JobStateInfo.state -ne "Failed" ) {
Write-Host $j.JobStateInfo.state
Start-Sleep 10
}
$results = Receive-Job -Job $j
$results
}
DockerPull microsoft/windowsservercore-insider
DockerPull microsoft/nanoserver-insider
$images = ""
if (Test-Path env:docker_pull) {
$images = $env:docker_pull.split()
}
function DockerPull {
Param ([string]$image)
if ($image -eq "") {
return
}
Write-Host Installing $image ...
$j = Start-Job -ScriptBlock { docker pull $args[0] } -ArgumentList $image
while ( $j.JobStateInfo.state -ne "Completed" -And $j.JobStateInfo.state -ne "Failed" ) {
Write-Host $j.JobStateInfo.state
Start-Sleep 10
Start-Sleep 30
}
$results = Receive-Job -Job $j
$results
}
DockerPull microsoft/windowsservercore
DockerPull microsoft/nanoserver
$images | foreach {
DockerPull $_
}
$docker_provider = "ce"
$docker_version = "17.10.0"
if (Test-Path env:docker_provider) {
$docker_provider = $env:docker_provider
}
if (Test-Path env:docker_version) {
$docker_version = $env:docker_version
}
if ($docker_provider -eq "ce") {
Set-ExecutionPolicy Bypass -scope Process
New-Item -Type Directory -Path "$($env:ProgramFiles)\docker"
Write-Host "Downloading docker $docker_version ..."
wget -outfile $env:TEMP\docker.zip "https://download.docker.com/win/static/edge/x86_64/docker-{0}-ce.zip" -f $docker_version
Expand-Archive -Path $env:TEMP\docker.zip -DestinationPath $env:TEMP -Force
copy $env:TEMP\docker\*.exe $env:ProgramFiles\docker
Remove-Item $env:TEMP\docker.zip
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($env:ProgramFiles)\docker", [EnvironmentVariableTarget]::Machine)
$env:Path = $env:Path + ";$($env:ProgramFiles)\docker"
Write-Host "Registering docker service ..."
. dockerd --register-service
} else {
Write-Host "Install-PackageProvider ..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Write-Host "Install-Module $docker_provider ..."
Install-Module -Name $docker_provider -Force
Write-Host "Install-Package version $docker_version ..."
Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
$ErrorActionStop = 'SilentlyContinue'
Install-Package -Name docker -ProviderName DockerProvider -RequiredVersion $docker_version -Force
Set-PSRepository -InstallationPolicy Untrusted -Name PSGallery
}
Write-Host "Starting docker ..."
Start-Service docker
......@@ -43,10 +43,15 @@
"type": "windows-restart"
},
{
"environment_vars": [
"docker_images={{user `docker_images`}}",
"docker_provider={{user `docker_provider`}}",
"docker_version={{user `docker_version`}}"
],
"scripts": [
"./scripts/docker/add-docker-group.ps1",
"./scripts/docker/10/install-docker.ps1",
"./scripts/docker/docker-pull-async.ps1",
"./scripts/docker/install-docker.ps1",
"./scripts/docker/docker-pull.ps1",
"./scripts/docker/open-docker-insecure-port.ps1",
"./scripts/docker/open-docker-swarm-ports.ps1",
"./scripts/docker/remove-docker-key-json.ps1",
......@@ -64,6 +69,9 @@
}
],
"variables": {
"docker_images": "microsoft/windowsservercore microsoft/nanoserver",
"docker_provider": "ce",
"docker_version": "17.10.0",
"source_path": "path-to.vmx"
}
}
......
......@@ -137,11 +137,16 @@
"type": "windows-restart"
},
{
"environment_vars": [
"docker_images={{user `docker_images`}}",
"docker_provider={{user `docker_provider`}}",
"docker_version={{user `docker_version`}}"
],
"scripts": [
"./scripts/docker/add-docker-group.ps1",
"./scripts/docker/set-winrm-automatic.ps1",
"./scripts/docker/2016/install-docker-ee-preview.ps1",
"./scripts/docker/docker-pull-async.ps1",
"./scripts/docker/install-docker.ps1",
"./scripts/docker/docker-pull.ps1",
"./scripts/docker/open-docker-insecure-port.ps1",
"./scripts/docker/open-docker-swarm-ports.ps1",
"./scripts/docker/remove-docker-key-json.ps1",
......@@ -164,6 +169,9 @@
"autounattend": "./answer_files/2016_core/Autounattend.xml",
"disk_size": "61440",
"disk_type_id": "1",
"docker_images": "microsoft/windowsservercore microsoft/nanoserver",
"docker_provider": "DockerProvider",
"docker_version": "stable",
"headless": "false",
"iso_checksum": "70721288BBCDFE3239D8F8C0FAE55F1F",
"iso_checksum_type": "md5",
......
......@@ -38,11 +38,16 @@
"type": "windows-restart"
},
{
"environment_vars": [
"docker_images={{user `docker_images`}}",
"docker_provider={{user `docker_provider`}}",
"docker_version={{user `docker_version`}}"
],
"scripts": [
"./scripts/docker/add-docker-group.ps1",
"./scripts/docker/disable-windows-defender.ps1",
"./scripts/docker/2016/install-docker.ps1",
"./scripts/docker/docker-pull-async.ps1",
"./scripts/docker/install-docker.ps1",
"./scripts/docker/docker-pull.ps1",
"./scripts/docker/remove-docker-key-json.ps1"
],
"type": "powershell"
......@@ -53,6 +58,9 @@
"azure_ad_tenant_id": "{{env `PACKER_AZURE_AD_TENANT_ID`}}",
"azure_subscription_id": "{{env `PACKER_AZURE_SUBSCRIPTION_ID`}}",
"client_secret": "{{env `PACKER_AZURE_CLIENT_SECRET`}}",
"docker_images": "microsoft/windowsservercore microsoft/nanoserver",
"docker_provider": "DockerProvider",
"docker_version": "stable",
"headless": "false",
"object_id": "{{env `PACKER_AZURE_OBJECT_ID`}}",
"resource_group": "{{env `PACKER_AZURE_RESOURCE_GROUP`}}",
......
......@@ -138,11 +138,16 @@
"type": "windows-restart"
},
{
"environment_vars": [
"docker_images={{user `docker_images`}}",
"docker_provider={{user `docker_provider`}}",
"docker_version={{user `docker_version`}}"
],
"scripts": [
"./scripts/docker/add-docker-group.ps1",
"./scripts/docker/set-winrm-automatic.ps1",
"./scripts/docker/2016/install-docker-ee-preview.ps1",
"./scripts/docker/docker-pull-1709-async.ps1",
"./scripts/docker/install-docker.ps1",
"./scripts/docker/docker-pull.ps1",
"./scripts/docker/open-docker-insecure-port.ps1",
"./scripts/docker/open-docker-swarm-ports.ps1",
"./scripts/docker/remove-docker-key-json.ps1",
......@@ -166,6 +171,9 @@
"autounattend": "./answer_files/server_1709/Autounattend.xml",
"disk_size": "61440",
"disk_type_id": "1",
"docker_images": "microsoft/windowsservercore:1709 microsoft/nanoserver:1709",
"docker_provider": "DockerProvider",
"docker_version": "preview",
"headless": "false",
"iso_checksum": "ca1108d5be2c091bfb57e8f3db3be1e8baa9c32802131f7a6e43e63f7b596591",
"iso_checksum_type": "sha256",
......
......@@ -125,10 +125,15 @@
"type": "windows-restart"
},
{
"environment_vars": [
"docker_images={{user `docker_images`}}",
"docker_provider={{user `docker_provider`}}",
"docker_version={{user `docker_version`}}"
],
"scripts": [
"./scripts/docker/add-docker-group.ps1",
"./scripts/docker/2016/install-docker-ee-preview.ps1",
"./scripts/docker/docker-pull-insider-async.ps1",
"./scripts/docker/install-docker.ps1",
"./scripts/docker/docker-pull.ps1",
"./scripts/docker/open-docker-insecure-port.ps1",
"./scripts/docker/open-docker-swarm-ports.ps1",
"./scripts/docker/remove-docker-key-json.ps1",
......@@ -141,6 +146,9 @@
"autounattend": "./answer_files/server_insider/Autounattend.xml",
"disk_size": "61440",
"disk_type_id": "1",
"docker_images": "microsoft/windowsservercore-insider microsoft/nanoserver-insider",
"docker_provider": "DockerProvider",
"docker_version": "preview",
"headless": "false",
"iso_checksum": "dd412bd5c7d29fa5166a10f4cb36dacf7fcb605a5b8e8a6e8fa87e13aed6851d",
"iso_checksum_type": "sha256",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment