JavaScript and npm package consumption in a large organization is typically
managed by a repository manager. Commonly used repository manager applications
are JFrog Artifactory, Sonatype Nexus
Repository, and
others. The repository manager acts as a single point of access for developers
and development tools to retrieve the required libraries.
At a high level, adopting the use of Chainguard Libraries consists of the
following steps:
Add the Chainguard Libraries for JavaScript registry as a remote repository
for library retrieval.
Configure the repository as the first choice for any library access. This
ensures that any future requests of new libraries access the version supplied
by Chainguard. Typically this is accomplished by creating a group repository
or virtual repository that combines the repository with other external and
internal repositories.
Additional steps depend on the desired insights and can include the following
optional measures:
Remove all cached libraries in the proxy repository of the npm Registry. This
step allows you to validate which libraries are not available from Chainguard
Libraries and proceed with potential next steps with Chainguard and your own
development efforts.
Remove any repositories that are no longer desired or necessary. Depending on
your library requirements this step can result in removal of some proxy
repositories or even removal of all proxy repositories.
Adopting the use of a repository manager is the recommended approach, however if
your organization does not use a repository manager, you can still use
Chainguard Libraries. All access to the Chainguard Libraries repository is then
distributed across all your build platforms and therefore more complex to
configure and control. Refer to the direct access documentation for build
tools for more
information.
Cloudsmith
Cloudsmith supports npm registries repositories for
proxying and hosting. Refer to the npm registry
documentation and the npm
Upstream
documentation
for Cloudsmith for more information. Cloudsmith supports combining repositories
by defining multiple upstream repositories.
Initial configuration
Use the following steps to add a repository with the npm registry and the
Chainguard Libraries for JavaScript repository as npm upstream repositories.
Configure a javascript-all repository:
Log in as a user with administrator privileges.
Select the Repositories tab near the top of the screen.
On the Repositories page, click the + New repository button.
Enter the name javascript-all for your new repository. The name should
include javascript to identify the ecosystem. This convention helps
avoid confusion since repositories in Cloudsmith are multi-format.
Select a storage region that is appropriate for your organization and
infrastructure.
Press + Create Repository.
Configure an upstream proxy for the npm registry:
Click the name of the new javascript-all repository on the repositories
page to configure it.
Access the Upstreams tab and click + Add Upstream Proxy.
Configure an upstream proxy with the format npm and the following details:
Configure another upstream proxy with the following details
Namejavascript-public
Priority2
Upstream URLhttps://registry.npmjs.org/
ModeCache and Proxy
Press Create Upstream Proxy.
Configure an upstream proxy for the Chainguard Libraries for JavaScript
repository:
Click the name of the new javascript-chainguard repository on the
repositories page to configure it.
Access the Upstreams tab and click + Add Upstream Proxy.
Configure an upstream proxy with the format npm and the following details:
Use this setup for initial testing with Chainguard Libraries for JavaScript. For
production usage, add the javascript-chainguard upstream proxy to your production
repository.
Build tool access
The following steps allow you to determine the URL and authentication details
for accessing the repository:
Select the Packages tab.
Press Push/Pull Packages.
Choose the format NPM.
Refer to the Pull Package tab.
Note the registry URL and syntax from the code snippets for npm. For example,
the URL for the registry in the example organization is
https://npm.cloudsmith.io/example/javascript-all/.
Note that authentication is using an authentication token and the syntax for
npm in the example organization is
//npm.cloudsmith.io/example/javascript-all/:_authToken=YOUR-API-KEY
Use the provided code snippets directly for your use with npm, or adjust as
necessary for other JavaScript build and packaging tools. Find relevant details
in the Build
Configuration and
specific packaging tool documentation.
Use the following steps to retrieve the necessary API key as an authentication
token for the registry access:
Click on your user name at the top, right corner.
Select Personal API keys*.
Authenticate again in the Confirm access dialog.
Create a new token or refresh the existing one in case you lost the token
value.
Use the following steps to add the npm Registry and the Chainguard Libraries for
JavaScript repository as remote repositories and combine them as a virtual
repository:
Log in as a user with administrator privileges.
Press Administration in the top navigation bar.
Select Repositories in the left hand navigation.
Configure a remote repository for the npm Registry:
Press Create a Repository and choose the Remote option.
Select Npm as the Package type.
Set the Repository Key to javascript-public.
Set the URL to https://registry.npmjs.org .
Press Create Remote Repository.
Configure a remote repository for the Chainguard Libraries for JavaScript
repository:
Press Create a Repository and choose the Remote option.
Select Npm as the Package type.
Set the Repository Key to javascript-chainguard.
Set the URL to https://libraries.cgr.dev/javascript/.
Combine the two repositories in a new virtual repository:
Press Create a Repository and choose the Virtual option.
Select Npm as the Package type.
Set the Repository Key to javascript-all.
Scroll down to the Repositories section.
Add the javascript-chainguard and javascript-public repositories. Ensure
the javascript-chainguard repository is the first in the displayed list.
Use the icon on the right of the repository name to drag and drop
repositories into the desired position.
Press Create Virtual Repository.
Use this setup for initial testing with Chainguard Libraries for JavaScript. For
production usage add the javascript-chainguard repository to your production
virtual repository.
Build tool access
The following steps allow you to determine the URL and authentication details
for accessing the repository:
Press Administration in the top navigation bar.
Select Repositories in the left hand navigation.
Select the Virtual tab in the repositories view.
Locate the javascript-all repository.
Hover over the row and click the … in the last column on the right.
Select Set Me Up in the dialog.
Press Generate Token & Create Instructions.
Copy the generated token value to use as the password for authentication.
Press Generate Settings.
Copy the value from a url field. The are all identical. For example,
https://exampleorg.jfrog.io/artifactory/javascript-all/ with exampleorg
replaced with the name of your organization.
Use the URL of the virtual repository in the build
configuration and build a
first test project. In a working setup the chainguard remote repository contains
all libraries retrieved from Chainguard.
For initial testing and adoption it is advised to create a separate proxy
repository for the npm registry, a separate proxy repository Chainguard
Libraries for JavaScript repository, and a separate repository group:
Log in as a user with administrator privileges.
Access the Server administration and configuration section with the gear
icon in the top navigation bar.
Configure a remote repository for the npm Registry:
Select Repository - Repositories in the left hand navigation.
Press Create repository.
Select the npm (proxy) recipe.
Provide a new name javascript-public.
In the Proxy - Remote storage input add the URL
https://registry.npmjs.org/.
Press Create repository.
Configure a remote repository for the Chainguard Libraries for JavaScript
repository:
Select Repository - Repositories in the left hand navigation.
Press Create repository.
Select the npm (proxy) recipe.
Provide a new name javascript-chainguard.
In the Proxy - Remote storage input add the URL
https://libraries.cgr.dev/javascript/.
Combine a new repository group and add the two repositories:
Select Repository - Repositories in the left hand navigation.
Press Create repository.
Select the npm (group) recipe.
Provide a new name javascript-all.
In the section Group - Member repositories, move the new repositories
javascript-public and javascript-chainguard to the right and move the
javascript-chainguard repository to the top of the list with the arrow
control.
Build tool access
The following steps allow you to determine the URL and authentication details
for accessing the repository:
Click Browse in the Welcome view or the browse icon (cube) in the top
navigation bar.
Locate the URL column for the javascript-all repository group and press
copy. For example, https://repo.example.com/repository/javascript-all/
with repo.example.com replaced with the hostname of you repository manager.
Copy the URL in the dialog.
Use your configured username and password unless Security - Anonymous
Access - Access - Allow anonymous users to access the server is
activated. Details vary based on your configured authentication system.
Use the URL of the repository group, such as
https://repo.example.com/repository/javascript-all/ in the build
configuration and build a
first test project. In a working setup the javascript-chainguard proxy
repository contains all libraries retrieved from Chainguard.