crates-registry

Crates.iocrates-registry
lib.rscrates-registry
version0.1.3
sourcesrc
created_at2023-09-11 09:04:36.880469
updated_at2023-09-23 17:38:48.906024
descriptionCrates Registry is a tool for serve crates and rustup installation in offline networks. The project is based on panamax project and cargo-http-registry and use theis code.
homepagehttps://github.com/TalRoni/crates-registry
repositoryhttps://github.com/TalRoni/crates-registry.git
max_upload_size
id969401
size5,516,458
TalYRoni (TalRoni)

documentation

README

Crates Registry


Static Badge Static Badge

Description

Crates Registry is a tool for serving and publishing crates and serving rustup installation in offline networks. (like Verdaccio as npm registry) The project partially uses code from these open source projects: panamax project and cargo-http-registry and they deserve credit accordingly.

Installation

Crates Registry can be installed with cargo:

$ cargo install crates-registry

Also available in docker (recommended for serving use):

$ docker run -d --name crates-registry -e RUST_LOG=info -v /path/to/mirror-folder:/registry -p 80:80 crates-registry:latest serve -s <server ip> --root-registry /registry 

(Modify /path/to/registry port and server-IP as needed)

Usage

There are several possible uses:

  • Packing - Pack rust installation in the online network.
  • Unpacking - Unpacking new rust installation into the registry folder (also possible through the UI).
  • Serving - Serve the registry in your offline network.

Packing

Packing rust installations on the online side to serve later in the offline network. We download the rust installations in self-contained directories and pack the directory in tar file. packing example:

$ crates-registry pack --pack-file packed_file.tar --rust-versions 1.67.1,04-03-2023-nightly --platfroms x86_64-unknown-linux-gnu

Run crates-registry pack --help for all available options.

Unpacking

Unpack the packed file that contains the rustup installations in the registry folder. You can load the tar file through the UI at http://server-adress/manage-installations. Follow the instructions in the page. Another option is to load the tar file using the unpack command:

$ crates-registry pack --packed-file /packed_file.tar --root-registry /path/to/registry/folder

Serving

The Crates Registry provides an HTTP server that can handle serving the crates and rustup installations fast and at scale. serving example:

$ docker run -d --name crates-registry -e RUST_LOG=info -v /path/to/mirror-folder:/registry -p 80:80 crates-registry:latest serve -s <server ip> --root-registry /registry 

(Modify /path/to/registry port and server-IP as needed) Run crates-registry serve --help for all available options.

Configuring your environment

Once you have a server set up and running, it's time to tell your rust components to use it.

Setting environment variables

To ensure rustup knows where to look for the Rust components, we need to set some environment variables. Assuming the server is hosted at http://crates.registry/:

export RUSTUP_DIST_SERVER=http://crates.registry
export RUSTUP_UPDATE_ROOT=http://crates.registry/rustup

These need to be set whenever rustup is used, so these should be added to your .bashrc file (or equivalent).

Rustup

To install rustup you can download the rustup-init file. The rustup-init file you want depends on your architecture. Assuming you're running desktop Linux on a 64-bit machine:

wget http://crates.registry/rustup/dist/x86_64-unknown-linux-gnu/rustup-init
chmod +x rustup-init
./rustup-init

This will let you install rustup the similarly following the steps from https://rustup.rs. This will also let you use rustup to keep your Rust installation updated in the future.

Cargo

Cargo also needs to be configured to point to the mirror. This can be done by adding the following lines to ~/.cargo/config (creating the file if it doesn't exist):

[source.my-mirror]
registry = "http://crates.registry/git/index"
[source.crates-io]
replace-with = "my-mirror"

# For publish crates.
[registries]
my-registry = { index = "https://crates.registry/git/index" }

Cargo should now be pointing to the correct location to use the mirror.

Import crates to the registry.

Tow utilities to import new crates:

You can also publish crates using the cargo publish command.

License

Licensed under the terms of the GNU GENERAL PUBLIC LICENSE Version 3 and the Apache License (Version 2.0)

Commit count: 17

cargo fmt