Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add optional S3 endpoint to upload arguments #110

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

#[derive(Debug, Clone, Args)]
Expand Down
12 changes: 9 additions & 3 deletions cli/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&region)
.with_access_key_id(&access_key)
.with_secret_access_key(&secret_key)
.with_endpoint(&url)
.build()
.map_err(|err| {
BonsolCliError::S3ClientError(S3ClientError::FailedToBuildClient {
Expand All @@ -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");
Expand All @@ -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) => {
Expand Down
Loading