Matlab,Windows 兼容 Docker 容器无法 运行 Azure Devops CI/CD 作业的 Matlab 作业步骤

Matlab, Windows compatible Docker Container Fails to run Matlab job steps of Azure Devops CI/CD job

我正在尝试为 运行 我的作品 AzureDevops CI/CD 管道制作一个 Matlab/Windows/FMU 兼容的 docker 容器。但是当我 运行 CI 在线构建作业时遇到问题。 当它尝试 运行 任何 matlab 代码时,我得到他的错误:

错误:

2020-12-10T14:55:08.0295754Z ##[debug]   cd('C:\azp\agent\_work\_temp'); command_3a2582de_1b59_40fc_8400_bb6ddbb6b019
2020-12-10T14:55:08.0312327Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\azp\agent\_work\_tasks\RunMATLABCommand_28fdff80-51b4-4b6e-83e1-cfcf3f3b25a6[=14=].3.7\bin\run_matlab_command.bat "cd('C:\azp\agent\_work\_temp'); command_3a2582de_1b59_40fc_8400_bb6ddbb6b019""
2020-12-10T14:55:08.8200355Z Fatal Internal Error: std::exception: Bundle#4 start failed: Loading C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error: The specified module could not be found.

我使用自己的计算机作为自托管代理 运行ning 我的 CI/CD 循环没问题,但是我在我的容器中 运行ning matlab 遇到问题。

我试过这样做: https://www.mathworks.com/matlabcentral/answers/384746-libmwlmgrimpl-dll-error-in-r2017b 通过直接将 dll 添加到我的 src 项目,将代码(与 dll)推送到 azure 并强制将 dll 加载到我的 docker 容器中。没用。更多信息,我没有任何可执行文件。我有一个从 matlab 控制项目生成的构建过程,我还有一个测试过程 运行 在 matlab 单元测试 class.

中使用 simulink 文件

有什么想法吗?

Dockerfile:

# Indicates that the windowsservercore image will be used as the base image.
FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Metadata indicating an image maintainer.
LABEL maintainer="***@***.com"

# Define Work Directory
WORKDIR /azp
RUN mkdir C:\install

# Installing Packet Manager
RUN powershell -command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell -command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
# Installing Depedencies
RUN mkdir c:\tools\cygwin && cd c:\tools\cygwin && curl -Sso cygwinsetup.exe https://cygwin.com/setup-x86_64.exe && start /wait cygwinsetup -q --root C:\tools\cygwin -P dos2unix,make,perl,python27,python38,rsync,libxml2,pbzip2,mc -X --site http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/64bit/2020/05/31/142136/
RUN setx PATH "%PATH%;C:\tools\cygwin\bin" /M
RUN powershell -command choco install -y git
RUN powershell -command choco install -y mingw 
RUN powershell -command choco install -y cmake 
RUN powershell -command choco install -y wget 
RUN powershell -command choco install -y ninja 
RUN powershell -command choco install -y python3 

# Verification Step
RUN choco -?
RUN path
RUN ls
RUN wget --help

# Fetch

#RUN wget -rH https://releases.linaro.org/components/toolchain/binaries/latest-6/arm-eabi/
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python get-pip.py
# Transfert Self-Hosted Agent Script
COPY start.ps1 .
# Transfert Matlab Install & Licences
COPY _temp_matlab_R2017b_win64 C:\install\_temp_matlab_R2017b_win64
COPY MathWorks C:\Users\ContainerAdministrator\Downloads\MathWorks
COPY network.lic C:\install
COPY matlab_license.dat C:\install
COPY installer_input.txt C:\install
# Transfert Modelon Install & Licences
COPY FMI_Toolbox-2.8-win.exe C:\install
COPY fmi_license.lic C:\install
RUN ls ..\install
#Install Matlab
#RUN powershell.exe -command \
#     Start-Job -ScriptBlock {C:\install\_temp_matlab_R2017b_win64\setup.exe -inputFile C:\install\installer_input.txt} -Name matlabInstallContainer ;\
#     Wait-Job -Name "matlabInstallContainer";\
#     Stop-Job -Name "matlabInstallContainer";
RUN powershell.exe -command \
  "&C:\install\_temp_matlab_R2017b_win64\setup.exe -inputFile C:\install\installer_input.txt | Out-Null"
#Install Modelon
RUN C:\install\FMI_Toolbox-2.8-win.exe /S /D=C:\Program Files (x86)\Modelon\FMI Toolbox 2.8
#RUN matlab -r "cd 'C:\Program Files (x86)\Modelon\FMI Toolbox 2.8';setup('C:\install\fmi_license.lic', true);exit;"
RUN mkdir C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Modelon\Licenses\Server
RUN cp C:\install\fmi_license.lic C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Modelon\Licenses\Server

# Sets a command or process that will run each time a container is run from the new image.
CMD powershell .\start.ps1
#CMD [ "cmd" ]

更新:

还是不行。 我已经安装了 Windows 2016 Container,但出现了同样的错误。

...\libmwlmgrimpl.dllfailed with error: The specified module could not be found.

我正在添加一个对象转储,也许它可以帮助你们中的一些人? 我确实在转储中看到了 LIBEAY32.DLL,但是 我没有看到 SSLEAY32.DLL,这正常吗? 参考: https://www.mathworks.com/matlabcentral/answers/375270-why-does-my-matlab-compiler-standalone-application-fail-to-start-with-a-the-operating-system-cannot

C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl>objdump -x libmwlmgrimpl.dll | grep "DLL Name"
        DLL Name: ddux.dll
        DLL Name: instlic_4a.dll
        DLL Name: jit_launcher.dll
        DLL Name: libmwi18n.dll
        DLL Name: libmwfl.dll
        DLL Name: libmwms.dll
        DLL Name: libmwservices.dll
        DLL Name: libmx.dll
        DLL Name: libut.dll
        DLL Name: mpath.dll
        DLL Name: mvm.dll
        DLL Name: mlutil.dll
        DLL Name: settingscore.dll
        DLL Name: webproxy.dll
        DLL Name: boost_date_time-vc140-mt-1_56.dll
        DLL Name: boost_filesystem-vc140-mt-1_56.dll
        DLL Name: boost_log-vc140-mt-1_56.dll
        DLL Name: boost_system-vc140-mt-1_56.dll
        DLL Name: boost_thread-vc140-mt-1_56.dll
        DLL Name: CppMicroServices3.dll
        DLL Name: ADVAPI32.dll
        DLL Name: COMCTL32.dll
        DLL Name: COMDLG32.dll
        DLL Name: NETAPI32.dll
        DLL Name: WS2_32.dll
        DLL Name: SHLWAPI.dll
        DLL Name: dhcpcsvc.DLL
        DLL Name: PocoFoundation64.dll
        DLL Name: PocoNet64.dll
        DLL Name: PocoNetSSL64.dll
        DLL Name: WININET.dll
        DLL Name: msi.dll
        DLL Name: CRYPT32.dll
        DLL Name: IPHLPAPI.DLL
        DLL Name: MAPI32.dll
        DLL Name: ole32.dll
        DLL Name: libsqlite3.dll
        DLL Name: tbb.dll
        DLL Name: xerces-c_3_1.dll
        DLL Name: KERNEL32.dll
        DLL Name: USER32.dll
        DLL Name: SHELL32.dll
        DLL Name: OLEAUT32.dll
        DLL Name: MSVCP140.dll
        DLL Name: VCRUNTIME140.dll
        DLL Name: api-ms-win-crt-runtime-l1-1-0.dll
        DLL Name: api-ms-win-crt-stdio-l1-1-0.dll
        DLL Name: api-ms-win-crt-time-l1-1-0.dll
        DLL Name: api-ms-win-crt-convert-l1-1-0.dll
        DLL Name: api-ms-win-crt-heap-l1-1-0.dll
        DLL Name: api-ms-win-crt-environment-l1-1-0.dll
        DLL Name: api-ms-win-crt-locale-l1-1-0.dll
        DLL Name: api-ms-win-crt-string-l1-1-0.dll
        DLL Name: api-ms-win-crt-math-l1-1-0.dll
        DLL Name: api-ms-win-crt-utility-l1-1-0.dll
        DLL Name: api-ms-win-crt-filesystem-l1-1-0.dll
        DLL Name: LIBEAY32.dll

我还添加了在我的工作计算机(自托管代理)上完成的工作 matlab/libmwlmgrimpl 依赖遍历器分析。 我不知道如何通过我的 docker 容器内的命令行来进行比较。希望这有助于找到缺少模块的问题。

更新#2:

在与 Mathworks 交谈后,使用 depency walker、dependencies.exe 和 vim diff,我发现 windows 2016 服务器的系统 32 文件夹中的 dll 比 'Windows 10' 或 'windows 2016 server with desktop experience'。这些 dll 似乎是使 mathlab 工作所必需的,因此我需要将它们添加到我的容器中。我将我的主计算机和 docker 容器的正确差异复制粘贴到我的 docker 容器中的一个文件夹中,并将其添加到路径中。之前,我之前的错误发生在启动我的 MATLAB 作业后 1 seconf 的第二个。现在我得到一个不同的错误(这是 PROGRESS!!)并在第二个错误(这是 PROGRESS!!)失败。

大家对这个新的有什么想法吗?

##[debug]   cd('C:\azp\agent\_work\_temp'); command_35722346_1e7d_4546_956b_f1320bcc9adc
C:\Windows\system32\cmd.exe /D /S /C "C:\azp\agent\_work\_tasks\RunMATLABCommand_28fdff80-51b4-4b6e-83e1-cfcf3f3b25a6[=18=].3.7\bin\run_matlab_command.bat "cd('C:\azp\agent\_work\_temp'); command_35722346_1e7d_4546_956b_f1320bcc9adc""
Fatal Internal Error: std::exception: Bundle#4 start failed: Loading C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error: %1 is not a valid Win32 application.

Matlab, Windows compatible Docker Container Fails to run Matlab job steps of Azure Devops CI/CD job

据我所知,MATLAB R2017b 在 MATLAB R2019a 之前不支持 Windows Server 2019。

对于 MATLAB R2017b,您可以尝试使用 Windows Server 2016。

你可以查看文档System Requirements and Supported Compilers

因此,您可以尝试使用图像 mcr.microsoft.com/windows:1809mcr.microsoft.com/windows/servercore:1607

正如@Leo Liu-MSFT 所说,

For MATLAB R2017b, you could try to use Windows Server 2016…⠀So, you could try to use the image mcr.microsoft.com/windows:1809 or mcr.microsoft.com/windows/servercore:1607.

扩展该答案:

联系 MathWorks 后,我了解到 Windows 2016 Server 是 Windows 的准系统版本,带有一组极简的 System 32 DLL。但是 MATLAB 需要很多它们才能运行。因此,解决方案也是:

  1. 使用具有桌面体验的 Windows 2016 服务器 (mcr.microsoft.com/windows:1809),或
  2. 使用 Windows 2016 Server Docker 容器(mcr.microsoft.com/windows/servercore:1809)并添加所有缺少的 System32 DLL。 (可以使用 dependency walker 或对主机和 Docker 容器的 system32 文件夹进行 Right Diff 找到)