I'm trying to use a Docker image I created as a build agent in an Azure pipeline. I'm using Azure DevOps Server 2019.
My Docker image is built with nodejs and my npm dependencies installed. I use the Docker image as a build agent for an Angular application.
This is the Dockerfile I use:
FROM mcr.microsoft.com/windows:1809-amd64
#Create app directory
WORKDIR /
# Install Chocolatey
RUN powershell -ExecutionPolicy unrestricted -Command iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
#install node and npm
RUN choco install -y nodejs-lts --version 14.15.0
#install angular-cli
RUN npm install -g @angular/cli
RUN refreshenv
#Install app dependencies
COPY ./client/package*.json ./
RUN npm ci
CMD powershell
Here is the pipeline YAML I'm using:
trigger:
none
resources:
containers:
- container: angulardocker
image: angular-dev:1.0
endpoint: Docker Hub
stages:
- stage: Client
jobs:
- job: Build
pool:
name: Default
container: angulardocker
steps:
- task: Npm@1
displayName: 'Client Build'
inputs:
command: custom
customCommand: run build -- --prod
workingDir: client
- task: CopyFiles@2
displayName: 'Copy Client Build to Staging Directory'
inputs:
contents: '**'
SourceFolder: $(Build.SourcesDirectory)/client/dist
targetFolder: $(Build.ArtifactStagingDirectory)/client
- task: PublishBuildArtifacts@1
displayName: 'Publish Build Artifact - Client'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)/client'
artifactName: 'Client'
When the pipeline runs, the Docker image is pulled from Docker Hub and initialized as a container successfully but throws an error when it gets to the 'npm run build --prod' build step. This is the error message that appears:
; environment configs
cache = "C:\\__w\\6\\.npm"
userconfig = "C:\\__w\\6\\npm\\346.npmrc"
; builtin config undefined
prefix = "C:\\Users\\ContainerAdministrator\\AppData\\Roaming\\npm"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\__w\6\s\client
; HOME = C:\Users\ContainerAdministrator
; "npm config ls -l" to show all defaults.
[command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" run build -- --prod"
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'C:\__w\6\s\client\node_modules\@angular\cli\bin\ng'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
The pipeline says it can't find the angular-cli node module. I ran the Docker image on its own and the node_modules folder does exist. I also tried changing the build step to 'ng build --prod'
using powershell and got this error: An unhandled exception occurred: Cannot locate the 'node_modules' directory.
How do I get the pipeline to find the node_modules folder?