Cargo Artifact Registry
About 531 wordsAbout 2 min
Configure Credentials
Update the .cargo/config.toml file under the current project, add the following lines
[registry]
default = "cnb"
global-credential-providers = ["cargo:token"]
[registries.cnb]
index = "sparse+<CNB_CARGO_URL>"Use the following command to configure credentials
echo ${CNB_TOKEN} | cargo login --registry cnbFor how to get <CNB_CARGO_URL>, please refer to Obtaining the Artifact Registry Address
For how to get <CNB_TOKEN>, please refer to Creating an Access Token
Push Artifacts
Follow the above Configure Credentials
Execute the following command to publish to CNB
cargo publish- Paste the following content into
.cnb.yaml, commit to the repository
$:
tag_push:
- docker:
image: docker.cnb.cool/examples/language/rust-1.87
stages:
- name: Configure authentication credentials
script: echo ${CNB_TOKEN} | cargo login
- name: Publish to CNB
script: cargo publish --allow-dirty- Update the
.cargo/config.tomlfile in the repository, add the following lines. For<CNB_CARGO_URL>, please refer to Obtaining the Artifact Registry Address
[registry]
default = "cnb"
global-credential-providers = ["cargo:token"]
[registries.cnb]
index = "sparse+<CNB_CARGO_URL>"- Update the version field in the
Cargo.tomlfile in the repository
[package]
name = "<PACKAGE_NAME>"
version = "<VERSION>"- Commit a Tag, which will trigger Cloud Native Build
- Paste the following content into
.cnb.yaml, after committing to the repository, click the 「Workspace」 button in the upper right corner of the repository page to enter the development environment
$:
vscode:
- docker:
image: docker.cnb.cool/examples/language/rust-1.87
services:
- vscode
- dockerFollow the above Configure Credentials
Update the version field in the
Cargo.tomlfile in the repository
[package]
name = "<PACKAGE_NAME>"
version = "<VERSION>"- Publish to CNB
cargo publishUse Artifacts
Pull Artifacts
After following the above Configure Credentials, use the following command to pull artifacts
# Using rand as an example
cargo add randYank/Unyank Artifacts
# Yank artifact
cargo yank my-crate@0.1.0
# Unyank artifact
cargo yank my-crate@0.1.0 --undoDelete Artifacts
cargo does not provide a delete command, please refer to Deleting Artifacts
FQA
Q1: How to configure global credentials
Global configuration paths are as follows:
windows: %USERPROFILE%\.cargo\config.toml
Unix: $HOME/.cargo/config.toml
For more usage, please check official documentation
Q2: cargo version requirements
It is recommended to use cargo version 1.68 and above
Because the current Cargo Artifact Registry only supports the sparse index protocol
1.60 - 1.67 versions: Need to add -Z sparse-registry parameter for each command to use the sparse index protocol
Versions below 1.60: Do not support the sparse index protocol
Q3: When uploading an open-source package to CNB, it prompts that the artifact version already exists
This is because CNB proxies the official source by default. When the package does not exist on the server side, it will automatically provide the package to the cargo client from the proxy.
As a result, the cargo client mistakenly assumes that the package already exists in CNB.
To resolve this issue, you can first upload a placeholder with a non-existent version, and then upload the correct version again.