Browse code

Windows CI: Making dockerfile WAAAAAY faster

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/01/31 13:50:11
Showing 1 changed files
... ...
@@ -19,14 +19,7 @@
19 19
 # Important notes:
20 20
 # ---------------
21 21
 #
22
-# Multiple commands in a single powershell RUN command are deliberately not done. This is
23
-# because PS doesn't have a concept quite like set -e in bash. It would be possible to use 
24
-# try-catch script blocks, but that would make this file unreadable. The problem is that
25
-# if there are two commands eg "RUN powershell -command fail; succeed", as far as docker
26
-# would be concerned, the return code from the overall RUN is succeed. This doesn't apply to
27
-# RUN which uses cmd as the command interpreter such as "RUN fail; succeed".
28
-#
29
-# 'sleep 5' is a deliberate workaround for a current problem on containers in Windows 
22
+# 'Start-Sleep' is a deliberate workaround for a current problem on containers in Windows 
30 23
 # Server 2016. It ensures that the network is up and available for when the command is
31 24
 # network related. This bug is being tracked internally at Microsoft and exists in TP4.
32 25
 # Generally sleep 1 or 2 is probably enough, but making it 5 to make the build file
... ...
@@ -39,55 +32,70 @@
39 39
 # Don't try to use a volume for passing the source through. The cygwin posix utilities will
40 40
 # balk at reparse points. Again, see the example at the top of this file on how use a volume
41 41
 # to get the built binary out of the container.
42
+#
43
+# The steps are minimised dramatically to improve performance (TP4 is slow on commit)
42 44
 
43 45
 FROM windowsservercore
44 46
 
45 47
 # Environment variable notes:
46
-#  - GOLANG_VERSION should be updated to be consistent with the Linux dockerfile.
48
+#  - GOLANG_VERSION must consistent with 'Dockerfile' used by Linux'.
47 49
 #  - FROM_DOCKERFILE is used for detection of building within a container.
48 50
 ENV GOLANG_VERSION=1.5.3 \
49
-    GIT_VERSION=2.7.0 \
51
+    GIT_LOCATION=https://github.com/git-for-windows/git/releases/download/v2.7.1.windows.2/Git-2.7.1.2-64-bit.exe \
50 52
     RSRC_COMMIT=ba14da1f827188454a4591717fff29999010887f \
51 53
     GOPATH=C:/go;C:/go/src/github.com/docker/docker/vendor \
52 54
     FROM_DOCKERFILE=1
53 55
 
54
-# Make sure we're in temp for the downloads
55
-WORKDIR c:/windows/temp
56
-
57
-# Download everything else we need to install
58
-# We want a 64-bit make.exe, not 16 or 32-bit. This was hard to find, so documenting the links
59
-#  - http://sourceforge.net/p/mingw-w64/wiki2/Make/ -->
60
-#  - http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/ -->
61
-#  - http://sourceforge.net/projects/mingw-w64/files/External binary packages %28Win64 hosted%29/make/
62
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile make.zip http://downloads.sourceforge.net/project/mingw-w64/External%20binary%20packages%20%28Win64%20hosted%29/make/make-3.82.90-20111115.zip
63
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile gcc.zip http://downloads.sourceforge.net/project/tdm-gcc/TDM-GCC%205%20series/5.1.0-tdm64-1/gcc-5.1.0-tdm64-1-core.zip 
64
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile runtime.zip http://downloads.sourceforge.net/project/tdm-gcc/MinGW-w64%20runtime/GCC%205%20series/mingw64runtime-v4-git20150618-gcc5-tdm64-1.zip
65
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile binutils.zip http://downloads.sourceforge.net/project/tdm-gcc/GNU%20binutils/binutils-2.25-tdm64-1.zip
66
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile 7zsetup.exe http://www.7-zip.org/a/7z1514-x64.exe 
67
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile lzma.7z http://www.7-zip.org/a/lzma1514.7z
68
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile gitsetup.exe https://github.com/git-for-windows/git/releases/download/v%GIT_VERSION%.windows.1/Git-%GIT_VERSION%-64-bit.exe
69
-RUN powershell -command sleep 5; Invoke-WebRequest -UserAgent 'DockerCI' -outfile go.msi https://storage.googleapis.com/golang/go%GOLANG_VERSION%.windows-amd64.msi
70
-
71
-# Path
72
-RUN setx /M Path "c:\git\cmd;c:\git\bin;c:\git\usr\bin;%Path%;c:\gcc\bin;c:\7zip"
73
-
74
-# Install and expand the bits we downloaded. 
75
-# Note: The git, 7z and go.msi installers execute asynchronously. 
76
-RUN powershell -command start-process .\gitsetup.exe -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES /CLOSEAPPLICATIONS /DIR=c:\git' -Wait
77
-RUN powershell -command start-process .\7zsetup -ArgumentList '/S /D=c:/7zip' -Wait
78
-RUN powershell -command start-process .\go.msi -ArgumentList '/quiet' -Wait
79
-RUN powershell -command Expand-Archive gcc.zip \gcc -Force 
80
-RUN powershell -command Expand-Archive runtime.zip \gcc -Force 
81
-RUN powershell -command Expand-Archive binutils.zip \gcc -Force
82
-RUN powershell -command 7z e lzma.7z bin/lzma.exe
83
-RUN powershell -command 7z x make.zip  make-3.82.90-20111115/bin_amd64/make.exe 
84
-RUN powershell -command mv make-3.82.90-20111115/bin_amd64/make.exe /gcc/bin/ 
85
-
86
-# RSRC for manifest and icon	
87
-RUN powershell -command sleep 5 ; git clone https://github.com/akavel/rsrc.git c:\go\src\github.com\akavel\rsrc 
88
-RUN cd c:/go/src/github.com/akavel/rsrc && git checkout -q %RSRC_COMMIT% && go install -v
56
+WORKDIR c:/
89 57
 
58
+# Everything downloaded/installed in one go (better performance, esp on TP4)
59
+RUN \
60
+ setx /M Path "c:\git\cmd;c:\git\bin;c:\git\usr\bin;%Path%;c:\gcc\bin;c:\go\bin" && \
61
+ setx GOROOT "c:\go" && \
62
+ powershell -command \
63
+  $ErrorActionPreference = 'Stop'; \
64
+  Start-Sleep -Seconds 5; \
65
+  Function Download-File([string] $source, [string] $target) { \
66
+   $wc = New-Object net.webclient; $wc.Downloadfile($source, $target) \
67
+  } \
68
+  \
69
+  Write-Host INFO: Downloading git...; \		
70
+  Download-File %GIT_LOCATION% gitsetup.exe; \
71
+  \
72
+  Write-Host INFO: Downloading go...; \
73
+  Download-File https://storage.googleapis.com/golang/go%GOLANG_VERSION%.windows-amd64.msi go.msi; \
74
+  \
75
+  Write-Host INFO: Downloading compiler 1 of 3...; \
76
+  Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/gcc.zip gcc.zip; \
77
+  \
78
+  Write-Host INFO: Downloading compiler 2 of 3...; \
79
+  Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/runtime.zip runtime.zip; \
80
+  \
81
+  Write-Host INFO: Downloading compiler 3 of 3...; \
82
+  Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/binutils.zip binutils.zip; \
83
+  \
84
+  Write-Host INFO: Installing git...; \
85
+  Start-Process gitsetup.exe -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES /CLOSEAPPLICATIONS /DIR=c:\git\' -Wait; \
86
+  \
87
+  Write-Host INFO: Installing go..."; \
88
+  Start-Process msiexec -ArgumentList '-i go.msi -quiet' -Wait; \
89
+  \
90
+  Write-Host INFO: Unzipping compiler...; \
91
+  c:\git\usr\bin\unzip.exe -q -o gcc.zip -d /c/gcc; \
92
+  c:\git\usr\bin\unzip.exe -q -o runtime.zip -d /c/gcc; \
93
+  c:\git\usr\bin\unzip.exe -q -o binutils.zip -d /c/gcc"; \
94
+  \
95
+  Write-Host INFO: Removing interim files; \
96
+  Remove-Item *.zip; \
97
+  Remove-Item go.msi; \
98
+  Remove-Item gitsetup.exe; \
99
+  \
100
+  Write-Host INFO: Cloning and installing RSRC; \
101
+  c:\git\bin\git.exe clone https://github.com/akavel/rsrc.git c:\go\src\github.com\akavel\rsrc; \
102
+  cd \go\src\github.com\akavel\rsrc; c:\git\bin\git.exe checkout -q %RSRC_COMMIT%; c:\go\bin\go.exe install -v; \
103
+  \
104
+  Write-Host INFO: Completed
105
+  
90 106
 # Prepare for building
91
-WORKDIR c:/
92 107
 COPY . /go/src/github.com/docker/docker
93 108