Skip to content

Commit eda10d2

Browse files
authored
Library update-hashes command (#3267)
[ ] Check if this is a typo or other quick fix and ignore the rest :) ## Type of change Update to existing pages ### What should this PR do? - Add how to use the new `chainctl libraries update-hashes` command in: Quick start, JavaScript Build configuration, Python Build configuration, Python Overview ### Why are we making this change? This information will make it easier to migrate existing projects to Chainguard ### What are the acceptance criteria? - Content should appear in the expected locations - Content should be clear and accurate ### How should this PR be tested? Review the deploy preview --------- Signed-off-by: s-stumbo <sally.stumbo@chainguard.dev>
1 parent 1be5c53 commit eda10d2

5 files changed

Lines changed: 151 additions & 8 deletions

File tree

content/chainguard/libraries/javascript/build-configuration.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ recommended. See the [global
7070
configuration](/chainguard/libraries/javascript/global-configuration/) for setup
7171
guides.
7272

73+
## Updating lockfile hashes for existing projects
74+
75+
> **Note**: `chainctl libraries update-hashes` does not currently support authentication through a repository manager. You will need to configure [direct access](#direct-access) credentials before running the command.
76+
77+
If you are migrating an existing JavaScript project to Chainguard Libraries,
78+
your lockfile likely contains integrity hashes generated against the npm
79+
registry. Because Chainguard rebuilds packages in a secured build environment rather than distributing upstream artifacts directly, the resulting checksums differ even for identical package versions; they must be updated before reinstalling.
80+
81+
Use the following command, in the directory containing the lockfile, to update hashes in place across all supported lockfile formats (`package-lock.json`, `yarn.lock`,
82+
`pnpm-lock.yaml`, `bun.lock`) without regenerating the lockfile from scratch:
83+
84+
```bash
85+
chainctl libraries update-hashes
86+
```
87+
88+
After running the command, ensure your `.npmrc` is configured with Chainguard
89+
credentials, then reinstall to apply the updated hashes. The `chainctl libraries update-hashes` command will output
90+
a "Next steps" section that includes the tool-specific command for reinstalling.
91+
92+
> **Note:** If your organization uses the [Chainguard Repository with upstream
93+
> npm fallback
94+
> enabled](/chainguard/libraries/javascript/overview/#upstream-fallback-policy-and-controls),
95+
> packages that resolve through the upstream registry may still point to
96+
> `registry.npmjs.org` in your lockfile after running `chainctl libraries
97+
> update-hashes`. These packages are not automatically redirected to route
98+
> through Chainguard. To fully migrate these packages, update their resolved
99+
> URLs to use `libraries.cgr.dev/javascript-upstream/` manually.
100+
73101
<a id="npm"></a>
74102

75103
## npm
@@ -144,8 +172,13 @@ Example URLs:
144172
* Sonatype Nexus: https://repo.example.com:8443/repository/javascript-all/
145173
* Direct access: https://libraries.cgr.dev/javascript/
146174

147-
To change the packages, remove the `node_modules` directory and the
148-
`package-lock.json` file and run the `npm install` command again.
175+
To apply the registry changes, remove the `node_modules` directory and the
176+
`package-lock.json` file and run the `npm install` command again. This re-fetches all
177+
packages from Chainguard and regenerates the lockfile with updated hashes.
178+
179+
If you are migrating an existing project and want to preserve your current
180+
lockfile, use [`chainctl libraries update-hashes`](#updating-lockfile-hashes-for-existing-projects)
181+
to update only the integrity hashes in place instead.
149182

150183
Now you can proceed with your development and testing.
151184

@@ -323,8 +356,13 @@ Example URLs:
323356
* Sonatype Nexus: https://repo.example.com:8443/repository/javascript-all/
324357
* Direct access: https://libraries.cgr.dev/javascript/
325358

326-
To change the packages, remove the `node_modules` directory and the
327-
`pnpm-lock.yaml` file and run the `pnpm install` command again.
359+
To apply the registry change, remove the `node_modules` directory and the
360+
`pnpm-lock.yaml` file and run the `pnpm install` command again. This re-fetches all
361+
packages from Chainguard and regenerates the lockfile with updated hashes.
362+
363+
If you are migrating an existing project and want to preserve your current
364+
lockfile, use [`chainctl libraries update-hashes`](#updating-lockfile-hashes-for-existing-projects)
365+
to update only the integrity hashes in place instead.
328366

329367
Now you can proceed with your development and testing.
330368

@@ -444,9 +482,14 @@ Example URLs:
444482
* Sonatype Nexus: https://repo.example.com:8443/repository/javascript-all
445483
* Direct access: https://libraries.cgr.dev/javascript
446484

447-
To change the packages, run the `yarn` command again. This forces an update of
485+
To apply the registry change, run the `yarn` command again. This forces an update of
448486
all packages from the new registry and regeneration of the lock file.
449487

488+
If you are migrating an existing project and want to preserve your current
489+
lockfile, use [`chainctl libraries update-hashes`](#updating-lockfile-hashes-for-existing-projects)
490+
to update only the integrity hashes in place instead.
491+
492+
450493
Now you can proceed with your development and testing.
451494

452495
<a id="yarn-berry-minimal"></a>
@@ -572,12 +615,16 @@ Refer to the [`.yarnrc`
572615
documentation](https://classic.yarnpkg.com/lang/en/docs/yarnrc/) for more
573616
details.
574617

575-
To change the packages, remove the `node_modules` directory and the `yarn.lock`
618+
To apply the registry change, remove the `node_modules` directory and the `yarn.lock`
576619
file and run the `yarn` command again. This forces a new download of all
577620
packages from the new registry and regeneration of the lock file. Alternatively,
578621
you can run `yarn upgrade` to update all dependencies to their latest allowed
579622
versions and regenerate the lock file.
580623

624+
If you are migrating an existing project and want to preserve your current
625+
lockfile, use [`chainctl libraries update-hashes`](#updating-lockfile-hashes-for-existing-projects)
626+
to update only the integrity hashes in place instead.
627+
581628
Now you can proceed with your development and testing.
582629

583630
<a id="yarn-classic-minimal"></a>

content/chainguard/libraries/javascript/overview.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,61 @@ You can continue to use additional registries alongside Chainguard for needs out
9393

9494
Configure this endpoint [globally through a repository manager](/chainguard/libraries/javascript/global-configuration/) for centralized access control across your organization, or use it for [direct access](/chainguard/libraries/javascript/build-configuration/) from individual build tools. If you prefer to manage your own npm fallback rather than using the built-in upstream fallback, see the [global configuration documentation](/chainguard/libraries/javascript/global-configuration/) for setup guides per repository manager.
9595

96+
## Updating lockfile hashes
97+
98+
When migrating an existing JavaScript project to Chainguard Libraries, your
99+
lockfile contains integrity hashes generated against npm registry artifacts.
100+
Because Chainguard rebuilds packages in a secured build environment rather than
101+
distributing upstream artifacts directly, the resulting checksums differ even
102+
for identical package versions. These hashes must be updated before your package
103+
manager will accept packages from Chainguard.
104+
105+
> **Note:** `chainctl libraries update-hashes` does not currently support
106+
> authentication through a repository manager. You will need to
107+
> [configure direct access](/chainguard/libraries/javascript/build-configuration/#direct-access)
108+
> credentials before running the command, or update the lockfiles manually.
109+
110+
The `chainctl libraries update-hashes` command automates lockfile hash updates
111+
for all supported JavaScript lockfile formats. Rather than deleting your
112+
lockfile and reinstalling from scratch, you can run the command directly against
113+
your existing lockfile to update integrity hashes and resolved URLs to use
114+
Chainguard, while preserving the file's format and structure.
115+
116+
Supported formats include `package-lock.json` (npm v2/v3), `yarn.lock` (Yarn
117+
Classic and Berry), `pnpm-lock.yaml`, and `bun.lock`.
118+
119+
Run the command in the directory containing the lockfile:
120+
121+
```bash
122+
chainctl libraries update-hashes
123+
```
124+
125+
Or specify a lockfile path directly:
126+
127+
```bash
128+
chainctl libraries update-hashes path/to/lockfile
129+
```
130+
131+
By default, Chainguard hashes are appended alongside existing upstream hashes
132+
and resolved URLs are updated to point to Chainguard. After updating the
133+
lockfile, ensure your `.npmrc` or equivalent is configured with Chainguard
134+
credentials, then reinstall to apply the changes. The `chainctl libraries update-hashes` command will output
135+
a "Next steps" section that includes the tool-specific command for reinstalling.
136+
137+
> **Note:** Packages that resolve through the Chainguard Repository's upstream
138+
> npm fallback may still point to `registry.npmjs.org` in your lockfile after
139+
> running the command. See [Upstream packages](#upstream-packages) for
140+
> details.
141+
142+
#### Upstream packages
143+
144+
If your organization uses the Chainguard Repository with upstream npm fallback
145+
enabled, packages that resolve through the upstream registry may still point to
146+
`registry.npmjs.org` in your lockfile after running `chainctl libraries
147+
update-hashes`. These packages are not automatically redirected to route through
148+
Chainguard. Once Chainguard has rebuilt the package from source, a subsequent
149+
run of `update-hashes` will update it automatically.
150+
96151
## Provenance and attestations
97152
Chainguard Libraries for JavaScript include SLSA provenance with signed attestations.
98153
These attestations cryptographically link each package to the Chainguard

content/chainguard/libraries/python/build-configuration.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ Chainguard Libraries for Python. For testing purposes, you can use direct access
491491
and environment variables as detailed in the [access
492492
documentation](/chainguard/libraries/access/#use-environment-variables-for-pull-token-credentials).
493493

494+
> **Migrating an existing project?** If you have an existing uv lockfile with
495+
> upstream hashes, use [`chainctl libraries update-hashes`](/chainguard/libraries/python/overview/#updating-lockfile-hashes)
496+
> to update hashes in place rather than starting from scratch.
497+
494498
**1. Configure credentials**
495499

496500
Once the environment variables are set, configure credentials in `~/.netrc`:
@@ -613,6 +617,9 @@ Use the following steps to create a minimal example project for pip with Chaingu
613617
For testing purposes, you can use direct access and environment variables as detailed in the [access
614618
documentation](/chainguard/libraries/access/#use-environment-variables-for-pull-token-credentials).
615619

620+
> **Migrating an existing project?** If you have an existing pip lockfile with
621+
> upstream hashes, use [`chainctl libraries update-hashes`](/chainguard/libraries/python/overview/#updating-lockfile-hashes)
622+
> to update hashes in place rather than starting from scratch.
616623
617624
**1. Update your configuration to point to Chainguard**
618625

content/chainguard/libraries/python/overview.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ Because Chainguard rebuilds Python packages from source rather than mirroring up
321321
- Tools such as `pip`, `Poetry`, and `uv` generate lock files that include SHA-256 hashes
322322
- Repository managers such as JFrog Artifactory or Sonatype Nexus may have cached upstream PyPI wheels and continue serving them instead of Chainguard versions, even after you have reconfigured to use Chainguard Libraries
323323

324-
Resolving these issues requires two steps: [clearing cached artifacts](#clearing-caches-before-migration) at every layer of your build pipeline, and [regenerating lock files or requirements files](#resolving-checksum-mismatches) so they reflect Chainguard's checksums.
324+
Resolving these issues requires two steps: [clearing cached artifacts](#clearing-caches-before-migration) at every layer of your build pipeline, and [updating lock files or requirements files](#updating-lockfile-hashes) so they reflect Chainguard's checksums.
325325

326326
### Clearing caches before migration
327327

@@ -357,7 +357,34 @@ Cached Docker image layers may reuse upstream dependencies even after reconfigur
357357
docker build --no-cache
358358
```
359359

360-
### Resolving checksum mismatches
360+
### Updating lockfile hashes
361+
362+
> Note: `chainctl libraries update-hashes` does not currently support authentication through a repository manager. You will need to [configure direct access](/chainguard/libraries/python/build-configuration/#direct-access) credentials before running the command, or [update the lockfiles manually](#update-lockfiles-manually).
363+
364+
The `chainctl libraries update-hashes` command automates lockfile hash updates for all supported Python lockfile formats. Rather than manually regenerating lock files with each tool, you can run the command directly against your existing lockfile to update hashes to Chainguard checksums while preserving your locked dependency versions, without re-resolving your dependency graph.
365+
366+
Supported formats include `requirements.txt` (pip-tools `--hash` style), `poetry.lock`, `uv.lock`, `pdm.lock`, `Pipfile.lock`, and `pylock.toml`.
367+
368+
Run the command in your project directory to auto-detect the lockfile:
369+
370+
```bash
371+
chainctl libraries update-hashes
372+
```
373+
374+
Or specify a lockfile path directly:
375+
376+
```bash
377+
chainctl libraries update-hashes path/to/requirements.txt
378+
```
379+
380+
By default, Chainguard hashes are appended alongside existing upstream hashes. After updating the lockfiles, to switch your environment to use Chainguard packages, configure your tool to use the Chainguard index and reinstall. The `chainctl libraries update-hashes` command will output
381+
a "Next steps" section that includes the tool-specific command for reinstalling.
382+
383+
#### Update lockfiles manually
384+
385+
If you are using a repository manager, and do not want to use direct access temporarily while updating lockfiles, you can use the following instructions to update your lockfiles:
386+
387+
{{< details "Manually updating lockfiles" >}}
361388

362389
Before regenerating lock files, ensure your tool is configured to use Chainguard as the package index by following the [global configuration](/chainguard/libraries/python/global-configuration/) or [direct access](/chainguard/libraries/python/build-configuration/#direct-access) documentation.
363390

@@ -411,6 +438,8 @@ Repository managers such as JFrog Artifactory or Sonatype Nexus may continue ser
411438

412439
Before regenerating lock files, ensure your tool is configured to use Chainguard as the package index by following the [global configuration](/chainguard/libraries/python/global-configuration/) or [direct access](/chainguard/libraries/python/build-configuration/#direct-access) documentation.
413440

441+
{{< /details >}}
442+
414443
>**Note:** While hash mismatches are expected for some tooling and
415444
configurations while migrating to Chainguard, you can verify the authenticity and provenance of Chainguard
416445
packages using SBOM and SLSA attestation files as described in the next section.

content/chainguard/libraries/quickstart.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ Classic](/chainguard/libraries/javascript/build-configuration/#minimal-example-p
207207
and
208208
[Bun](/chainguard/libraries/javascript/build-configuration/#minimal-example-project-4) to understand how to use these repositories.
209209

210+
> **Migrating an existing Python or JavaScript project?** If you have an
211+
> existing lockfile with upstream hashes, use `chainctl libraries update-hashes`
212+
> to update checksums to Chainguard's automatically, without regenerating your
213+
> lockfile from scratch.
214+
210215
## Step 4: Verify your libraries
211216

212217
After setup, you can verify that your dependencies are sourced from Chainguard using:

0 commit comments

Comments
 (0)