Skip to content

Commit

Permalink
Merge pull request #377 from infosiftr/go-1.17-windows
Browse files Browse the repository at this point in the history
For Go 1.17+, move the Windows install to C:\Program Files\Go
  • Loading branch information
yosifkit committed Jul 19, 2021
2 parents 7f1f587 + 272431a commit 91fcb9a
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 24 deletions.
6 changes: 4 additions & 2 deletions 1.15/windows/nanoserver-1809/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion 1.15/windows/windowsservercore-1809/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion 1.15/windows/windowsservercore-ltsc2016/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions 1.16/windows/nanoserver-1809/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion 1.16/windows/windowsservercore-1809/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion 1.16/windows/windowsservercore-ltsc2016/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions 1.17-rc/windows/nanoserver-1809/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions 1.17-rc/windows/windowsservercore-1809/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions 1.17-rc/windows/windowsservercore-ltsc2016/Dockerfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions Dockerfile-windows-nanoserver.template
Expand Up @@ -5,18 +5,39 @@ SHELL ["cmd", "/S", "/C"]
# no Git installed (intentionally)
# -- Nano Server is "Windows Slim"

# 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
{{
def install_directory:
if [ "1.15", "1.16" ] | index(env.version) then
"C:\\go"
else
"C:\\Program Files\\Go"
end
-}}
{{ if install_directory == "C:\\go" then ( -}}
# ideally, this would be C:\go to match Linux a bit closer, but C:\go was the default install path for Go itself on Windows
ENV GOPATH C:\\gopath
# (https://golang.org/cl/283600)
{{ ) else ( -}}
# for 1.17+, we'll follow the (new) Go upstream default for install (https://golang.org/cl/283600), which frees up C:\go to be the default GOPATH and thus match the Linux images more closely (https://github.com/docker-library/golang/issues/288)
ENV GOPATH C:\\go
# HOWEVER, please note that it is the Go upstream intention to remove GOPATH support entirely: https://blog.golang.org/go116-module-changes
{{ ) end -}}

# PATH isn't actually set in the Docker image, so we have to set it from within the container
USER ContainerAdministrator
RUN setx /m PATH "%GOPATH%\bin;C:\go\bin;%PATH%"
RUN setx /m PATH "%GOPATH%\bin;{{ install_directory }}\bin;%PATH%"
USER ContainerUser
# doing this first to share cache across versions more aggressively

ENV GOLANG_VERSION {{ .version }}

COPY --from=golang:{{ .version }}-windowsservercore-{{ env.windowsRelease }} C:\\go C:\\go
# Docker's Windows path parsing is absolutely *cursed*; please just trust me on this one -Tianon
COPY --from=golang:{{ .version }}-windowsservercore-{{ env.windowsRelease }} {{
install_directory
| gsub("\\\\"; "\\\\")
| [ . , . ]
| @json
}}
RUN go version

WORKDIR $GOPATH
24 changes: 22 additions & 2 deletions Dockerfile-windows-servercore.template
Expand Up @@ -37,11 +37,26 @@ RUN Write-Host ('Downloading {0} ...' -f $env:GIT_DOWNLOAD_URL); \
\
Write-Host 'Complete.';

# 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
{{
def install_directory:
if [ "1.15", "1.16" ] | index(env.version) then
"C:\\go"
else
"C:\\Program Files\\Go"
end
-}}
{{ if install_directory == "C:\\go" then ( -}}
# ideally, this would be C:\go to match Linux a bit closer, but C:\go was the default install path for Go itself on Windows
ENV GOPATH C:\\gopath
# (https://golang.org/cl/283600)
{{ ) else ( -}}
# for 1.17+, we'll follow the (new) Go upstream default for install (https://golang.org/cl/283600), which frees up C:\go to be the default GOPATH and thus match the Linux images more closely (https://github.com/docker-library/golang/issues/288)
ENV GOPATH C:\\go
# HOWEVER, please note that it is the Go upstream intention to remove GOPATH support entirely: https://blog.golang.org/go116-module-changes
{{ ) end -}}

# PATH isn't actually set in the Docker image, so we have to set it from within the container
RUN $newPath = ('{0}\bin;C:\go\bin;{1}' -f $env:GOPATH, $env:PATH); \
RUN $newPath = ('{0}\bin;{{ install_directory }}\bin;{1}' -f $env:GOPATH, $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine);
# doing this first to share cache across versions more aggressively
Expand All @@ -61,6 +76,11 @@ RUN $url = '{{ .arches["windows-amd64"].url }}'; \
\
Write-Host 'Expanding ...'; \
Expand-Archive go.zip -DestinationPath C:\; \
{{ if install_directory != "C:\\go" then ( -}}
\
Write-Host 'Moving ...'; \
Move-Item -Path C:\go -Destination '{{ install_directory }}'; \
{{ ) else "" end -}}
\
Write-Host 'Removing ...'; \
Remove-Item go.zip -Force; \
Expand Down
2 changes: 1 addition & 1 deletion apply-templates.sh
Expand Up @@ -7,7 +7,7 @@ jqt='.jq-template.awk'
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
jqt="$BASHBREW_SCRIPTS/jq-template.awk"
elif [ "$BASH_SOURCE" -nt "$jqt" ]; then
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/5f0c26381fb7cc78b2d217d58007800bdcfbcfa1/scripts/jq-template.awk'
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/1da7341a79651d28fbcc3d14b9176593c4231942/scripts/jq-template.awk'
fi

if [ "$#" -eq 0 ]; then
Expand Down

0 comments on commit 91fcb9a

Please sign in to comment.