0
votes

I am desperately trying to build a dotnet core 3.1 project, and then make an image from it with docker and push that image to my registry

Here is my azure-pipeline.yaml:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- none

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: obs-devops-global-variables
  # Put variable group for your team  (variable groups in Pipelines-->Library)
  - group: obs-devops-tso-variables
  - name: AzureSubscription
    value: 'obs-acr-sc-dev'
  - name: ACR
    value: obsaksacrdev.azurecr.io
  - name: ImagePrefix
    value: obs-$(team)/
  # Put name of Image same like name of repo
  - name: ImageName
    value: obs-datalake-raw2gold
  - name: BuildConfiguration
    value: 'Release'
  - name: imageTag
    value: '4.0.$(build.buildId)'
  - name: rid
    value: 'linux-x64'

steps:
#- script: |
#    dotnet restore
#    dotnet build
#    dotnet publish ./RawToGold.Worker/ --configuration $(buildConfiguration) 

- task: UseDotNet@2
  inputs:
    version: '3.1.x'
    packageType: sdk

- task: DotNetCoreCLI@2
  displayName: 'dotnet build $(buildConfiguration)'
  inputs:
    command: 'build'
    arguments: '-r $(rid) --configuration $(buildConfiguration) /p:SourceRevisionId=$(Build.SourceVersion)'

- task: DotNetCoreCLI@2
  displayName: "Publish"
  inputs:
    command: 'publish'
    publishWebProjects: false
    arguments: './RawToGold.Worker/ -r $(rid) --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: false


- task: Docker@1
  displayName: 'Containerize the micro service'
  inputs:
    useDefaultContext: false
    azureSubscriptionEndpoint: '$(AzureSubscription)'
    azureContainerRegistry: '$(ACR)'
    dockerFile: 'Dockerfile'
    imageName: '$(ACR)/$(ImagePrefix)$(ImageName):$(imageTag)'

- task: Docker@1
  displayName: 'Push image'
  inputs:
    azureSubscriptionEndpoint: '$(AzureSubscription)'
    azureContainerRegistry: '$(ACR)'
    command: 'Push an image'
    imageName: '$(ACR)/$(ImagePrefix)$(ImageName):$(imageTag)'

- task: PublishPipelineArtifact@1
  displayName: 'Publish Pipeline Artifact'
  inputs:
    artifactName: 'k8s'
    targetPath: 'k8s'

And here is my docker file

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-bionic

RUN groupadd --gid 1000 rawtogold \
  && useradd --uid 1000 --gid rawtogold --shell /bin/bash --create-home rawtogold

USER rawtogold

#Use locally
#COPY ./RawToGold.Worker/bin/Release/netcoreapp3.1/publish /home/rawtogold/app/
COPY . /home/rawtogold/app/
RUN ls /home/rawtogold/app/
WORKDIR /home/rawtogold/app/
ENTRYPOINT ["dotnet", "RawToGold.Worker.dll"]

But the compiled code is not copied into the image? I have tried both the COPY . /home.... and the COPY ./RawToGold.Worker/bin/Release/netcoreapp3.1/publish which I would use on my local development machine to build the image. But how do I control the buildContext of the dockerfile. And adding input: buildContext to the task does NOT help in Docker@1 If I build it using powershell (the lines uncommented in the top" I can actually access the files using the ./RawToGold.Worker/bin/Release/netcoreapp3.1/publish But I would like to know how to control the docker build context in docker@1

1
Do you get any error message? Could you share your pipeline log? In addition, please refer to the following link to build an image: docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/…Cece Dong - MSFT
I gave up and turned to docker@2 instead. Works OKLars Christoffersen

1 Answers

0
votes

Actually I gave up on this and started to use Docker@2 instead, which works flawlessly, The Docker@1 is deprecated any way