From 5b3873b608b2c2292c865501e20b9bb6dd1bb16a Mon Sep 17 00:00:00 2001 From: kidneyweakx <35759909+kidneyweakx@users.noreply.github.com> Date: Tue, 17 Dec 2024 07:00:02 +0800 Subject: [PATCH] fix: Add optional S3 endpoint to upload arguments (#110) ### Description Add an optional `endpoint` field in the `S3UploadArgs` struct. Users can now specify a custom AWS S3-compatible endpoint, enhancing the deployment function's flexibility for working with different S3-compatible services. The changes include: 1. Modifying the `S3UploadArgs` struct to include an `endpoint` field. 2. Updating the deployment logic to use the provided `endpoint` if specified. 3. Defaulting to the standard S3 URL format when the `endpoint` field is not provided. 4. Updating the `AmazonS3Builder` configuration to incorporate the custom endpoint. ### Related Issues - Resolves #108 ### References - https://docs.rs/object_store/latest/object_store/aws/struct.AmazonS3Builder.html#method.with_endpoint --- cli/src/command.rs | 8 ++++++++ cli/src/deploy.rs | 12 +++++++++--- 2 files changed, 17 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..7d0981b 100644 --- a/cli/src/deploy.rs +++ b/cli/src/deploy.rs @@ -53,14 +53,22 @@ 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 = endpoint.unwrap_or( + 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_endpoint(&url) .build() .map_err(|err| { BonsolCliError::S3ClientError(S3ClientError::FailedToBuildClient { @@ -78,9 +86,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 +99,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) => {