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 {
|
||||
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::{
|
||||
hidden_unless_forced,
|
||||
input_validators::is_url_or_moniker,
|
||||
|
@ -37,6 +37,7 @@ impl<'a> ClientConfig<'a> {
|
|||
pub struct Client {
|
||||
pub rpc_client: Arc<RpcClient>,
|
||||
pub port: u16,
|
||||
pub server_url: String,
|
||||
websocket_url: String,
|
||||
commitment: commitment_config::CommitmentConfig,
|
||||
cli_signers: Vec<Keypair>,
|
||||
|
@ -112,6 +113,18 @@ impl Client {
|
|||
.takes_value(true)
|
||||
.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::with_name("commitment")
|
||||
.long("commitment")
|
||||
|
@ -192,6 +205,9 @@ impl Client {
|
|||
|
||||
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 {
|
||||
rpc_client: Arc::new(RpcClient::new_with_timeouts_and_commitment(
|
||||
json_rpc_url.to_string(),
|
||||
|
@ -200,6 +216,7 @@ impl Client {
|
|||
confirm_transaction_initial_timeout,
|
||||
)),
|
||||
port,
|
||||
server_url,
|
||||
websocket_url,
|
||||
commitment,
|
||||
cli_signers: vec![payer_keypair, authority_keypair],
|
||||
|
|
|
@ -4,7 +4,6 @@ use {
|
|||
std::{
|
||||
fs::{self, create_dir_all},
|
||||
io::ErrorKind,
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
process::Command,
|
||||
},
|
||||
|
@ -19,15 +18,15 @@ struct RegistryConfig {
|
|||
pub struct 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");
|
||||
|
||||
let expected_config = serde_json::to_string(&RegistryConfig {
|
||||
dl: format!(
|
||||
"http://{}/api/v1/crates/{{crate}}/{{version}}/download",
|
||||
server_addr
|
||||
"{}/api/v1/crates/{{crate}}/{{version}}/download",
|
||||
server_url
|
||||
),
|
||||
api: Some(format!("http://{}", server_addr)),
|
||||
api: Some(server_url.to_string()),
|
||||
})
|
||||
.expect("Failed to create expected config");
|
||||
|
||||
|
|
|
@ -306,7 +306,9 @@ impl CargoRegistryService {
|
|||
async fn main() {
|
||||
solana_logger::setup_with_default("solana=info");
|
||||
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 client_inner = client.clone();
|
||||
|
@ -317,11 +319,8 @@ async fn main() {
|
|||
}
|
||||
});
|
||||
|
||||
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port);
|
||||
DummyGitIndex::create_or_update_git_repo(PathBuf::from("/tmp/dummy-git"), &addr);
|
||||
|
||||
let server = Server::bind(&addr).serve(registry_service);
|
||||
info!("Server running on on http://{}", addr);
|
||||
let server = Server::bind(&bind_addr).serve(registry_service);
|
||||
info!("Server running on on http://{}", bind_addr);
|
||||
|
||||
let _ = server.await;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue