3

I'm running a CI pipeline (ubuntu-latest) and I'm trying to save a docker image as an artifact for later usage on a release pipeline, however I keep getting the same error:

error

This is my complete pipeline setup:

pool:
  name: Azure Pipelines
variables:
  ImageName: 'thecreatorshare'

steps:

- task: CopyFiles@2
  displayName: 'Copy Files to Staging Directory'
  inputs:
    SourceFolder: core
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: DockerInstaller@0
  displayName: 'Install Docker'

- task: Docker@2
  displayName: 'Build Image'
  inputs:
    containerRegistry: 'azure-registry-conn'
    repository: '$(ImageName)'
    command: build
    Dockerfile: core/Dockerfile

- task: Docker@2
  displayName: 'Save Image'
  inputs:
    containerRegistry: 'azure-registry-conn'
    repository: '$(ImageName)'
    command: save
    arguments: '$(ImageName):$(Build.BuildId) > $(Build.ArtifactStagingDirectory)/$(ImageName).tar'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Image as Artifact'

And finally, this is my Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /web
COPY . .

RUN dotnet restore "Presentation.Web/Presentation.Web.csproj" -s https://api.nuget.org/v3/index.json

WORKDIR "/web/Presentation.Web"
RUN dotnet build "Presentation.Web.csproj" -c Release -o /app/build

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

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

After a whole day of failed attempts, I am clueless as what to do, any help is much appreciated!

Andrew Fox
  • 69
  • 1
  • 7
  • 2
    I think you have some confusion. Once you "Build" a container image you cannot save it like a regular File in the Artifacts Staging Directory and then Publish it as an Artifact. What you need to do instead is PUBLISH it to a Container Registry. Then later in another pipeline you need to use the docker command to PULL it (which downloads it). I have my own method to save meta-data (which I do save an a Build Artifact) to pass to the next pipeline so I can pull the container image. – Antebios Dec 28 '21 at 19:57
  • @Antebios I was following a different approach, which seems to be a less known way, perhaps not even a "good" way, considering the issues I've been facing. https://dev.to/n3wt0n/container-image-promotion-across-environments-build-artifact-5887 – Andrew Fox Dec 28 '21 at 20:02
  • 1
    Well, technically you can save a docker image as a physical file, but it is really REALLY huge. You would have to SAVE it to a physical file first with the "-o" argument. But please do not do this. Avoid this at all costs because Windows container images are GB in size (2016 are 15-20 GB, 2019 are a little smaller, nano images are even smaller, etc). See: https://docs.docker.com/engine/reference/commandline/save/ – Antebios Dec 28 '21 at 20:12
  • [Azure DevOps Docker Task](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker?view=azure-devops#task-inputs) only allows the following commands: `buildAndPush`, `build`, `push`, `login`, `logout` – usuario Dec 28 '21 at 22:12
  • 1
    @AndrewFox Yeah, that blog is full of bad advice. Deployments of images should be handled by using good semantic versioning practices, not dumping an image as a pipeline artifact. – Daniel Mann Dec 29 '21 at 16:57

0 Answers0