|
| 1 | +FROM mcr.microsoft.com/windows/servercore:ltsc2016 |
| 2 | + |
| 3 | +# $ProgressPreference: https://github.com/PowerShell/PowerShell/issues/2138#issuecomment-251261324 |
| 4 | +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] |
| 5 | + |
| 6 | +# install MinGit (especially for "go get") |
| 7 | +# https://blogs.msdn.microsoft.com/visualstudioalm/2016/09/03/whats-new-in-git-for-windows-2-10/ |
| 8 | +# "Essentially, it is a Git for Windows that was stripped down as much as possible without sacrificing the functionality in which 3rd-party software may be interested." |
| 9 | +# "It currently requires only ~45MB on disk." |
| 10 | +ENV GIT_VERSION 2.11.1 |
| 11 | +ENV GIT_TAG v${GIT_VERSION}.windows.1 |
| 12 | +ENV GIT_DOWNLOAD_URL https://github.com/git-for-windows/git/releases/download/${GIT_TAG}/MinGit-${GIT_VERSION}-64-bit.zip |
| 13 | +ENV GIT_DOWNLOAD_SHA256 668d16a799dd721ed126cc91bed49eb2c072ba1b25b50048280a4e2c5ed56e59 |
| 14 | +# steps inspired by "chcolateyInstall.ps1" from "git.install" (https://chocolatey.org/packages/git.install) |
| 15 | +RUN Write-Host ('Downloading {0} ...' -f $env:GIT_DOWNLOAD_URL); \ |
| 16 | + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \ |
| 17 | + Invoke-WebRequest -Uri $env:GIT_DOWNLOAD_URL -OutFile 'git.zip'; \ |
| 18 | + \ |
| 19 | + Write-Host ('Verifying sha256 ({0}) ...' -f $env:GIT_DOWNLOAD_SHA256); \ |
| 20 | + if ((Get-FileHash git.zip -Algorithm sha256).Hash -ne $env:GIT_DOWNLOAD_SHA256) { \ |
| 21 | + Write-Host 'FAILED!'; \ |
| 22 | + exit 1; \ |
| 23 | + }; \ |
| 24 | + \ |
| 25 | + Write-Host 'Expanding ...'; \ |
| 26 | + Expand-Archive -Path git.zip -DestinationPath C:\git\.; \ |
| 27 | + \ |
| 28 | + Write-Host 'Removing ...'; \ |
| 29 | + Remove-Item git.zip -Force; \ |
| 30 | + \ |
| 31 | + Write-Host 'Updating PATH ...'; \ |
| 32 | + $env:PATH = 'C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin;' + $env:PATH; \ |
| 33 | + [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); \ |
| 34 | + \ |
| 35 | + Write-Host 'Verifying install ...'; \ |
| 36 | + Write-Host ' git --version'; git --version; \ |
| 37 | + \ |
| 38 | + Write-Host 'Complete.'; |
| 39 | + |
| 40 | +# ideally, this would be C:\go to match Linux a bit closer, but C:\go is the recommended install path for Go itself on Windows |
| 41 | +ENV GOPATH C:\\gopath |
| 42 | + |
| 43 | +# PATH isn't actually set in the Docker image, so we have to set it from within the container |
| 44 | +RUN $newPath = ('{0}\bin;C:\go\bin;{1}' -f $env:GOPATH, $env:PATH); \ |
| 45 | + Write-Host ('Updating PATH: {0}' -f $newPath); \ |
| 46 | + [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine); |
| 47 | +# doing this first to share cache across versions more aggressively |
| 48 | + |
| 49 | +ENV GOLANG_VERSION 1.13beta1 |
| 50 | + |
| 51 | +RUN $url = ('https://golang.org/dl/go{0}.windows-amd64.zip' -f $env:GOLANG_VERSION); \ |
| 52 | + Write-Host ('Downloading {0} ...' -f $url); \ |
| 53 | + Invoke-WebRequest -Uri $url -OutFile 'go.zip'; \ |
| 54 | + \ |
| 55 | + $sha256 = '08098b4b0e1a105971d2fced2842e806f8ffa08973ae8781fd22dd90f76404fb'; \ |
| 56 | + Write-Host ('Verifying sha256 ({0}) ...' -f $sha256); \ |
| 57 | + if ((Get-FileHash go.zip -Algorithm sha256).Hash -ne $sha256) { \ |
| 58 | + Write-Host 'FAILED!'; \ |
| 59 | + exit 1; \ |
| 60 | + }; \ |
| 61 | + \ |
| 62 | + Write-Host 'Expanding ...'; \ |
| 63 | + Expand-Archive go.zip -DestinationPath C:\; \ |
| 64 | + \ |
| 65 | + Write-Host 'Verifying install ("go version") ...'; \ |
| 66 | + go version; \ |
| 67 | + \ |
| 68 | + Write-Host 'Removing ...'; \ |
| 69 | + Remove-Item go.zip -Force; \ |
| 70 | + \ |
| 71 | + Write-Host 'Complete.'; |
| 72 | + |
| 73 | +WORKDIR $GOPATH |
0 commit comments