title | description | ms.prod | ms.technology | ms.manager | ms.author | author | ms.reviewer | ms.date | monikerRange |
---|---|---|---|---|---|---|---|---|---|
Keep your OSS packages safe with upstream sources | Azure Artifacts |
Use upstream sources in Azure Artifacts to keep your OSS packages safe from failing dependencies. |
devops |
devops-artifacts |
jillfra |
phwilson |
chasewilson |
amullans |
12/04/2018 |
>= tfs-2017 |
Upstream sources enable you to manage your product's OSS dependencies in a single feed. Using upstream sources makes it easy to use your favorite OSS packages, and can also give you additional protection against outages and corrupted or compromised packages. You can also publish private dependencies in the same feed that manages your OSS dependencies. Read all about upstream sources and their benefits.
This tutorial covers how to upgrade an existing project that uses OSS packages from public registries like nuget.org, npmjs.com, etc. to instead get those dependencies from an Azure Artifacts feed with upstream sources.
In this tutorial, you will:
[!div class="checklist"]
- Create a new feed using upstream sources
- Replace the public registry in your configuration files
- Run an initial package restore to populate your feed
- Check your feed to see the saved copy of everything you used from the public registry
- Navigate to Azure Artifacts:
::: moniker range=">= azure-devops-2019"
::: moniker-end
::: moniker range="<= tfs-2018"
::: moniker-end
- Select + New feed:
::: moniker range=">= azure-devops-2019"
::: moniker-end
::: moniker range="<= tfs-2018"
::: moniker-end
- In the dialog, provide a feed name and click Create.
::: moniker range=">= azure-devops-2019"
::: moniker-end
::: moniker range="<= tfs-2018"
::: moniker-end
::: moniker range=">=tfs-2017 < azure-devops"
-
Navigate to the Packages page:
-
Select + New feed:
-
In the dialog:
- Give the feed a name.
- Choose who can read and contribute (or update) packages in your feed.
- Select Use packages from public sources through this feed
- When you're done, choose Create.
::: moniker-end
Now that you've created the feed that we will use to store your packages, you will update your configuration files to point to the newly created feed.
The next step is to update your configuration file to point to the new Azure Artifacts feed instead of the public registry. There are two steps to achieve this:
- Get your feed's URL
- Update the configuration file with the feed URL
::: moniker range=">= azure-devops-2019"
-
From your Packages page, click Connect to Feed
-
Copy the "registry" text:
::: moniker-end
::: moniker range="< azure-devops-2019"
::: moniker-end
After you've got the feed URL, create a new text file named .npmrc
in the root of your project (in the same folder as your package.json
file). Open your new .npmrc
file and paste the text that you copied in step 2 above.
[!INCLUDE get a NuGet URL]
Now that we have the feed URL, we can add our feed as a package source by following these steps:
-
Create a new file named
nuget.config
in the root of your project. -
Copy and paste the template below into your new
nuget.config
file:<?xml version="1.0" encoding="utf-8"?> <configuration> </configuration>
-
Run the following command with your feed name and feed URL:
nuget sources add -Name "<feed_name>" -Source <feed_url> -configfile nuget.config
Now, we recommend a few steps to ensure that we use our feed instead of the public registry. To do so:
-
Add a
<clear />
tag to the<packageSources>
section yournuget.config
file, which was created in the previous step. For example:... <packageSources> <clear /> ... </packageSources>
Now that you have upstream packages set up, you'll need to run an initial package restore to populate your new feed with the upstream packages.
The basic steps are to clear your local package cache and then do a clean install of all the packages used by the project so that Azure Artifacts can save them from the upstream source.
Remove the node_modules
folder in your project (find out more about the node_modules folder), and rerun:
npm install --force
The
-force
option is to ensure the cache is bypassed.
Clear your local package cache:
nuget locals --clear all
Then, download and install packages from the upstream sources:
nuget restore
The instructions above show the simplest way to populate your feed. In larger projects, you can also consider setting up a continuous integration (CI) build that has a clean cache on each build run. This build will then save any new packages from upstream sources as they're used.
Navigate to the feed you created in Step 1. This feed should now be populated with the packages that are used in your project. The Source field contains the public registry, or other upstream source, that you were using before completing this tutorial.