Azure Devops nuget artifact feed and docker

前端 未结 2 1825
一生所求
一生所求 2021-01-28 03:30

Is there a good way to create an authentication mechanism to Devops to be able to access the artifact NuGet feed? I would like to create a base image for my team that would allo

2条回答
  •  攒了一身酷
    2021-01-28 04:18

    YAML

    1. Run NuGetAuthenticate task to add VSS_NUGET_ACCESSTOKEN to environment variables (more info)
    2. Pass token to Docker task as an argument
    - task: NuGetAuthenticate@0
    
    - task: Docker@2
      displayName: 'build docker image'
      inputs:
        command: build
        containerRegistry: 'happycodeacr'
        repository: 'hc-app-sample-api-dev'
        buildContext: '$(Pipeline.Workspace)/app'
        Dockerfile: '$(Pipeline.Workspace)/app/src/HappyCode.Api/Dockerfile'
        arguments: '--build-arg FEED_ACCESSTOKEN=$(VSS_NUGET_ACCESSTOKEN)'
        tags: |
          latest
          $(Build.BuildId)
    

    Dockerfile

    1. Download and install artifacts provider (more info)
    2. Receive token
    3. Set VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable with feed url and token for nuget restore process
    4. Copy NuGet.config file
    5. Run dotnet restore
    FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
    WORKDIR /work
    
    RUN curl -L https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh  | sh
    ARG FEED_ACCESSTOKEN
    ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS \
        "{\"endpointCredentials\": [{\"endpoint\":\"https://happycode.pkgs.visualstudio.com/_packaging/hc-nuget-feed/nuget/v3/index.json\", \"password\":\"${FEED_ACCESSTOKEN}\"}]}"
    COPY ["NuGet.config", "./"]
    
    COPY ["src/*/*.csproj", "./"]
    RUN for projectFile in $(ls *.csproj); \
        do \
          mkdir -p ${projectFile%.*}/ && mv $projectFile ${projectFile%.*}/; \
        done
    RUN dotnet restore /work/HappyCode.Api/HappyCode.Api.csproj
    
    # further instructions 
    
    

提交回复
热议问题