Skip to content

Commit 8369761

Browse files
committed
moved away from editing dockerfiles with set_versions to using Docker ARG flags and a versions.ps1 user file. Allow switching the base docker image.
1 parent eaa8f42 commit 8369761

12 files changed

+136
-145
lines changed

.dockerignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
versions.ps1
2+
.dockerignore

Dockerfile_cef

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ RUN $env:Path = 'c:/Program Files/Git/bin/;' + $env:Path;setx /M PATH $env:Path;
44
RUN Invoke-WebRequest 'https://storage.googleapis.com/chrome-infra/depot_tools.zip' -OutFile 'C:/code/depot_tools.zip';
55
RUN Expand-Archive C:/code/depot_tools.zip -DestinationPath "C:/code/depot_tools";
66
RUN $env:Path = 'c:/code/depot_tools/;' + $env:Path;setx /M PATH $env:Path;
7-
ENV GN_DEFINES is_debug=false
7+
ARG GN_DEFINES="is_debug=false"
88
ENV DEPOT_TOOLS_WIN_TOOLCHAIN 0
99
ENV CEF_USE_GN 1
1010
ENV GYP_MSVS_VERSION 2017
11-
ENV DUAL_BUILD 0
12-
ENV GYP_DEFINES target_arch=x64
13-
RUN setX /M DEPOT_TOOLS_WIN_TOOLCHAIN 0;setX /M GYP_MSVS_VERSION 2017;setx /M GN_DEFINES "$env:GN_DEFINES";setx /M GYP_DEFINES "$env:GYP_DEFINES";
14-
ENV CHROME_BRANCH 3239
11+
ARG DUAL_BUILD="0"
12+
ARG GYP_DEFINES="target_arch=x64 "
13+
RUN setX /M DEPOT_TOOLS_WIN_TOOLCHAIN 0;setX /M GYP_MSVS_VERSION 2017;setx /M GN_DEFINES "$env:GN_DEFINES";setx /M GYP_DEFINES "$env:GYP_DEFINES";setx /M DUAL_BUILD "$env:DUAL_BUILD";
14+
ARG CHROME_BRANCH=3239
1515
ADD https://bitbucket.org/chromiumembedded/cef/raw/master/tools/automate/automate-git.py c:/code/automate/
1616
RUN cd c:/code/depot_tools/;update_depot_tools.bat;git checkout .\cipd.ps1;update_depot_tools.bat;
1717

1818
# Comment out the next step if you want to do it by hand
19-
ADD cef_build.ps1 c:/code
19+
ADD functions.ps1 cef_build.ps1 c:/code/
2020
RUN c:/code/cef_build.ps1
2121

2222

2323

2424

25-
26-
27-
25+
26+
27+

Dockerfile_cef_compiled

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
FROM vs
2+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
23
ADD binaries.zip c:/code/
34
RUN Expand-Archive c:\code\binaries.zip -DestinationPath "C:\code\binaries";

Dockerfile_cefsharp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ RUN MKDIR c:/code/cefsharp
33
WORKDIR c:/code/cefsharp
44
RUN $env:Path = 'c:/Program Files/Git/bin/;' + $env:Path;setx /M PATH $env:Path;
55
RUN git clone https://github.com/cefsharp/CefSharp.git .
6-
ENV CEFSHARP_BRANCH cefsharp/63
6+
ARG CEFSHARP_BRANCH cefsharp/63
77
#This line and the one two below are due to waiting to use the new vs2017 compat build script
88
RUN cp build.ps1 ../
99
RUN git checkout $env:CEFSHARP_BRANCH;
1010
RUN cp ../build.ps1 .
11-
ENV CEFSHARP_VERSION 63.0.90
12-
ENV CEF_VERSION_STR auto
13-
ENV CHROME_BRANCH 3239
11+
ARG CEFSHARP_VERSION 63.0.90
12+
ARG CEF_VERSION_STR auto
13+
ARG CHROME_BRANCH 3239
1414
ENV PACKAGE_SOURCE C:/code/cef-binary/cef-binary-master/NuGet
1515
ADD cefsharp_set_versions_and_restore.ps1 c:/code/cefsharp
1616
RUN ./cefsharp_set_versions_and_restore.ps1
@@ -19,4 +19,4 @@ RUN ./cefsharp_set_versions_and_restore.ps1
1919
ENV VS141COMNTOOLS C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build
2020
RUN [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;./build.ps1 -Target vs2017 -Version $env:CEFSHARP_VERSION -AssemblyVersion $env:CEFSHARP_VERSION;
2121
RUN cp $env:PACKAGE_SOURCE/*.nupkg C:/code/cefsharp/nuget/
22-
RUN Compress-Archive -Path C:/code/cefsharp/nuget/*.nupkg -CompressionLevel Fastest -DestinationPath C:\packages_cefsharp
22+
RUN Compress-Archive -Path C:/code/cefsharp/nuget/*.nupkg -CompressionLevel Fastest -DestinationPath C:\packages_cefsharp

Dockerfile_vs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM microsoft/dotnet-framework:4.7.1-windowsservercore
1+
ARGS BASE_DOCKER_FILE="microsoft/dotnet-framework:4.7.1-windowsservercore-1709"
2+
FROM $BASE_DOCKER_FILE
23
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
34

45
RUN mkdir c:\code\automate;mkdir c:\temp\;mkdir c:\code\depot_tools;

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ With the Azure F32 v2 host above the total estimated build time is about 3.5 hou
7979

8080

8181
## Build Process
82-
Once docker is setup and running copy this repo to a local folder. Edit set_version.ps1 and change the version strings to match what you want then run it to have it update the dockerfiles.
82+
Once docker is setup and running copy this repo to a local folder. Copy versions_src.ps1 to versions.ps1 and change the version strings to match what you want. NOTE BASE_DOCKER_FILE must match the same kernel as the host machine IF you are using process isolation mode. This means you cannot use the 1709 image on an older host and you can use and older image on a 1709 host. Either base file is fine however to use just match it to the host.
8383

84-
Next run build.ps1 and if you are lucky you will end up with a cefsharp_packages.zip file with all the nupkg files you need:) Beware that as docker can be flaky you may need to call build.ps1 a few times. It should largely just resume.
84+
Next run build.ps1 and if you are lucky you will end up with a cefsharp_packages.zip file with all the nupkg files you need:) Beware that as docker might be flaky you may need to call build.ps1 a few times. It should largely just resume.
8585

86-
To be safer you can run each build command by hand. The hardest (longest) build step if the CEF build at the start. You can comment out the last step in the dockerfile and manually do that step and commit it. To do so comment out the final build step in Dockerfile_cef then run the following:
86+
To be safer you can run the biggest build command by hand. The hardest (longest) build step if the CEF build at the start. You can comment out the last step in the dockerfile and manually do that step and commit it. Infact you can just docker run the build image from before than manually call cef_build.ps1 one or more times (it should do a decent job at auto-resuming) until success. If you are using a proper host with enough ram it should be able to automatically build 9 times out of 10 (if not higher) with its current redundant tries. Of course if you prefer to manually run the commands from it you can do that too. To do so comment out the final build step in Dockerfile_cef then run the following:
8787
```
8888
#So if the autmate-git.py doesn't work (if something errors out it doesn't always stop at the right point) try running the build steps manually that are there.
8989
# From the c:/code/chromium/src folder run the build hooks to download tools: gclient runhooks
@@ -94,8 +94,7 @@ To be safer you can run each build command by hand. The hardest (longest) build
9494
# cd C:/code/chromium/src/cef/tools/
9595
# C:/code/chromium/src/cef/tools/make_distrib.bat --ninja-build --allow-partial;
9696
# c:/code/chromium/src/cef/tools/make_distrib.bat --ninja-build --allow-partial --x64-build;
97-
98-
# Allow partial needed if not building debug builds
97+
# Allow partial needed if not building debug builds, make sure to run it when done or run the cef_build last few commands to create the archive with the result and to clean up the workspace of the source files.
9998
```
10099
### Dual Build Flag
101100
Note the DUAL_BUILD may speed up builds by running x86 and x64 builds concurrently (each with 1/2 as many threads). This is primarily useful during linking. Linking is largely single threaded and takes awhile and is single thread CPU bound (given enough IO). The main issue is memory usage. If both linking steps run at once you may need nearly 50GB of memory at once (in worst case). It would be better if they linked at slightly separate times but as every compute system was different there did not seem to be a good way to determine how long to sleep for to make it most efficient.
@@ -109,7 +108,7 @@ Note the DUAL_BUILD may speed up builds by running x86 and x64 builds concurrent
109108
- Sometimes docker may start to mis-behave often restarting docker may fix the problem. Sometimes a full reboot is needed.
110109

111110
### How requirements were determined
112-
- Space: windows base ~10 gigs, ~6 gigs for the finished visual studio build image. Another 20 or so when done with cefsharp. Chrome will take 200 gigs or so during build for the VHD, we remove the bulk of this before it finishes though. So for docker storage I would recommend 16 + 200 = ~ 220 gigs of space + some buffer so maybe 250GB.
111+
- Space: windows base ~6 gigs, ~9 gigs for the finished visual studio build image. Another 20 or so when done with cefsharp. Chrome will take 200 gigs or so during build for the VHD, we remove the bulk of this before it finishes though. So for docker storage I would recommend 16 + 200 = ~ 220 gigs of space + some buffer so maybe 250GB.
113112
- Memory: For Chrome 63 bare minimum memory requirements (actual + page file) for JUST the linker is x86: 24.2 GB x64: 25.7 GB. I would make sure you have atleast 32 gigs of ram to be safe with OS and other overhead.
114113

115114

build.ps1

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,52 @@
11
[CmdletBinding()]
22
Param(
3-
[Switch] $NoSkip
3+
[Switch] $NoSkip,
4+
[Switch] $NoMemoryWarn
45
)
5-
6+
$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition;
7+
. (Join-Path $WorkingDir 'functions.ps1')
8+
#Always read the source file first incase of a new variable.
9+
. (Join-Path $WorkingDir "versions_src.ps1")
10+
#user overrides
11+
if (Test-Path ./versions.ps1 -PathType Leaf){
12+
. (Join-Path $WorkingDir "versions.ps1")
13+
}
614
Set-StrictMode -version latest;
715
$ErrorActionPreference = "Stop";
816
if ((Get-MpPreference).DisableRealtimeMonitoring -eq $false){
917
Write-Host Warning, windows defender is enabled it will slow things down. -Foreground Red
1018
}
11-
12-
$last_time = Get-Date;
13-
function out {
14-
Param(
15-
[Parameter(Mandatory = $true, ParameterSetName = "ByPath", Position = 0)]
16-
$FilePath,
17-
[Parameter(Mandatory = $true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true, ParameterSetName = "ByPath", Position = 1)]
18-
$InputObject,
19-
[switch] $Append
20-
)
21-
Begin {
22-
if (! $Append){
23-
Out-File -FilePath $FilePath -Encoding ASCII;
24-
}
25-
}
26-
Process {
27-
Out-File -Append -InputObject $InputObject -FilePath $FilePath -Encoding ASCII
19+
if (! $NoMemoryWarn){
20+
$page_files = Get-CimInstance Win32_PageFileSetting;
21+
$os = Get-Ciminstance Win32_OperatingSystem;
22+
$min_gigs = 27;
23+
$warning = "linking may take around $min_gigs during linking";
24+
if ($VAR_DUAL_BUILD -eq "1"){
25+
$warning="dual build mode is enabled and may use 50+ GB if both releases link at once.";
26+
$min_gigs = 50;
27+
}
28+
if (($os.FreePhysicalMemory/1mb + $os.FreeSpaceInPagingFiles/1mb) -lt $min_gigs) { #if the memory isn't yet avail with the page files and they have a set size lets try to compute it that way
29+
$total_memory_gb = $os.FreePhysicalMemory/1mb;
30+
foreach ($file in $page_files){
31+
$total_memory_gb += $file.MaximumSize/1kb; #is zero if system managed, then we really don't know how big it could be.
2832
}
29-
}
30-
31-
Function RunProc{
32-
[CmdletBinding()]
33-
Param($proc,$opts,
34-
[switch] $errok)
35-
Write-Verbose "Running: $proc $opts"
36-
if ($proc.ToUpper().EndsWith(".PL")){
37-
$path = (C:\Windows\system32\where.exe $proc | Out-String).Trim()
38-
$opts = "$path $opts";
39-
$proc="perl";
40-
}
41-
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
42-
$pinfo.FileName = $proc
43-
$working = Convert-Path .
44-
$pinfo.WorkingDirectory = $working
45-
$pinfo.UseShellExecute = $false
46-
$pinfo.Arguments = $opts
47-
$p = New-Object System.Diagnostics.Process
48-
$p.StartInfo = $pinfo
49-
$p.Start() | Out-Null
50-
$p.WaitForExit()
51-
if ($p.ExitCode -ne 0 -and -not $errok){
52-
throw "Process $proc $opts exited with non zero code aborting!"
53-
}
54-
if ($errok){
55-
return $p.ExitCode;
56-
}
57-
}
33+
if ($total_memory_gb -lt $min_gigs){
34+
if (! (confirm("Warning $warning. Your machine may not have enough memory, make sure your page files can grow to allow it. (Disable this warning with -$NoMemoryWarn flag). Do you want to proceed?"))){
35+
exit 1;
36+
}
5837

59-
Function TimerNow($name){
60-
$now = Get-Date;
61-
$diff = ($now - $start_time).TotalSeconds.ToString("0.0");
62-
Write-Host $name took $diff -ForegroundColor Green;
63-
$last_time = $now;
38+
}
39+
}
6440
}
65-
$start_time = Get-Date;
66-
$end_time = Get-Date;
6741

6842

6943
echo packages_cefsharp.zip | out .dockerignore
7044
echo binaries.zip | out .dockerignore -Append
7145
if (! (Test-Path ./binaries.zip -PathType Leaf) -or $NoSkip){
7246
TimerNow("Starting");
73-
RunProc -proc "docker" -opts "build -f Dockerfile_vs -t vs ."
47+
RunProc -proc "docker" -opts "build --build-arg BASE_DOCKER_FILE=`"$VAR_BASE_DOCKER_FILE`" -f Dockerfile_vs -t vs ."
7448
TimerNow("VSBuild");
75-
RunProc -proc "docker" -opts "build -f Dockerfile_cef -t cef ."
49+
RunProc -proc "docker" -opts "build --build-arg DUAL_BUILD=`"$VAR_DUAL_BUILD`" --build-arg GN_DEFINES=`"$VAR_GN_DEFINES`" --build-arg GYP_DEFINES=`"$VAR_GYP_DEFINES`" --build-arg CHROME_BRANCH=`"$VAR_CHROME_BRANCH`" -f Dockerfile_cef -t cef ."
7650
TimerNow("CEF Build");
7751
docker rm cef
7852
RunProc -proc "docker" -opts "run --name cef cef cmd /C echo CopyVer"
@@ -87,7 +61,7 @@ if (! (Test-Path ./binaries.zip -PathType Leaf) -or $NoSkip){
8761
}
8862
RunProc -proc "docker" -opts "build -f Dockerfile_cef_binary -t cef_binary ."
8963
TimerNow("CEF Binary compile");
90-
RunProc -proc "docker" -opts "build -f Dockerfile_cefsharp -t cefsharp ."
64+
RunProc -proc "docker" -opts "build --build-arg CEFSHARP_BRANCH=`"$VAR_CEFSHARP_BRANCH`" --build-arg CEFSHARP_VERSION=`"$VAR_CEFSHARP_VERSION`" --build-arg CEF_VERSION_STR=`"$VAR_CEF_VERSION_STR`" --build-arg CHROME_BRANCH=`"$VAR_CHROME_BRANCH`" -f Dockerfile_cefsharp -t cefsharp ."
9165
TimerNow("CEFSharp compile");
9266
docker rm cefsharp
9367
RunProc -proc "docker" -opts "run --name cefsharp cefsharp cmd /C echo CopyVer"

cef_build.ps1

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
Set-StrictMode -version latest;
22
$ErrorActionPreference = "Stop";
3-
Function RunProc{
4-
[CmdletBinding()]
5-
Param($proc,$opts,
6-
[switch] $errok,
7-
[switch] $no_wait
8-
)
9-
if ($proc.ToUpper().EndsWith(".PL")){
10-
$path = (C:\Windows\system32\where.exe $proc | Out-String).Trim()
11-
$opts = "$path $opts";
12-
$proc="perl";
13-
}
14-
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
15-
$pinfo.FileName = $proc
16-
$working = Convert-Path .
17-
Write-Host "Running: $proc $opts in $working" -Foreground Green
18-
$pinfo.WorkingDirectory = $working
19-
$pinfo.UseShellExecute = $false
20-
$pinfo.Arguments = $opts
21-
$p = New-Object System.Diagnostics.Process
22-
$p.StartInfo = $pinfo
23-
$p.Start() | Out-Null
24-
if ($no_wait){
25-
return $p;
26-
}
27-
$p.WaitForExit()
28-
if ($p.ExitCode -ne 0 -and -not $errok){
29-
throw "Process $proc $opts exited with non zero code: $($p.ExitCode) aborting!"
30-
}
31-
if ($errok){
32-
return $p.ExitCode;
33-
}
34-
}
3+
$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition;
4+
. (Join-Path $WorkingDir 'functions.ps1')
5+
356
$build_args_add = "";
367
if ($env:DUAL_BUILD -eq "1"){
378
$cores = (Get-WmiObject -class Win32_processor).NumberOfLogicalProcessors + 2; #ninja defaults to number of procs + 2
@@ -43,7 +14,7 @@ if ($env:DUAL_BUILD -eq "1"){
4314
Function RunBuild{
4415
[CmdletBinding()]
4516
Param($build_args_add,$version)
46-
return RunProc -proc "c:/code/depot_tools/ninja.exe" -opts "$build_args_add -C out/Release_GN_$version cefclient" -no_wait;
17+
return RunProc "host" -proc "c:/code/depot_tools/ninja.exe" -opts "$build_args_add -C out/Release_GN_$version cefclient" -no_wait;
4718
}
4819
RunProc -proc "c:/code/depot_tools/python.bat" -errok -opts "c:/code/automate/automate-git.py --download-dir=c:/code --branch=$env:CHROME_BRANCH --no-build --no-debug-build --no-distrib";
4920
Set-Location -Path c:/code/chromium/src/cef;

functions.ps1

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Set-StrictMode -version latest;
2+
$ErrorActionPreference = "Stop";
3+
Function RunProc{
4+
[CmdletBinding()]
5+
Param($proc,$opts,
6+
[switch] $errok,
7+
[switch] $no_wait,
8+
[ValidateSet("verbose","host","none")]
9+
[String] $verbose_mode="host"
10+
)
11+
if ($proc.ToUpper().EndsWith(".PL")){
12+
$path = (C:\Windows\system32\where.exe $proc | Out-String).Trim()
13+
$opts = "$path $opts";
14+
$proc="perl";
15+
}
16+
$pinfo = New-Object System.Diagnostics.ProcessStartInfo;
17+
$pinfo.FileName = $proc;
18+
$working = Convert-Path .;
19+
$verbose_str = "Running: $proc $opts in $working";
20+
if ($verbose_mode -eq "host"){
21+
Write-Host $verbose_str -Foreground Green;
22+
}elseif($verbose_mode -eq "verbose"){
23+
Write-Verbose $verbose_str;
24+
}
25+
$pinfo.WorkingDirectory = $working;
26+
$pinfo.UseShellExecute = $false;
27+
$pinfo.Arguments = $opts;
28+
$p = New-Object System.Diagnostics.Process;
29+
$p.StartInfo = $pinfo;
30+
$p.Start() | Out-Null;
31+
if ($no_wait){
32+
return $p;
33+
}
34+
$p.WaitForExit();
35+
if ($p.ExitCode -ne 0 -and -not $errok){
36+
throw "Process $proc $opts exited with non zero code: $($p.ExitCode) aborting!" ;
37+
}
38+
if ($errok){
39+
return $p.ExitCode;
40+
}
41+
}
42+
function out {
43+
Param(
44+
[Parameter(Mandatory = $true, ParameterSetName = "ByPath", Position = 0)]
45+
$FilePath,
46+
[Parameter(Mandatory = $true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true, ParameterSetName = "ByPath", Position = 1)]
47+
$InputObject,
48+
[switch] $Append
49+
)
50+
Begin {
51+
if (! $Append){
52+
Out-File -FilePath $FilePath -Encoding ASCII;
53+
}
54+
}
55+
Process {
56+
Out-File -Append -InputObject $InputObject -FilePath $FilePath -Encoding ASCII
57+
}
58+
}
59+
Function confirm($str){
60+
return $PSCmdlet.ShouldContinue($str, "");
61+
}
62+
$last_time = Get-Date;
63+
Function TimerNow($name){
64+
$now = Get-Date;
65+
$diff = ($now - $last_time).TotalSeconds.ToString("0.0");
66+
Write-Host $name took $diff -ForegroundColor Green;
67+
$last_time = $now;
68+
}

0 commit comments

Comments
 (0)