|
| 1 | +ARG SERVERCORE_VERSION |
| 2 | + |
| 3 | +FROM mcr.microsoft.com/windows/servercore:${SERVERCORE_VERSION} as builder |
| 4 | +SHELL ["powershell", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] |
| 5 | +RUN if (-not (Get-Command Expand-7Zip -ErrorAction Ignore)) { \ |
| 6 | + Install-PackageProvider -Name NuGet -Force -Verbose; \ |
| 7 | + Install-Module -Name 7Zip4Powershell -Repository PSGallery -Force -Verbose; \ |
| 8 | + if(-not $?) { \ |
| 9 | + Write-Error "Failed to install package"; \ |
| 10 | + Exit 1; \ |
| 11 | + } \ |
| 12 | + } |
| 13 | +ENV K8S_VERSION v1.19.7 |
| 14 | +RUN $URL = ('https://dl.k8s.io/{0}/kubernetes-node-windows-amd64.tar.gz' -f $env:K8S_VERSION); \ |
| 15 | + \ |
| 16 | + function Expand-GZip ($inFile, $outFile) { \ |
| 17 | + $input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read); \ |
| 18 | + $output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None); \ |
| 19 | + $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress); \ |
| 20 | + try { \ |
| 21 | + if (!$input -or !$output -or !$gzipStream) { \ |
| 22 | + Write-Error "Failed to Unzip the archive"; \ |
| 23 | + Exit 1; \ |
| 24 | + } \ |
| 25 | + $buffer = New-Object byte[](1024); \ |
| 26 | + while ($true) { \ |
| 27 | + $read = $gzipstream.Read($buffer, 0, 1024); \ |
| 28 | + if ($read -le 0 ) { \ |
| 29 | + break; \ |
| 30 | + } \ |
| 31 | + $output.Write($buffer, 0, $read); \ |
| 32 | + } \ |
| 33 | + } finally { \ |
| 34 | + $gzipStream.Close(); \ |
| 35 | + $output.Close(); \ |
| 36 | + $input.Close(); \ |
| 37 | + } \ |
| 38 | + }; \ |
| 39 | + \ |
| 40 | + Write-Host ('Downloading Kubernetes from {0} ...' -f $URL); \ |
| 41 | + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \ |
| 42 | + Invoke-WebRequest -UseBasicParsing -OutFile c:\kubernetes.tar.gz -Uri $URL; \ |
| 43 | + \ |
| 44 | + Write-Host 'Expanding ...'; \ |
| 45 | + Expand-GZip c:\kubernetes.tar.gz c:\kubernetes.tar; \ |
| 46 | + Expand-7Zip c:\kubernetes.tar c:\; \ |
| 47 | + \ |
| 48 | + Write-Host 'Complete.' |
| 49 | + |
| 50 | +# FROM mcr.microsoft.com/powershell:nanoserver-${SERVERCORE_VERSION} |
| 51 | +# USER ContainerAdministrator |
| 52 | +# SHELL ["pwsh.exe", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] |
| 53 | +RUN $URL = 'https://github.com/rancher/azure-cli/releases/download/v0.0.2/dist.azure-cli.zip'; \ |
| 54 | + \ |
| 55 | + Write-Host ('Downloading azure-cli from {0} ...' -f $URL); \ |
| 56 | + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \ |
| 57 | + Invoke-WebRequest -UseBasicParsing -OutFile c:\azure-cli.zip -Uri $URL; \ |
| 58 | + \ |
| 59 | + Write-Host 'Expanding ...'; \ |
| 60 | + Expand-Archive -Force -Path c:\azure-cli.zip -DestinationPath c:\azure-cli; \ |
| 61 | + Remove-Item -Force -Path c:\azure-cli.zip; \ |
| 62 | + \ |
| 63 | + Write-Host 'Complete.' |
| 64 | +# COPY --from=builder /Windows/System32/netapi32.dll /Windows/System32/ |
| 65 | +RUN Move-Item -Path /kubernetes/node/bin/kubectl.exe -Destination /Windows |
| 66 | +RUN New-Item -Force -ItemType Directory -Path /etc; \ |
| 67 | + New-Item -Force -ItemType Directory -Path /etc/kubernetes; \ |
| 68 | + New-Item -Force -ItemType Directory -Path /etc/kubernetes/bin; \ |
| 69 | + Move-Item -Path /kubernetes/node/bin/*.exe -Destination /etc/kubernetes/bin/ |
| 70 | +COPY windows/entrypoint.ps1 /usr/bin/ |
0 commit comments