dockerfile: reduce build time for WSC-based image
Turns out that caching the golang:windowsservercore-ltsc2022 image between GithubAction workflow runs is a bad idea because `docker load` command still takes too long to load image from cached archive (~9-10min on standard windows runner). And after that runner still needs to build the neo-go image itself. However, standard GA windows runner is supplied with prefetched latest mcr.microsoft.com/windows/servercore:ltsc2022 image, so using it costs almost nothing. Thus, the other approach is implemented: we use standard mcr.microsoft.com/windows/servercore:ltsc2022 image as both build-base and final-base. Then we install all required tools for building neo-go manually on build-base image (these tools are git and go 1.17). Compared to the first approach, the publishing job (included build and publish to DockerHub) takes ~7-8min to finish.
This commit is contained in:
parent
2cf15ea4e3
commit
0760e5486b
2 changed files with 24 additions and 1 deletions
3
.github/workflows/publish_to_dockerhub.yml
vendored
3
.github/workflows/publish_to_dockerhub.yml
vendored
|
@ -138,6 +138,9 @@ jobs:
|
|||
# Allows to fetch all history for all branches and tags. Need this for proper versioning.
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Show docker images
|
||||
run: docker images
|
||||
|
||||
- name: Build image
|
||||
run: make image-wsc
|
||||
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
# Builder image
|
||||
FROM golang:windowsservercore-ltsc2022 as builder
|
||||
FROM mcr.microsoft.com/windows/servercore:ltsc2022 as builder
|
||||
|
||||
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';", "$ProgressPreference = 'SilentlyContinue';"]
|
||||
|
||||
ENV GIT_VERSION=2.23.0
|
||||
|
||||
ENV GIT_TAG=v2.23.0.windows.1
|
||||
|
||||
ENV GIT_DOWNLOAD_URL=https://github.com/git-for-windows/git/releases/download/v2.23.0.windows.1/MinGit-2.23.0-64-bit.zip
|
||||
|
||||
ENV GIT_DOWNLOAD_SHA256=8f65208f92c0b4c3ae4c0cf02d4b5f6791d539cd1a07b2df62b7116467724735
|
||||
|
||||
RUN Write-Host ('Downloading {0} ...' -f $env:GIT_DOWNLOAD_URL); [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri $env:GIT_DOWNLOAD_URL -OutFile 'git.zip'; Write-Host ('Verifying sha256 ({0}) ...' -f $env:GIT_DOWNLOAD_SHA256); if ((Get-FileHash git.zip -Algorithm sha256).Hash -ne $env:GIT_DOWNLOAD_SHA256) { Write-Host 'FAILED!'; exit 1; }; Write-Host 'Expanding ...'; Expand-Archive -Path git.zip -DestinationPath C:\git\.; Write-Host 'Removing ...'; Remove-Item git.zip -Force; Write-Host 'Updating PATH ...'; $env:PATH = 'C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin;' + $env:PATH; [Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine); Write-Host 'Verifying install ("git version") ...'; git version; Write-Host 'Complete.';
|
||||
|
||||
ENV GOPATH=C:\\go
|
||||
|
||||
RUN $newPath = ('{0}\bin;C:\Program Files\Go\bin;{1}' -f $env:GOPATH, $env:PATH); Write-Host ('Updating PATH: {0}' -f $newPath); [Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine);
|
||||
|
||||
ENV GOLANG_VERSION=1.17.6
|
||||
|
||||
RUN $url = 'https://dl.google.com/go/go1.17.6.windows-amd64.zip'; Write-Host ('Downloading {0} ...' -f $url); [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri $url -OutFile 'go.zip'; $sha256 = '5bf8f87aec7edfc08e6bc845f1c30dba6de32b863f89ae46553ff4bbcc1d4954'; Write-Host ('Verifying sha256 ({0}) ...' -f $sha256); if ((Get-FileHash go.zip -Algorithm sha256).Hash -ne $sha256) { Write-Host 'FAILED!'; exit 1; }; Write-Host 'Expanding ...'; Expand-Archive go.zip -DestinationPath C:\; Write-Host 'Moving ...'; Move-Item -Path C:\go -Destination 'C:\Program Files\Go'; Write-Host 'Removing ...'; Remove-Item go.zip -Force; Write-Host 'Verifying install ("go version") ...'; go version; Write-Host 'Complete.';
|
||||
|
||||
COPY . /neo-go
|
||||
|
||||
|
|
Loading…
Reference in a new issue