From f8744f6093669e19670bbdaa05c0dbd363e50c31 Mon Sep 17 00:00:00 2001 From: kidneyweakx Date: Mon, 16 Dec 2024 14:00:23 +0800 Subject: [PATCH 1/3] feat: Add optional S3 endpoint to upload arguments This update introduces an optional `endpoint` field to the `S3UploadArgs` struct, allowing users to specify a custom AWS S3 compatibility endpoint. The deployment function has been modified to utilize this new endpoint if provided, otherwise defaulting to the standard S3 URL format. This enhances flexibility for users working with different S3-compatible services. --- cli/src/command.rs | 8 ++++++++ cli/src/deploy.rs | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index b0efffc..7ff85a2 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -100,6 +100,14 @@ pub struct S3UploadArgs { env = "AWS_REGION" )] pub region: String, + + #[arg( + help = "Specify the AWS S3 compatibility endpoint", + long, + required = false, + env = "AWS_S3_ENDPOINT" + )] + pub endpoint: Option, } #[derive(Debug, Clone, Args)] diff --git a/cli/src/deploy.rs b/cli/src/deploy.rs index e2dc7db..57fa15e 100644 --- a/cli/src/deploy.rs +++ b/cli/src/deploy.rs @@ -53,14 +53,25 @@ pub async fn deploy(rpc_url: String, signer: Keypair, deploy_args: DeployArgs) - access_key, secret_key, region, + endpoint, .. } = s3_upload; + let dest = + object_store::path::Path::from(format!("{}-{}", manifest.name, manifest.image_id)); + + let url = if let Some(endpoint) = endpoint { + format!("{}", endpoint) + } else { + format!("https://{}.s3.{}.amazonaws.com/{}", bucket, region, dest) + }; + let s3_client = AmazonS3Builder::new() .with_bucket_name(&bucket) .with_region(®ion) .with_access_key_id(&access_key) .with_secret_access_key(&secret_key) + .with_url(&url) .build() .map_err(|err| { BonsolCliError::S3ClientError(S3ClientError::FailedToBuildClient { @@ -78,9 +89,6 @@ pub async fn deploy(rpc_url: String, signer: Keypair, deploy_args: DeployArgs) - }) })?; - let dest = - object_store::path::Path::from(format!("{}-{}", manifest.name, manifest.image_id)); - let url = format!("https://{}.s3.{}.amazonaws.com/{}", bucket, region, dest); // get the file to see if it exists if s3_client.head(&dest).await.is_ok() { bar.set_message("File already exists, skipping upload"); @@ -94,6 +102,7 @@ pub async fn deploy(rpc_url: String, signer: Keypair, deploy_args: DeployArgs) - } bar.finish_and_clear(); + println!("Uploaded to S3 url {}", url); url } DeployDestination::ShadowDrive(shadow_drive_upload) => { From cdb903a653e1d4b9511e07beca3f3319b93a5f4b Mon Sep 17 00:00:00 2001 From: kidneyweakx Date: Mon, 16 Dec 2024 14:58:14 +0800 Subject: [PATCH 2/3] fix: update S3 client configuration to use `with_endpoint` instead of `with_url` --- cli/src/deploy.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/deploy.rs b/cli/src/deploy.rs index 57fa15e..a3bc92b 100644 --- a/cli/src/deploy.rs +++ b/cli/src/deploy.rs @@ -71,7 +71,7 @@ pub async fn deploy(rpc_url: String, signer: Keypair, deploy_args: DeployArgs) - .with_region(®ion) .with_access_key_id(&access_key) .with_secret_access_key(&secret_key) - .with_url(&url) + .with_endpoint(&url) .build() .map_err(|err| { BonsolCliError::S3ClientError(S3ClientError::FailedToBuildClient { From a75fd075cbdd78f72d45eb7e5db23284aff210a7 Mon Sep 17 00:00:00 2001 From: kidneyweakx Date: Mon, 16 Dec 2024 19:04:19 +0800 Subject: [PATCH 3/3] refactor: streamline S3 URL construction in deploy function --- cli/src/deploy.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cli/src/deploy.rs b/cli/src/deploy.rs index a3bc92b..7d0981b 100644 --- a/cli/src/deploy.rs +++ b/cli/src/deploy.rs @@ -60,11 +60,8 @@ pub async fn deploy(rpc_url: String, signer: Keypair, deploy_args: DeployArgs) - let dest = object_store::path::Path::from(format!("{}-{}", manifest.name, manifest.image_id)); - let url = if let Some(endpoint) = endpoint { - format!("{}", endpoint) - } else { - format!("https://{}.s3.{}.amazonaws.com/{}", bucket, region, dest) - }; + let url = endpoint.unwrap_or( + format!("https://{}.s3.{}.amazonaws.com/{}", bucket, region, dest)); let s3_client = AmazonS3Builder::new() .with_bucket_name(&bucket)