-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker use private NuGet Feed #6135
Comments
Are you building the container using 'docker build'? |
Yes, using the Dockerfile generated by Visual Studio, and the VSTS build template, |
You can't use Instead, build the product including getting dev dependencies from nuget (that could also be in a container) to a mapped output container and then when you do We are working on first class docker support in VSTS which means you can say step 1 runs in container x and then run docker build. If you email me at bryanmac (and that's at microsoft) I can share more details. |
I believe that's what my
Which is building correctly and the |
@Hinton - you're doing the dotnet restore in the docker file. You're also copying the nuget.config. What I'm saying is you do the dotnet restore and dotnet build outside the docker build file. The docker build file would copy in the resultant full product layout bits (your output). |
... that also has the benefit of not requiring build tools in your products final container (small as possible). You can have a docker dev image that is based on the prod image and only the dev image has dev tools. |
@bryanmacfarlane I understand that's a potential way to solve it. Docker build would then only copy the pre-built binary files and not actually build anything.
The |
@bryanmacfarlane Your proposal is antithetical to the promise of multi-stage build and to some degree to Docker itself. The promise of consistent and predictable execution environments applies nicely to build/CI environments as well. On the question, I don't think we've got a great solution for this currently. Ideally, you could specify a nuget.config via an environment variable. I don't think this will work w/o getting NuGet to become secret aware. I'll ask. |
@richlander I agree with you. @bryanmacfarlane One of the big advantages of docker is being able to have a new developer build the solution with no prereqs installed except docker. In this way, they don't even need .NET core installed to build a .NET application. Also, @Hinton is correct in a multi-stage build only the last build stage is kept so, the build stage along with any secrets and/or SDK and build tools will not end up in the final docker image produced for your application. |
@Hinton , @richlander, and @AceHack - I see where you're coming from. In VSTS we happen to have a focus on using containers for deployments. As such, we wanted to make sure you weren't putting VSTS PATs inside your deployments - and you're not! ✔️ It makes sense that you're asking for a better solution for the reproducible build scenario. We're chatting with @AndyGerlicher about this. |
@jerickmsft That's great to hear, I've worked up my own solution for passing though tokens to do authenticate with the registry. I'm now working on, unit tests and getting the results into VSTS, integration tests, code coverage, performance profiling, running static analysis, white source, and the list goes on and on. Doing your build inside the docker container makes many of the VSTS tasks hard or impossible to use. I'm having to come up with my own solutions to all of these. It's not really possible to find any guidance on these subjects either. Thanks. |
Hi All, I was wondering if there has been any progress on allowing a VSTS private NuGet package feed to be read from the dockerfile build process? I've tried creating a nuget.config file that can be then read by the dockerfile COPY nuget.config /root/.nuget/NuGet/ which is created at build time using a PAT token, but no success, still a 401 error. Thanks. |
What worked for me... using the PAT token. My dockerfile:
and my NuGet.Config file:
The Username parameter need to be passed but you can set a random username/phrase there... since PAT does not have username parameter. |
@danilobreda - is your PAT token now in a layer of your docker container? |
@AceHack - regarding building in container and dependencies - agreed. Both solutions build in a container. Building in a container is great for dev == dev == ci. It's awesome. Regarding tasks and the CI solution still working (tasks etc... ) and secrets not getting into layers (maps work dirs into container outside in), we will be previewing the ability to run any phase in a container (full yaml and task fidelty). We're waiting on the rollout of a couple new hosted pools optimized for building containers. This and this. I'm not advocating one over the other and docker build is an option. I'm just providing options while making it clear there's pros and cons to different approaches. Be aware of them. Pushing an image to a public repo with a token or cred in the layers is a real problem and concern. We also have using kubernetes as a build pool (infra) in proof of concept phase working end to end. |
After some tests, its not on layers... the final docker is on the /output folder. It have only the "publish" output. |
@danilobreda - one other note - does your current approach require you to check in your PAT to source code? (or some other process is generating it host side?) |
Since this issue is getting some activity again, I figured it might be worthwhile to describe, more in-depth how we worked around the issue (for now). In our build definitions, before the docker tasks we have a
The secret variable is linked through a variable group to our built tasks and contains the complete This ensures the Note that this works using the linux agents, on windows the bash script should be replaced with a PowerShell equivalent. |
For private nuget package or packages on Disk, I have the next Nuget.Config and Docker File. This works for me. ? xml version="1.0" encoding="utf-8" ?> `FROM microsoft/aspnetcore:2.0 AS base FROM microsoft/aspnetcore-build:2.0 AS build COPY NuGet.Config ./ WORKDIR /src #RUN dotnet restore -nowarn:msb3202,nu1503 FROM build AS publish #Try to create image from Publish output FROM base AS final |
@bryanmacfarlane ho, its on the code.. yes you are right. I think we can set the PAT as a enviroment variable... and pass it with the dockerfile ARG and ENV. Its something to test. |
@danilobreda - yeah, that's what the yaml feature I pointed to above does. It gets source in the host and maps it into the container we spawn, then exec tasks in the container. That would allow you to use Secure Files and all other tasks. You also wouldn't need to copy it into the container or remember to delete. That needs a good dev == dev solution though. Not sure, but I believe if you use ENV, that can get sealed in a layer. Might have to use ARG. |
I have a Nuget custom task that adds the builds access token to the config. That way the token only lives for the life of the build and you don't have to worry about storing it in clear text in the config. Another nice thing is you don't need to remember to replace an expiring PAT.
Make sure that you also have"Allow scripts to access OAuth token" checked on the options tab. I'm happy with this as a placeholder a better solution is presented. |
Looks like this will be a reality soon-ish :) Just requires BuildKit to be enabled, which is possible from Docker 18.06-CE. |
"--secret" won't be supported on 18.06 daemons though, the version of buildkit |
@cpuguy83 Sorry for the confusion. Meant that BuildKit's included (experimentally) since 18.06. Looking at the PR --secret will likely be in 18.09, right? |
Correct. |
So it will be possible to pass the PAT as a secret? How it will help for Docker use private NuGet Feed, can somebody clarify? Thanks. |
Seriously, when is this going to be fixed? I've done ALL the different solutions in this discussion and anything works! When is this going to be fixed? I've been blocked for the last 3 weeks. |
The solution posted by @cwoolum seems to best solution I've encountered so far. Documentation on this scenario is VERY lacking. It seems like either the Azure Pipelines or Azure Artifacts docs should contain an example of the cross platform friendly way to do a package restore from a private Azure Artifacts feed from within a docker container. I wasted LOTS of time trying to get to this solution and we're still left wondering if this is the "best" or "recommended" approach (I suspect it is). |
@cwoolum Unfortunately, changing the value of an ARG does cause a cache miss on the first use of that variable, causing the rest of the image to be rebuilt (including the dotnet restore), see Dockerfile reference. |
Using Docker build secrets, I was finally able to come up with a solution that properly handles caching and is also secure. Check out my blog post on it This solution doesn't work with Docker Compose yet and requires at least Docker 18.09 to work. |
@cwoolum Really nice! The buildx plugin, which is available in the current 19.03 betas can also build compose files via BuildKit, which means it also has support for mounting secrets and caches. It works via the ‘docker buildx bake’ command. Buildkit support in docker-compose depends on docker/docker-py#2230, which probably won’t be fixed in 19.03. |
I may have misunderstood something, but none of these solutions seem to work for using Docker from Visual Studio with Windows-based containers, right? apt-get would be out because of Linux, using Azure DevOps tasks is out because this wouldn't work inside Visual Studio and using Visual Studio project modifications like DockerfileBuildArguments don't seem to allow dynamic replacements like environment variables, only static text (which would commit the secret into the repo). As of yet, I did not find a solution to use a .NET Core project with Windows-based Docker containers that allow running via F5 from inside Visual Studio. Am I missing something? |
In Visual Studio, I've noticed that the build tools don't use the entire Dockerfile so restore works when building in Visual Studio. From what I can tell, it only uses the base image or the first few lines but I'm not positive on that. I've never had issues with F5 just working for Docker containers, no matter what Dockerfile I've had. For making this work in a deployed environment, |
I found this blog post really helpful and I take no credit for the solution. https://blog.ehn.nu/2019/05/accessing-azure-artifacts-feed-in-a-docker-build/ A workaround is to add a step in your dockerfile to download the microsoft azure cred provider and you pass your PAT as a build arg to docker.
|
The info provided by @heratyian works perfectly for me and is easy to implement. |
We already have that solution above but it prevents the |
I've come up with another way to use private Nuget repos in Azure Pipelines builds. It uses service containers so you'll need to be able to use YAML builds to support it. The BuildKit solution I had above worked but you lost the ability to use See the repo with the proxy and an example at https://github.com/cwoolum/ThinNugetProxy. |
Thanks! This worked for me. Regards! |
This is normal. When you request your packages from the Azure Artifacts
source, Azure Artifacts will look upstream at Nuget.org and cache the
packages.
You can remove Nuget.org as an upstream source but then you'll need to
ensure your nuget config in your solution has that source and your Azure
Artifacts source so it can search both.
…On Tue, Mar 24, 2020 at 6:43 AM andrew-vdb ***@***.***> wrote:
By doing this, it will push ALL dependencies to azure artifacts
[image: image]
<https://user-images.githubusercontent.com/12871379/77431837-8c768900-6ddd-11ea-99a4-f74bb09855cf.png>
[image: image]
<https://user-images.githubusercontent.com/12871379/77431913-aa43ee00-6ddd-11ea-93e3-cd4700e9c45d.png>
Is this normal? expected?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6135 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHGCT6TT24JLTRG4QOT66TRJC2GJANCNFSM4EKHIBMA>
.
|
@cwoolum Thanks for the reply, I already deleted my post... For anyone else, I was asking why the nuget.org packages being copied to my azure private nuget feed Another problem now, for local development, regular container development mode, for build pipeline we use $(System.AccessToken) Update: Is there any better way than this? |
You wouldn't put that config in your project file. In Visual Studio 2019,
you would already be authenticated via your account. For your builds, you
would pass the PAT as a task parameter in your docker or docker-compose
build step. See my posts above for more details. At no point should you
need to specify the PAT manually.
…On Tue, Mar 24, 2020 at 11:13 PM andrew-vdb ***@***.***> wrote:
@cwoolum <https://github.com/cwoolum> Thanks for the reply, I already
deleted my post... For anyone else, I was asking why the nuget.org
packages being copied to my azure private nuget feed
Another problem now, for *local development, regular container
development mode*, for build pipeline we use $(System.AccessToken)
What do we do with local development? at this moment I put my own PAT
[image: image]
<https://user-images.githubusercontent.com/12871379/77505326-1e74a500-6e63-11ea-9615-1dd5ae3ea048.png>
I can't share this with others
Update:
I put my own PAT within this file now, .csproj.user
[image: image]
<https://user-images.githubusercontent.com/12871379/77506822-1a4a8680-6e67-11ea-9ee7-325320948013.png>
Is there any better way than this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6135 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHGCT6IOQRMAC34M7MTKUTRJGOHZANCNFSM4EKHIBMA>
.
|
I believe you use fast mode, not regular mode.... |
Have folks seen Managing NuGet Credentials in Docker Scenarios? It seems closely related to this topic. /cc @mthalman |
It might be the same approach, but I prefer to use the dotnet cli to add the nuget source + credentials. Especially if you use a multi-stage build, the nuget config that stores the token is removed afterwards. There is no need to add a specific packages as i think. Especially if you run it Azure Pipelines you can just inject the $(System.AccessToken) as the PAT argument. It would look like this in the dockerfile
|
As @richlander pointed out this is something to follow up on the dotnet-docker repo: |
Reading through so many solution and implementing them , i was huffed and puffed . please don't forget to add username in ENV variable otherwise you will have 401.
|
My question is: How to make |
I'm trying this latest approach and the Docker build step isn't interpolating the variable usage for the build-args: I tried the above with no quotes and single quotes as well. Here is the important part of my Dockerfile: And when I look at the logs of the failed build, I see that it is sending the password to my private source like this: |
Reminder: Do NOT NOT NOT put secrets/credentials as ENV vars into layers that you ship. Docker loves to store your environment variables as part of the layer. If you are not careful you will ship your credentials with the layers you create. See: |
did you come right with this? |
Environment
Issue Description
When building docker containers I would like to be able to use private NuGet feeds hosted on VSTS (Packaging). Currently there does not seem to be a good way to do this other than including a NuGet.config file with clear text credentials, which is less than optimal.
The .NET core task (v4) has options for NuGet feeds, and it would be nice if the Docker containers worked the same.
The text was updated successfully, but these errors were encountered: