Search code examples
angulardockerazure-pipelinessingle-page-applicationwindows-container

Azure pipelines build failed for SPA docker windows container


I am using Asp.net core with angular and docker windows container. Here is dockerfile as below:

Dockerfile:

#escape=`
FROM mcr.microsoft.com/powershell:nanoserver-1809 AS downloadnodejs
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip"; `
Expand-Archive nodejs.zip -DestinationPath C:\; `
Rename-Item "C:\node-v10.16.3-win-x64" c:\nodejs

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY --from=downloadnodejs C:\nodejs\ C:\Windows\system32\

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
COPY --from=downloadnodejs C:\nodejs\ C:\Windows\system32\
WORKDIR /src
COPY ["DemoAngularWindows.csproj", "./"]
RUN dotnet restore "./DemoAngularWindows.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "DemoAngularWindows.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DemoAngularWindows.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DemoAngularWindows.dll"]

I run docker and no issue. But now I have pushed repo into azure devops and have created docker build and push an image to container registry piplines. I am getting error message and it says as below:

Invoke-WebRequest: Access to the path 'C:\nodejs.zip' is denied.
The command 'pwsh -Command $ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue'; Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip"; Expand-Archive nodejs.zip -DestinationPath C:\; Rename-Item "C:\node-v10.16.3-win-x64" c:\nodejs' returned a non-zero code: 1
##[error]The process 'C:\Program Files\Docker\docker.exe' failed with exit code 1
Finishing: Build and push an image to container registry

enter image description here

azure-pipelines.yml:

trigger:
- master

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '43a885d5-3f2b-417d-9df3-eaac92ed0a20'
  imageRepository: 'demoangularwindows'
  containerRegistry: 'democontainerregistryname.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/DemoAngularWindows/Dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'windows-2019'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: |
          $(tag)

Ref: https://learn.microsoft.com/en-us/visualstudio/containers/container-tools-react?view=vs-2019#modify-the-dockerfile-windows-containers

Could you please help to resolve this issue?

Thanks


Solution

  • Azure pipelines build failed for SPA docker windows container

    I could reproduce this issue on my side:

    enter image description here

    According to the error messages this issue is noticed as a permission issue, please try to create a WORKDIR, then execute your SHELL scripts in that directory:

    FROM mcr.microsoft.com/powershell:nanoserver-1809 AS downloadnodejs
    RUN mkdir -p C:\nodejsfolder
    WORKDIR C:\nodejsfolder
    SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
    

    As test, that error disappeared:

    enter image description here

    Hope this helps.