ffi-napi docker build fail

136 Views Asked by At

I am moving my code from the local build agent to docker build, and getting some error when install ffi-napi on docker environment

There is step to reproduce:

First, I install vs build tool via https://learn.microsoft.com/en-us/visualstudio/install/build-tools-container?view=vs-2022

My Dockerfile is Dockerfile-vsbuildtool

FROM mcr.microsoft.com/dotnet/framework/sdk:3.5-20210525-windowsservercore-ltsc2019

SHELL ["cmd", "/S", "/C"]
RUN `
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_BuildTools.exe `
    && (start /w vs_buildtools.exe --quiet --wait --norestart --nocache `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
        --add   Microsoft.VisualStudio.Workload.VCTools `
        --add   Microsoft.VisualStudio.Component.Windows10SDK.19041 `
        --add   Microsoft.VisualStudio.Component.VC.140 `
        --add   Microsoft.VisualStudio.Component.VC.14.29.16.11.ARM64 `
        --add   Microsoft.VisualStudio.Component.VC.14.29.16.11.ATL.ARM64 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
        --remove Microsoft.VisualStudio.Component.Windows81SDK `
        || IF "%ERRORLEVEL%"=="3010" EXIT 0) `
    # Cleanup
    && del /q vs_buildtools.exe `
    && del /q %TEMP%\*

WORKDIR C:/app

ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

And from this vsbuildtool image, I created a Dockerfile for my project. From this docker file, I installed python and nodejs

FROM vsbuildtool:local

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    Write-Output "Downloading python zip"; \
    curl.exe -o python.zip -L https://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-amd64.zip; \
    Write-Output "Extract python zip"; \
    Expand-Archive -Path python.zip -DestinationPath C:\python37; \
    Write-Output "Cleaning python zip"; \
    Remove-Item -Path 'python.zip';

RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    Write-Output "Downloading node installer"; \
    curl.exe -o node.msi -L https://nodejs.org/dist/v14.16.0/node-v14.16.0-x64.msi; \
    Write-Output "Installing node installer"; \
    Start-Process -Wait -FilePath 'msiexec' -ArgumentList '/i', 'node.msi', '/qn'; \
    Write-Output "Cleaning node installer"; \
    Remove-Item -Path 'node.msi';

# Config python for node-gyp
RUN npm config set python "C:\python37\python.exe"

WORKDIR C:/app

ENTRYPOINT ["cmd"]

Then I run this image into a docker container, then I exec to this container Next, I run

npm i ffi-napi

And issue is occurred

> [email protected] install C:\app\server\api\node_modules\ffi-napi
> node-gyp-build


C:\app\server\api\node_modules\ffi-napi>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin
\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )   
gyp ERR! find VS  
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS unknown version "undefined" found at "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
gyp ERR! find VS checking VS2019 (16.10.31424.327) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
gyp ERR! find VS - "Visual Studio C++ core features" missing
gyp ERR! find VS checking VS2019 (16.10.31424.327) found at:
gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent" 
gyp ERR! find VS - "Visual Studio C++ core features" missing
gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - found in "C:\Program Files (x86)\Microsoft Visual Studio 14.0"
gyp ERR! find VS - could not find MSBuild in registry for this version
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows 
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)    
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:20
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:315:5)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1048:16)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\app\server\api\node_modules\ffi-napi
gyp ERR! node -v v14.16.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN rollback Rolling back [email protected] failed (this is probably harmless): EPERM: operation not permitted, unlink 'C:\app\server\api\node_modules\ffi-napi\
prebuilds\win32-x64\node.napi.uv1.node'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) 
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ContainerAdministrator\AppData\Roaming\npm-cache\_logs\2023-12-04T07_22_08_180Z-debug.log

I followed this https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md to fix the issue but look like it cannot help.

I my local, I installed VS Studio 2019 and it works, I don't think we can install VS in docker.

0

There are 0 best solutions below