Skip to content

Commit b04fa58

Browse files
committed
dockerfile: ensuring CMake version is not greater than the latest supported one, rework of Windows Containers Dockerfile build cache friendliness and configurability.
Signed-off-by: Marat Abrarov <[email protected]>
1 parent edf05d1 commit b04fa58

File tree

2 files changed

+138
-49
lines changed

2 files changed

+138
-49
lines changed

dockerfiles/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
4141
build-essential \
4242
curl \
4343
ca-certificates \
44-
cmake \
4544
git \
4645
make \
4746
tar \
@@ -56,6 +55,7 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
5655
flex \
5756
bison \
5857
libyaml-dev \
58+
&& apt-get satisfy -y cmake "cmake (<< 4.0)" \
5959
&& apt-get clean \
6060
&& rm -rf /var/lib/apt/lists/*
6161

@@ -254,8 +254,9 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
254254
net-tools mtr netcat-openbsd bridge-utils iperf ngrep \
255255
openssl \
256256
htop atop strace iotop sysstat ncdu logrotate hdparm pciutils psmisc tree pv \
257-
cmake make tar flex bison \
257+
make tar flex bison \
258258
libssl-dev libsasl2-dev libsystemd-dev/bookworm-backports zlib1g-dev libpq-dev libyaml-dev postgresql-server-dev-all \
259+
&& apt-get satisfy -y cmake "cmake (<< 4.0)" \
259260
&& apt-get clean \
260261
&& rm -rf /var/lib/apt/lists/*
261262

dockerfiles/Dockerfile.windows

+135-47
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,147 @@ ARG WINDOWS_VERSION=ltsc2019
1616
# Builder Image - Windows Server Core
1717
FROM mcr.microsoft.com/windows/servercore:$WINDOWS_VERSION AS builder-base
1818

19-
RUN setx /M PATH "%PATH%;C:\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\WinFlexBison;C:\dev\vcpkg"
20-
2119
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
22-
WORKDIR /local
23-
24-
# Install Visual Studio 2019
25-
ADD https://aka.ms/vs/16/release/vs_buildtools.exe /local/vs_buildtools.exe
26-
ADD https://aka.ms/vs/16/release/channel /local/VisualStudio.chman
27-
28-
RUN Start-Process /local/vs_buildtools.exe `
29-
-ArgumentList '--quiet ', '--wait ', '--norestart ', '--nocache', `
30-
'--installPath C:\BuildTools', `
31-
'--channelUri C:\local\VisualStudio.chman', `
32-
'--installChannelUri C:\local\VisualStudio.chman', `
33-
'--add Microsoft.VisualStudio.Workload.VCTools', `
34-
'--includeRecommended' -NoNewWindow -Wait;
35-
36-
ADD https://github.com/lexxmark/winflexbison/releases/download/v2.5.22/win_flex_bison-2.5.22.zip /local/win_flex_bison.zip
3720

38-
RUN Expand-Archive /local/win_flex_bison.zip -Destination /WinFlexBison; `
39-
Copy-Item -Path /WinFlexBison/win_bison.exe /WinFlexBison/bison.exe; `
40-
Copy-Item -Path /WinFlexBison/win_flex.exe /WinFlexBison/flex.exe;
41-
42-
# Technique from https://github.com/StefanScherer/dockerfiles-windows/blob/master/mongo/3.6/Dockerfile
21+
# Install Visual Studio Build Tools 2019
4322
WORKDIR /local
44-
ADD https://aka.ms/vs/15/release/vc_redist.x64.exe /local/vc_redist.x64.exe
45-
46-
WORKDIR /fluent-bit/bin/
47-
RUN Start-Process /local/vc_redist.x64.exe -ArgumentList '/install', '/quiet', '/norestart' -NoNewWindow -Wait; `
48-
Copy-Item -Path /Windows/System32/msvcp140.dll -Destination /fluent-bit/bin/; `
49-
Copy-Item -Path /Windows/System32/vccorlib140.dll -Destination /fluent-bit/bin/; `
50-
Copy-Item -Path /Windows/System32/vcruntime140.dll -Destination /fluent-bit/bin/;
23+
ENV MSVS_BUILD_TOOLS_VERSION="16" `
24+
MSVS_BUILD_TOOLS_DOWNLOAD_URL="https://aka.ms/vs" `
25+
MSVS_HOME="C:\BuildTools"
26+
RUN $msvs_build_tools_dist_name=\"vs_buildtools.exe\"; `
27+
$msvs_build_tools_dist=\"${env:TMP}\${msvs_build_tools_dist_name}\"; `
28+
$msvs_build_tools_channel=\"C:\local\VisualStudio.chman\"; `
29+
$msvs_build_tools_dist_url=\"${env:MSVS_BUILD_TOOLS_DOWNLOAD_URL}/${env:MSVS_BUILD_TOOLS_VERSION}/release/${msvs_build_tools_dist_name}\"; `
30+
$msvs_build_tools_channel_url=\"${env:MSVS_BUILD_TOOLS_DOWNLOAD_URL}/${env:MSVS_BUILD_TOOLS_VERSION}/release/channel\"; `
31+
Write-Host \"Downloading Visual Studio Build Tools...\"; `
32+
Write-Host \"${msvs_build_tools_dist_url} -> ${msvs_build_tools_dist}\"; `
33+
Write-Host \"${msvs_build_tools_channel_url} -> ${msvs_build_tools_channel}\"; `
34+
Invoke-WebRequest -OutFile \"${msvs_build_tools_dist}\" \"${msvs_build_tools_dist_url}\"; `
35+
Invoke-WebRequest -OutFile \"${msvs_build_tools_channel}\" \"${msvs_build_tools_channel_url}\"; `
36+
Write-Host \"Installing Visual Studio Build Tools into ${env:MSVS_HOME}...\"; `
37+
Start-Process \"${msvs_build_tools_dist}\" `
38+
-ArgumentList '--quiet ', '--wait ', '--norestart ', '--nocache', `
39+
\"--installPath ${env:MSVS_HOME}\", `
40+
\"--channelUri ${msvs_build_tools_channel}\", `
41+
\"--installChannelUri ${msvs_build_tools_channel}\", `
42+
'--add Microsoft.VisualStudio.Workload.VCTools', `
43+
'--includeRecommended' -NoNewWindow -Wait; `
44+
Remove-Item -Force \"${msvs_build_tools_dist}\";
45+
46+
ENV MSVC_RUNTIME_VERSION="15" `
47+
MSVC_RUNTIME_DOWNLOAD_URL="https://aka.ms/vs"
48+
RUN $msvc_runtime_dist_name=\"vc_redist.x64.exe\"; `
49+
$msvc_runtime_dist=\"${env:TMP}\${msvc_runtime_dist_name}\"; `
50+
$msvc_runtime_url=\"${env:MSVC_RUNTIME_DOWNLOAD_URL}/${env:MSVC_RUNTIME_VERSION}/release/${msvc_runtime_dist_name}\"; `
51+
Write-Host \"Downloading Microsoft Visual C++ Redistributable...\"; `
52+
Write-Host \"${msvc_runtime_url} -> ${msvc_runtime_dist}\"; `
53+
Invoke-WebRequest -OutFile \"${msvc_runtime_dist}\" \"${msvc_runtime_url}\"; `
54+
Write-Host \"Installing Microsoft Visual C++ runtime libraries...\"; `
55+
Start-Process \"${msvc_runtime_dist}\" -ArgumentList '/install', '/quiet', '/norestart' -NoNewWindow -Wait; `
56+
Remove-Item -Force \"${msvc_runtime_dist}\";
57+
58+
ENV CMAKE_VERSION="3.31.6" `
59+
CMAKE_HOME="C:\cmake" `
60+
CMAKE_DOWNLOAD_URL="https://github.com/Kitware/CMake/releases/download"
61+
62+
RUN if ([System.Version] \"${env:CMAKE_VERSION}\" -ge [System.Version] \"3.20.0\") { `
63+
$cmake_dist_base_name=\"cmake-${env:CMAKE_VERSION}-windows-x86_64\" `
64+
} else { `
65+
if ([System.Version] \"${env:CMAKE_VERSION}\" -ge [System.Version] \"3.6.0\") { `
66+
$cmake_dist_base_name=\"cmake-${env:CMAKE_VERSION}-win64-x64\" `
67+
} else { `
68+
$cmake_dist_base_name=\"cmake-${env:CMAKE_VERSION}-win32-x86\" `
69+
} `
70+
}; `
71+
$cmake_dist_name=\"${cmake_dist_base_name}.zip\"; `
72+
$cmake_dist=\"${env:TMP}\${cmake_dist_name}\"; `
73+
$cmake_url=\"${env:CMAKE_DOWNLOAD_URL}/v${env:CMAKE_VERSION}/${cmake_dist_name}\"; `
74+
Write-Host \"Downloading CMake...\"; `
75+
Write-Host \"${cmake_url} -> ${cmake_dist}\"; `
76+
Invoke-WebRequest -OutFile \"${cmake_dist}\" \"${cmake_url}\"; `
77+
$cmake_temp_dir=\"${env:TMP}\${cmake_dist_base_name}\"; `
78+
Write-Host \"Extracting CMake...\"; `
79+
Write-Host \"${cmake_dist} -> ${cmake_temp_dir}\"; `
80+
Expand-Archive \"${cmake_dist}\" -Destination \"${env:TMP}\"; `
81+
Remove-Item -Force \"${cmake_dist}\"; `
82+
Write-Host \"Moving CMake...\"; `
83+
Write-Host \"${cmake_temp_dir} -> ${env:CMAKE_HOME}\"; `
84+
[System.IO.Directory]::Move(\"${cmake_temp_dir}\", \"${env:CMAKE_HOME}\"); `
85+
$env:PATH=\"${env:PATH};${env:CMAKE_HOME}\bin\"; `
86+
Write-Host \"Setting PATH...\"; `
87+
Write-Host \"${env:PATH}\"; `
88+
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine);
89+
90+
ENV WIN_FLEX_BISON_VERSION="2.5.22" `
91+
WIN_FLEX_BISON_HOME="C:\WinFlexBison" `
92+
WIN_FLEX_BISON_DOWNLOAD_URL="https://github.com/lexxmark/winflexbison/releases/download"
93+
94+
RUN $win_flex_bison_dist_base_name=\"win_flex_bison-${env:WIN_FLEX_BISON_VERSION}\"; `
95+
$win_flex_bison_dist_name=\"${win_flex_bison_dist_base_name}.zip\"; `
96+
$win_flex_bison_dist=\"${env:TMP}\${win_flex_bison_dist_name}\"; `
97+
$win_flex_bison_url=\"${env:WIN_FLEX_BISON_DOWNLOAD_URL}/v${env:WIN_FLEX_BISON_VERSION}/${win_flex_bison_dist_name}\"; `
98+
Write-Host \"Downloading WinFlexBison...\"; `
99+
Write-Host \"${win_flex_bison_url} -> ${win_flex_bison_dist}\"; `
100+
Invoke-WebRequest -OutFile \"${win_flex_bison_dist}\" \"${win_flex_bison_url}\"; `
101+
Write-Host \"Extracting WinFlexBison...\"; `
102+
Write-Host \"${win_flex_bison_dist} -> ${env:WIN_FLEX_BISON_HOME}\"; `
103+
Expand-Archive \"${win_flex_bison_dist}\" -Destination \"${env:WIN_FLEX_BISON_HOME}\"; `
104+
Remove-Item -Force \"${win_flex_bison_dist}\"; `
105+
Write-Host \"Copying...\"; `
106+
Write-Host \"${env:WIN_FLEX_BISON_HOME}\win_bison.exe -> ${env:WIN_FLEX_BISON_HOME}\bison.exe\"; `
107+
Copy-Item -Path \"${env:WIN_FLEX_BISON_HOME}\win_bison.exe\" \"${env:WIN_FLEX_BISON_HOME}\bison.exe\"; `
108+
Write-Host \"Copying...\"; `
109+
Write-Host \"${env:WIN_FLEX_BISON_HOME}\win_flex.exe -> ${env:WIN_FLEX_BISON_HOME}\flex.exe\"; `
110+
Copy-Item -Path \"${env:WIN_FLEX_BISON_HOME}\win_flex.exe\" \"${env:WIN_FLEX_BISON_HOME}\flex.exe\"; `
111+
$env:PATH=\"${env:PATH}${env:WIN_FLEX_BISON_HOME}\"; `
112+
Write-Host \"Setting PATH...\"; `
113+
Write-Host \"${env:PATH}\"; `
114+
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine);
51115

52-
ENV VCPKG_VERSION=2024.05.24
53116
# https://github.com/microsoft/vcpkg/blob/2024.05.24/scripts/bootstrap.ps1
54-
ENV VCPKG_ROOT=/dev/vcpkg
117+
ENV VCPKG_VERSION=2024.05.24 `
118+
VCPKG_DOWNLOAD_URL="https://github.com/microsoft/vcpkg/archive/refs/tags" `
119+
VCPKG_DISABLE_METRICS="ON" `
120+
VCPKG_ROOT=/dev/vcpkg
55121

56122
WORKDIR /dev
57123

58-
RUN `
59-
Invoke-WebRequest -OutFile /dev/vcpkg.zip https://github.com/microsoft/vcpkg/archive/refs/tags/${ENV:VCPKG_VERSION}.zip; `
60-
Expand-Archive /dev/vcpkg.zip -Destination /dev; `
61-
Remove-Item -Force /dev/vcpkg.zip; `
62-
Rename-Item -Path /dev/vcpkg-${ENV:VCPKG_VERSION} -NewName vcpkg; `
63-
/dev/vcpkg/bootstrap-vcpkg.bat;
124+
RUN $vcpkg_dist_base_name=\"vcpkg-${env:VCPKG_VERSION}\"; `
125+
$vcpkg_dist=\"${env:TMP}\${vcpkg_dist_base_name}.zip\"; `
126+
$vcpkg_url=\"${env:VCPKG_DOWNLOAD_URL}/${env:VCPKG_VERSION}.zip\"; `
127+
Write-Host \"Downloading vcpkg...\"; `
128+
Write-Host \"${vcpkg_url} -> ${vcpkg_dist}\"; `
129+
Invoke-WebRequest -OutFile \"${vcpkg_dist}\" \"${vcpkg_url}\"; `
130+
$vcpkg_temp_dir=\"${env:TMP}\${vcpkg_dist_base_name}\"; `
131+
Write-Host \"Extracting vcpkg...\"; `
132+
Write-Host \"${vcpkg_dist} -> ${vcpkg_temp_dir}\"; `
133+
Expand-Archive \"${vcpkg_dist}\" -Destination \"${env:TMP}\"; `
134+
Remove-Item -Force \"${vcpkg_dist}\"; `
135+
$vcpkg_home_dir=\"${env:VCPKG_ROOT}\" -replace \"/\", \"\\\"; `
136+
$vcpkg_home_dir=\"C:${vcpkg_home_dir}\"; `
137+
Write-Host \"Moving vcpkg...\"; `
138+
Write-Host \"${vcpkg_temp_dir} -> ${vcpkg_home_dir}\"; `
139+
[System.IO.Directory]::Move(\"${vcpkg_temp_dir}\", \"${vcpkg_home_dir}\"); `
140+
$env:PATH=\"${env:PATH}${vcpkg_home_dir}\"; `
141+
Write-Host \"Setting PATH...\"; `
142+
Write-Host \"${env:PATH}\"; `
143+
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine); `
144+
Write-Host \"Bootstrapping vcpkg...\"; `
145+
& \"${vcpkg_home_dir}\bootstrap-vcpkg.bat\";
64146

65147
# Ensure we only attempt to build release and static linking
66-
ENV VCPKG_BUILD_TYPE=release
67-
ENV VCPKG_LIBRARY_LINKAGE=static
148+
ENV VCPKG_BUILD_TYPE=release `
149+
VCPKG_LIBRARY_LINKAGE=static
68150

69151
RUN vcpkg install --recurse openssl --triplet x64-windows-static; `
70152
vcpkg install --recurse libyaml --triplet x64-windows-static;
71153

154+
# Technique from https://github.com/StefanScherer/dockerfiles-windows/blob/master/mongo/3.6/Dockerfile
155+
WORKDIR /fluent-bit/bin
156+
RUN Copy-Item -Path C:\Windows\System32\msvcp140.dll -Destination /fluent-bit/bin/; `
157+
Copy-Item -Path C:\Windows\System32\vccorlib140.dll -Destination /fluent-bit/bin/; `
158+
Copy-Item -Path C:\Windows\System32\vcruntime140.dll -Destination /fluent-bit/bin/;
159+
72160
FROM builder-base AS builder
73161

74162
# Build Fluent Bit from source - context must be the root of the Git repo
@@ -77,14 +165,14 @@ COPY . /src/
77165

78166
ARG BUILD_PARALLEL=1
79167
RUN cmake -G "'Visual Studio 16 2019'" `
80-
-DOPENSSL_ROOT_DIR='C:\dev\vcpkg\packages\openssl_x64-windows-static' `
81-
-DFLB_LIBYAML_DIR='C:\dev\vcpkg\packages\libyaml_x64-windows-static' `
82-
-DCMAKE_BUILD_TYPE=Release `
83-
-DFLB_SHARED_LIB=Off `
84-
-DFLB_EXAMPLES=Off `
85-
-DFLB_DEBUG=Off `
86-
-DFLB_RELEASE=On `
87-
../;`
168+
-DOPENSSL_ROOT_DIR='C:\dev\vcpkg\packages\openssl_x64-windows-static' `
169+
-DFLB_LIBYAML_DIR='C:\dev\vcpkg\packages\libyaml_x64-windows-static' `
170+
-DCMAKE_BUILD_TYPE=Release `
171+
-DFLB_SHARED_LIB=Off `
172+
-DFLB_EXAMPLES=Off `
173+
-DFLB_DEBUG=Off `
174+
-DFLB_RELEASE=On `
175+
../;`
88176
cmake --build . --config Release -j ${BUILD_PARALLEL};
89177

90178
# Set up config files and binaries in single /fluent-bit hierarchy for easy copy in later stage

0 commit comments

Comments
 (0)