前期准备
1:准备一台装有windowserver2019的系统
2:开启Hyper-V服务
3:安装docker powerShell运行以下命令
从 PowerShell 库安装 Docker-Microsoft PackageManagement 提供程序。
Install-Module -Name DockerMsftProvider -Force
使用 PackageManagement PowerShell 模块安装最新版本的 Docker。
Install-Package -Name docker -ProviderName DockerMsftProvider
启用容器功能
Install-WindowsFeature -Name Containers
编译工具所需要的依赖
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.5.0",
"Microsoft.NetCore.Component.Runtime.3.1",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.NuGet",
"Microsoft.Net.Component.4.6.1.TargetingPack",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
"Microsoft.VisualStudio.Component.FSharp",
"Microsoft.ComponentGroup.ClickOnce.Publish",
"Microsoft.NetCore.Component.DevelopmentTools",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions",
"Microsoft.Net.Component.4.8.SDK",
"Microsoft.Net.Component.4.7.2.TargetingPack",
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
"Microsoft.VisualStudio.Component.TypeScript.4.3",
"Microsoft.VisualStudio.Component.JavaScript.TypeScript",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.TextTemplating",
"Microsoft.VisualStudio.Component.Common.Azure.Tools",
"Microsoft.VisualStudio.Component.SQL.CLR",
"Microsoft.VisualStudio.Component.ManagedDesktop.Core",
"Microsoft.Net.Component.4.5.2.TargetingPack",
"Microsoft.Net.Component.4.5.TargetingPack",
"Microsoft.Net.Component.4.TargetingPack",
"Microsoft.Net.Component.4.5.1.TargetingPack",
"Microsoft.Net.Component.4.6.TargetingPack",
"Microsoft.Net.ComponentGroup.TargetingPacks.Common",
"Microsoft.VisualStudio.Component.DiagnosticTools",
"Microsoft.VisualStudio.Component.EntityFramework",
"Microsoft.VisualStudio.Component.Debugger.JustInTime",
"Microsoft.VisualStudio.Component.IntelliCode",
"Microsoft.VisualStudio.Component.VC.CoreIde",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Graphics.Tools",
"Microsoft.VisualStudio.Component.VC.DiagnosticTools",
"Microsoft.VisualStudio.Component.Windows10SDK.19041",
"Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites",
"Microsoft.ComponentGroup.Blend",
"Microsoft.VisualStudio.Component.DotNetModelBuilder",
"Microsoft.VisualStudio.Workload.ManagedDesktop",
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Component.VC.Tools.ARM64",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions.CMake",
"Microsoft.VisualStudio.Component.VC.CMake.Project",
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Component.VC.TestAdapterForBoostTest",
"Microsoft.VisualStudio.Component.VC.TestAdapterForGoogleTest",
"Microsoft.VisualStudio.Component.VC.ASAN",
"Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset",
"Microsoft.VisualStudio.Component.VC.Llvm.Clang",
"Microsoft.VisualStudio.Component.Windows11SDK.22000",
"Microsoft.VisualStudio.Component.Windows10SDK.18362",
"Microsoft.Component.VC.Runtime.UCRTSDK",
"Microsoft.VisualStudio.Component.VC.140",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.Component.VC.Tools.ARM",
"Microsoft.VisualStudio.Component.VC.ATL.ARM",
"Microsoft.VisualStudio.Component.VC.ATL.ARM64",
"Microsoft.VisualStudio.Component.VC.MFC.ARM",
"Microsoft.VisualStudio.Component.VC.MFC.ARM64",
"Microsoft.VisualStudio.Component.WinXP"
编译所需要的windowserver-vs2019镜像
第一次编译镜像
1:创建 install.cmd 文件
@if not defined _echo echo off
setlocal enabledelayedexpansion
call %*
if "%ERRORLEVEL%"=="3010" (
exit /b 0
) else (
if not "%ERRORLEVEL%"=="0" (
set ERR=%ERRORLEVEL%
call C:\TEMP\collect.exe -zip:C:\vslogs.zip
exit /b !ERR!
)
)
exit /b 0
2: 创建dockerfile文件
# escape=`
# Use a specific tagged image. Tags can be changed, though that is unlikely for most images.
# You could also use the immutable tag @sha256:324e9ab7262331ebb16a4100d0fb1cfb804395a766e3bb1806c62989d1fc1326
ARG FROM_IMAGE=jenkins/inbound-agent:windowsservercore-1809
FROM ${FROM_IMAGE}
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
# Copy our Install script.
COPY Install.cmd C:\TEMP\
# Download collect.exe in case of an install failure.
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe
# Use the latest release channel. For more control, specify the location of an internal layout.
ARG CHANNEL_URL=https://aka.ms/vs/16/release/channel
ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman
RUN `
# Download the Build Tools bootstrapper.
curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe `
`
# Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
&& (call C:\TEMP\Install.cmd vs_buildtools.exe --quiet --wait --norestart --nocache install --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools" --channelUri C:\TEMP\VisualStudio.chman --installChannelUri C:\TEMP\VisualStudio.chman --add Microsoft.VisualStudio.Component.CoreEditor --add Microsoft.VisualStudio.Workload.CoreEditor --add Microsoft.NetCore.Component.Runtime.5.0 --add Microsoft.NetCore.Component.Runtime.3.1 --add Microsoft.NetCore.Component.SDK --add Microsoft.VisualStudio.Component.NuGet --add Microsoft.Net.Component.4.6.1.TargetingPack --add Microsoft.VisualStudio.Component.Roslyn.Compiler --add Microsoft.VisualStudio.Component.Roslyn.LanguageServices --add Microsoft.VisualStudio.Component.FSharp --add Microsoft.ComponentGroup.ClickOnce.Publish --add Microsoft.NetCore.Component.DevelopmentTools --add Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions --add Microsoft.Net.Component.4.8.SDK --add Microsoft.Net.Component.4.7.2.TargetingPack --add Microsoft.Net.ComponentGroup.DevelopmentPrerequisites --add Microsoft.VisualStudio.Component.TypeScript.4.3 --add Microsoft.VisualStudio.Component.JavaScript.TypeScript --add Microsoft.Component.MSBuild --add Microsoft.VisualStudio.Component.TextTemplating --add Microsoft.VisualStudio.Component.Common.Azure.Tools --add Microsoft.VisualStudio.Component.SQL.CLR --add Microsoft.VisualStudio.Component.ManagedDesktop.Core --add Microsoft.Net.Component.4.5.2.TargetingPack --add Microsoft.Net.Component.4.5.TargetingPack --add Microsoft.Net.Component.4.TargetingPack --add Microsoft.Net.Component.4.5.1.TargetingPack --add Microsoft.Net.Component.4.6.TargetingPack --add Microsoft.Net.ComponentGroup.TargetingPacks.Common --add Microsoft.VisualStudio.Component.DiagnosticTools --add Microsoft.VisualStudio.Component.EntityFramework --add Microsoft.VisualStudio.Component.Debugger.JustInTime --add Microsoft.VisualStudio.Component.IntelliCode --add Microsoft.VisualStudio.Component.VC.CoreIde --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Graphics.Tools --add Microsoft.VisualStudio.Component.VC.DiagnosticTools --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --add Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites --add Microsoft.ComponentGroup.Blend --add Microsoft.VisualStudio.Component.DotNetModelBuilder --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 --add Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions.CMake --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.VC.ATL --add Microsoft.VisualStudio.Component.VC.TestAdapterForBoostTest --add Microsoft.VisualStudio.Component.VC.TestAdapterForGoogleTest --add Microsoft.VisualStudio.Component.VC.ASAN --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.Windows11SDK.22000) `
`
# Cleanup
&& del /q vs_buildtools.exe
注:第一次只安装部分依赖,全部添加上会报错
3:编译 大概等待30-60分钟
docker build -t hr-jenkins-agent:frist -m 2GB .
第二次编译镜像
注:第二次编译镜像是在第一次编译的镜像的基础上再进行编译
1:创建 install.cmd 文件
@if not defined _echo echo off
setlocal enabledelayedexpansion
call %*
if "%ERRORLEVEL%"=="3010" (
exit /b 0
) else (
if not "%ERRORLEVEL%"=="0" (
set ERR=%ERRORLEVEL%
call C:\TEMP\collect.exe -zip:C:\vslogs.zip
exit /b !ERR!
)
)
exit /b 0
2: 创建dockerfile文件
# escape=`
# Use a specific tagged image. Tags can be changed, though that is unlikely for most images.
# You could also use the immutable tag @sha256:324e9ab7262331ebb16a4100d0fb1cfb804395a766e3bb1806c62989d1fc1326
ARG FROM_IMAGE=hr-jenkins-agent:frist
FROM ${FROM_IMAGE}
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
# Copy our Install script.
COPY Install.cmd C:\TEMP\
# Download collect.exe in case of an install failure.
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe
# Use the latest release channel. For more control, specify the location of an internal layout.
ARG CHANNEL_URL=https://aka.ms/vs/16/release/channel
ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman
RUN `
# Download the Build Tools bootstrapper.
curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe `
`
# Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
&& (call C:\TEMP\Install.cmd vs_buildtools.exe --quiet --wait --norestart --nocache install --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools" --channelUri C:\TEMP\VisualStudio.chman --installChannelUri C:\TEMP\VisualStudio.chman `
--add Microsoft.VisualStudio.Component.Windows10SDK.18362 `
--add Microsoft.Component.VC.Runtime.UCRTSDK `
--add Microsoft.VisualStudio.Component.VC.140 `
--add Microsoft.VisualStudio.Workload.NativeDesktop `
--add Microsoft.VisualStudio.Component.VC.Tools.ARM `
--add Microsoft.VisualStudio.Component.VC.ATL.ARM `
--add Microsoft.VisualStudio.Component.VC.ATL.ARM64 `
--add Microsoft.VisualStudio.Component.VC.MFC.ARM `
--add Microsoft.VisualStudio.Component.VC.MFC.ARM64 `
--add Microsoft.VisualStudio.Component.WinXP) `
`
# Cleanup
&& del /q vs_buildtools.exe
#设置 msbuild 环境变量
RUN setx path "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin"
3:编译 大概等待20-30分钟
docker build -t hr-jenkins-agent:base -m 2GB .
镜像上传到Harbor
注:这里的Harbor是自己安装的在 192.168.3.227这台服务器上
安装步骤请参考:https://blog.51cto.com/u_13760351/2532347文章来源:https://www.toymoban.com/news/detail-598796.html
打标签
docker tag hr-jenkins-agent:base xxx/win_build/hr-jenkins-agent:base
上传
docker push xxx/win_build/hr-jenkins-agent:base
k8s window节点下拉镜像
注:因为镜像比较大所有在window节点上提前下拉下来文章来源地址https://www.toymoban.com/news/detail-598796.html
crictl pull xxx/win_build/hr-jenkins-agent:base
到了这里,关于window镜像制作的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!