I am using Azure Pipelines and have successfully built a pipeline to build and deploy a docker image to azure app services.
Now I am trying to figure out how to build a docker image in a pipeline and then publish it to the artifact staging directory so I can push it to the azure container registry instead. I have looked all over google to see how this is done with no luck, this is going to be a three part question.
I am successfully building a dockerfile in my pipeline with the exception that I can not figure out how to delete a temporary file (keep getting access denied)
Removing intermediate container 543fb86650c4
---> 3ccb8c3a555e
Step 10/28 : RUN del -f "./NuGet.Config"
---> Running in c2ba7a3266a4
C:\src\NuGet.Config
Access is denied.
The image build continues from there and succeeds but I am trying to publish an artifact, I want to take the built image and pass it to the release pipeline to be pushed to azure container registry. The publish artifact fails because it cant find the image, and I am really not sure how to find it?
##[warning]Directory 'd:\a\1\a' is empty. Nothing will be added to build artifact 'Email'.
Maybe I am going about this all wrong? If so, please suggest an alternative, just remember I want to push my docker image to the azure container registry instead of the azure app service.
Question 1: How can I delete the file within the container in the pipeline task?
Question 2: How do I push a docker image to the Azure container registry instead of the Azure app service?
I am using the UI to configure my pipeline and do not have a full yaml file to share but here is the yaml from the view option:
pool:
name: Azure Pipelines
variables:
Parameters.ArtifactName: 'Email'
steps:
- task: Docker@2
displayName: 'Build an image'
inputs:
containerRegistry: 'Azure Container'
repository: email
command: build
Dockerfile: Services/Email/Email/Dockerfile
buildContext: Services/Email
tags: latest
arguments: '-o $(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
Question 3: Once I get the file to publish to the artifact staging directory how would I access it to push the image to the container registry?
UPDATE TO INCLUDE DOCKERFILE
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
WORKDIR /src
COPY ["Email/Email.csproj", "Email/"]
COPY ./NuGet.Config ./
RUN dotnet restore "Email/Email.csproj" --configfile ./NuGet.Config
RUN del "./NuGet.Config"
COPY . .
WORKDIR "/src/Email"
RUN dotnet build "Email.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Email.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Email.dll"]