Enable running remote cargo registry server (#33629)
* Enable running remote cargo registry server * use server URL to configure index
This commit is contained in:
parent
7c80fa1f67
commit
c929775106
|
@ -1,5 +1,5 @@
|
||||||
use {
|
use {
|
||||||
clap::{crate_description, crate_name, value_t_or_exit, App, Arg, ArgMatches},
|
clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg, ArgMatches},
|
||||||
solana_clap_utils::{
|
solana_clap_utils::{
|
||||||
hidden_unless_forced,
|
hidden_unless_forced,
|
||||||
input_validators::is_url_or_moniker,
|
input_validators::is_url_or_moniker,
|
||||||
|
@ -37,6 +37,7 @@ impl<'a> ClientConfig<'a> {
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
pub rpc_client: Arc<RpcClient>,
|
pub rpc_client: Arc<RpcClient>,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
pub server_url: String,
|
||||||
websocket_url: String,
|
websocket_url: String,
|
||||||
commitment: commitment_config::CommitmentConfig,
|
commitment: commitment_config::CommitmentConfig,
|
||||||
cli_signers: Vec<Keypair>,
|
cli_signers: Vec<Keypair>,
|
||||||
|
@ -112,6 +113,18 @@ impl Client {
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help("Cargo registry's local TCP port. The server will bind to this port and wait for requests."),
|
.help("Cargo registry's local TCP port. The server will bind to this port and wait for requests."),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("server_url")
|
||||||
|
.short("s")
|
||||||
|
.long("server-url")
|
||||||
|
.value_name("URL_OR_MONIKER")
|
||||||
|
.takes_value(true)
|
||||||
|
.global(true)
|
||||||
|
.validator(is_url_or_moniker)
|
||||||
|
.help(
|
||||||
|
"URL where the registry service will be hosted. Default: http://0.0.0.0:<port>",
|
||||||
|
),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("commitment")
|
Arg::with_name("commitment")
|
||||||
.long("commitment")
|
.long("commitment")
|
||||||
|
@ -192,6 +205,9 @@ impl Client {
|
||||||
|
|
||||||
let port = value_t_or_exit!(matches, "port", u16);
|
let port = value_t_or_exit!(matches, "port", u16);
|
||||||
|
|
||||||
|
let server_url =
|
||||||
|
value_t!(matches, "server_url", String).unwrap_or(format!("http://0.0.0.0:{}", port));
|
||||||
|
|
||||||
Ok(Client {
|
Ok(Client {
|
||||||
rpc_client: Arc::new(RpcClient::new_with_timeouts_and_commitment(
|
rpc_client: Arc::new(RpcClient::new_with_timeouts_and_commitment(
|
||||||
json_rpc_url.to_string(),
|
json_rpc_url.to_string(),
|
||||||
|
@ -200,6 +216,7 @@ impl Client {
|
||||||
confirm_transaction_initial_timeout,
|
confirm_transaction_initial_timeout,
|
||||||
)),
|
)),
|
||||||
port,
|
port,
|
||||||
|
server_url,
|
||||||
websocket_url,
|
websocket_url,
|
||||||
commitment,
|
commitment,
|
||||||
cli_signers: vec![payer_keypair, authority_keypair],
|
cli_signers: vec![payer_keypair, authority_keypair],
|
||||||
|
|
|
@ -4,7 +4,6 @@ use {
|
||||||
std::{
|
std::{
|
||||||
fs::{self, create_dir_all},
|
fs::{self, create_dir_all},
|
||||||
io::ErrorKind,
|
io::ErrorKind,
|
||||||
net::SocketAddr,
|
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::Command,
|
process::Command,
|
||||||
},
|
},
|
||||||
|
@ -19,15 +18,15 @@ struct RegistryConfig {
|
||||||
pub struct DummyGitIndex {}
|
pub struct DummyGitIndex {}
|
||||||
|
|
||||||
impl DummyGitIndex {
|
impl DummyGitIndex {
|
||||||
pub fn create_or_update_git_repo(root_dir: PathBuf, server_addr: &SocketAddr) {
|
pub fn create_or_update_git_repo(root_dir: PathBuf, server_url: &str) {
|
||||||
create_dir_all(&root_dir).expect("Failed to create root directory");
|
create_dir_all(&root_dir).expect("Failed to create root directory");
|
||||||
|
|
||||||
let expected_config = serde_json::to_string(&RegistryConfig {
|
let expected_config = serde_json::to_string(&RegistryConfig {
|
||||||
dl: format!(
|
dl: format!(
|
||||||
"http://{}/api/v1/crates/{{crate}}/{{version}}/download",
|
"{}/api/v1/crates/{{crate}}/{{version}}/download",
|
||||||
server_addr
|
server_url
|
||||||
),
|
),
|
||||||
api: Some(format!("http://{}", server_addr)),
|
api: Some(server_url.to_string()),
|
||||||
})
|
})
|
||||||
.expect("Failed to create expected config");
|
.expect("Failed to create expected config");
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,9 @@ impl CargoRegistryService {
|
||||||
async fn main() {
|
async fn main() {
|
||||||
solana_logger::setup_with_default("solana=info");
|
solana_logger::setup_with_default("solana=info");
|
||||||
let client = Arc::new(Client::new().expect("Failed to get RPC Client instance"));
|
let client = Arc::new(Client::new().expect("Failed to get RPC Client instance"));
|
||||||
let port = client.port;
|
|
||||||
|
let bind_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), client.port);
|
||||||
|
DummyGitIndex::create_or_update_git_repo(PathBuf::from("/tmp/dummy-git"), &client.server_url);
|
||||||
|
|
||||||
let registry_service = make_service_fn(move |_| {
|
let registry_service = make_service_fn(move |_| {
|
||||||
let client_inner = client.clone();
|
let client_inner = client.clone();
|
||||||
|
@ -317,11 +319,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port);
|
let server = Server::bind(&bind_addr).serve(registry_service);
|
||||||
DummyGitIndex::create_or_update_git_repo(PathBuf::from("/tmp/dummy-git"), &addr);
|
info!("Server running on on http://{}", bind_addr);
|
||||||
|
|
||||||
let server = Server::bind(&addr).serve(registry_service);
|
|
||||||
info!("Server running on on http://{}", addr);
|
|
||||||
|
|
||||||
let _ = server.await;
|
let _ = server.await;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue