Search code examples
dockergulp

Can you run gulp inside windows-server-core docker container?


We are trying to build a c# app that has gulp do some of the bundling/minification for the front end website.

We are currently using node 6 because of gulp dependencies. A future branch is updating to node 10 but that requires different node dependencies as we migrate our project. I thought using a docker container for the build might help alleviate switching between node versions on our local machine.

So I created a docker image FROM microsoft/dotnet-framework:4.7.2-sdk

Then I loaded npm on top of it. Binding a volume to my source directory I'm able to install npm packages, install nuget packages and call build but it will fail because it is missing my gulp step.

I have gulp installed both globally in the container and locally in the node_modules folder. I end up with an error like,

C:\Program Files\node\node-v6.16.0-win-x64\node_modules\gulp\node_modules\sver-compat\sver.js:19

  var semver = version.match(semverRegEx);
                      ^

TypeError: Cannot read property 'match' of undefined
    at new Semver (C:\Program Files\node\node-v6.16.0-win-x64\node_modules\gulp\node_modules\sver-compat\sver.js:19:23)
    at Function.match (C:\Program Files\node\node-v6.16.0-win-x64\node_modules\gulp\node_modules\sver-compat\sver.js:374:15)

I have search all over the web for multiple days with no luck finding anything that can help me with what is blowing up here. Has anyone been able to get gulp to run successfully inside of a Windows Server Core docker container? Is the problem with the directory being mounted? Using Docker for Windows if that matters here.


Solution

  • On Windows-Server-Core the best I can surmise there is an issue with docker, volume-mounts and npm/gulp system links.

    I believe the user set on the container by default wants to use the c:\containermappeddirectories folder. I am not sure at this point if that is configurable.

    But my work around looked like this in powershell all running in the container,

    npm install -g  gulp@^3.9.1
    md c:\ContainerMappedDirectories
    cd c:\containermappedDirectories
    
    robocopy /S "c:\MyUISource" C:\ContainerMappedDirectories 
    npm install #installs gulp locally to this folder
    gulp prod-build
    robocopy /S C:\ContainerMappedDirectories\dist c:\MyUISource
    

    So I installed gulp globally, I created the local workspace copied my source in and ran npm/gulp then copied back my output to the mounted location.

    In the end it was the best work around I could accomplish to complete my task.