I searching the syntax to do dotnet restore with azure devops feed and not global nuget.
ARG nuget_repository=https://api.nuget.org/v3/index.json
RUN dotnet restore "Xyz.csproj" -s ${nuget_repository}
i have the id of the feed
You could check the Azure Nuget feed URL from Azure Artifacts -> Connect to feed -> Nuget
Sample:
ARG PAT=xx
RUN dotnet restore "Xyz.csproj" -s
https://:${PAT}#pkgs.dev.azure.com/AzureTest23/_packaging/234/nuget/v3/index.json
Related
I have a simple dockerfile which I am trying to inject vc_redist into the container, when I build the image using docker desktop my appliaction runs correctly, however when I build the same image in Azure Pipeline and than pull that image from Azure Container Registry I am missing the vc_redist layers. Why is there a difference between building the image using docker desktop and Azure Pipeline Tasks? Here is a sample of my dockerfile
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019 AS base
WORKDIR /app
USER ContainerAdministrator
ADD https://download.visualstudio.microsoft.com/download/pr/9fbed7c7-7012-4cc0-a0a3-a541f51981b5/e7eec15278b4473e26d7e32cef53a34c/vc_redist.x64.exe /vc_redist.x64.exe
RUN /vc_redist.x64.exe /norestart /install /quiet
RUN del /vc_redist.x64.exe
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /src
RUN dotnet restore .....
COPY . .
RUN dotnet build ....
FROM build AS publish
RUN dotnet publish ...
FROM base AS runtime
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["myapp.exe"]
your URL is not working here. (it's probably a private URL only for your IP or time based)
see https://github.com/microsoft/dotnet-framework-docker/issues/15
he uses a Microsoft download link that is working
https://download.microsoft.com
while you use a visual studio link https://download.visualstudio.microsoft.com/
I would suggest to download the installer and re-upload it to a gist or GitHub, or just add the file itself to the docker
My goal
I want to publish a docker image to Dockerhub from the Azure DevOps Pipeline.
The pipeline runs after a commit on the master branch in Gitlab.
The application I want to build an image for is a .Net Core Web API project.
I'm using the automatically created Dockerfile by dotnet.
Error
This is the error I get:
Information
The folder structure of my application looks like this:
- APIGateway [Folder]
- APIGateway [Folder]
- Controller/Models/Services etc... [Folders]
- APIGateway.csproj
- APIGateway.csproj.user
- **Dockerfile**
- Program.cs
- Startup.cs
- Appsettings,json
- Appsettings.Development.json
- APIGateway.UnitTests [Folder]
- .dockerignore
- APIGateway.sln
- Readme.md
My Dockerfile looks like this:
For the Azure Pipeline, I added the .Net Core template task (restore, build, test, publish, publish artifect) to the agent job. The pipeline executes these tasks successfully.
I also added the Docker BuildAndPush task and configured my Dockerhub as a container registry.
The commands for the BuildAndPush task:
I already looked at this similar post: Azure Pipeline to build docker images fails using same docker file in Visual Studio. People mainly suggested to add 'Build.Repository.LocalPath' to the build context. But I still get the same error.
Does anyone know how to solve this issue?
Others have alluded to this in the comments.
Given you have a folder structure containing multiple projects within a solution similar to this:
AND your Dockerfile was created in one of the projects within the solution (e.g., the Server project) similar to this (e.g., generated by VS-right click, Add Docker support):
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Server/QuizManagerClientHosted.Server.csproj", "Server/"]
COPY ["Client/QuizManagerClientHosted.Client.csproj", "Client/"]
COPY ["Shared/QuizManagerClientHosted.Shared.csproj", "Shared/"]
RUN dotnet restore "Server/QuizManagerClientHosted.Server.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "QuizManagerClientHosted.Server.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "QuizManagerClientHosted.Server.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "QuizManagerClientHosted.Server.dll"]
Problem: It works locally but not via ADO (or perhaps GitHub Actions or other CI/CD solutions).
Solution: Move the Dockerfile up one level (e.g., from the Server directory to the QuizManagerClientHosted directory).
Here is the problem:
I have to send a asp.net core 3.1 api to a client.
I did published it through VisualStudio as self-contained (linux-64x) in order to ship less files as it is a third-part partner.
Before sending it i'm trying to test it with docker. The client wont have access to any code repository or anything, except the package. How to make it run throug Dockerfile? I've tried several examples but none of them seems to work. I'm new to docker but what i found is that every dockerfile example does things like "dotnet build" or "dotnet publish", but the Api is already published. I just need it to run with the dockerfile.
Dockerfile im using:
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1.0-alpine3.10
WORKDIR /api
COPY publish/Api api
ENV ASPNETCORE_URLS=http://+:5000
CMD ["./api"]
Generated files from VS publish (except Dockerfile)
UPDATE
Doing like this gives me "permission denied" error:
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1.0-alpine3.10
COPY . api
ENV ASPNETCORE_URLS=http://+:5000
CMD ["./api"]
UPDATE 2
Build command is:
docker build .
Folder structure:
If you publish it like:
dotnet publish Api/Api.csproj -c Release -o /publish
then try this one
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1.0-alpine3.10
WORKDIR /api
COPY /publish .
ENV ASPNETCORE_URLS=http://+:5000
ENTRYPOINT ["dotnet", "Api"]
add
RUN chmod +x Api
after copy
I am starting to investigate Azure Devops and its pipelines feature for setting up a continuous integration workflow. I have a pipeline that builds a Docker image of my application using the following dockerfile:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build-env
WORKDIR /cicd
# restore (put more volatile, changing projects later in process)
COPY src/WebApp/WebApp.csproj ./src/WebApp/
RUN dotnet restore src/WebApp/WebApp.csproj -s http://mycontainerrepo.acme.com/repository/nuget/
COPY tests/WebApp.Test/WebApp.Test.csproj ./tests/WebApp.Test/
RUN dotnet restore tests/WebApp.Test/WebApp.Test.csproj -s http://mycontainerrepo.acme.com/repository/nuget/
# copy source
COPY . .
# test (if tests fail, no final image, yay)
RUN dotnet test tests/WebApp.Test/WebApp.Test.csproj
# publish
RUN dotnet publish src/WebApp/WebApp.csproj -o /publish
# runtime stage
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS release
COPY --from=build-env /publish /publish
WORKDIR /publish
ENTRYPOINT ["dotnet", "WebApp.dll"]
The call to run dotnet test executes just fine and outputs results to the console, but I don't know of any way to make use of this result in the pipeline. In TeamCity, you could set an environment variable to sort of trick it into outputting the test results (xUnit only, I think...). But not sure if there's a similar trick here...
I saw this post on Github about making a separate test image just for testing but was hoping to avoid that route unless its my only option.
Any other CI/CD Azure Devops gurus out there?
I am using Visual Studio Team Services to build a .NET Core container with the aspnetcore image. If I build the image from source on a Linux machine, I can run it and curl localhost works great.
However, the same exact code running in VSTS, building the same image, yields a different result. I'm using the "Hosted Linux Preview" to build the image, which works. The CI build succeeds and uploads the image to my private Azure registry. When I run that image, on the same Linux machine mentioned above, it exits immediately with this error in the log:
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:...
Here is the Dockerfile:
FROM microsoft/aspnetcore:1.1
WORKDIR /app
COPY published .
ENV ASPNETCORE_URLS http://+:80
EXPOSE 80
ENTRYPOINT ["dotnet", "ContainerPOC.dll"]
The error is caused by what looks like a bug in the dotnet Publish task on VSTS. When this command is configured:
dotnet publish --output publish
This is executed:
dotnet publish --output publish/s
The appended /s causes the output to go to a subfolder called "s" in the publish folder. I changed the Dockerfile to reflect this location (the COPY directive) and all is well.
The error is reproducible:
Comment out the ENTRYPOINT directive
Build the image
Run a container from the image and execute an interactive bash shell
Execute the dotnet command and specify an assembly name that is not present in the working directory
The Did you mean..? error will appear. Not a very descriptive error given the situation.