diff --git a/.env b/.env new file mode 100644 index 0000000..6f56217 --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +AWS_ENDPOINT_URL=http://127.0.0.1:10000 +AWS_ACCESS_KEY_ID=minioadmin +AWS_SECRET_ACCESS_KEY=minioadminpassword diff --git a/crates/flux-releaser/src/app.rs b/crates/flux-releaser/src/app.rs index 82ca1d1..40a5e01 100644 --- a/crates/flux-releaser/src/app.rs +++ b/crates/flux-releaser/src/app.rs @@ -1,5 +1,10 @@ use std::{ops::Deref, sync::Arc}; +use aws_config::{BehaviorVersion, Region}; +use aws_sdk_s3::config::Credentials; + +use self::infra::aws_s3::s3_client; + #[derive(Clone)] pub struct SharedApp(Arc); @@ -23,9 +28,44 @@ pub struct App { impl App { pub async fn new() -> anyhow::Result { - let shared_config = aws_config::load_from_env().await; - let client = aws_sdk_s3::Client::new(&shared_config); - - Ok(Self { s3_client: client }) + Ok(Self { + s3_client: s3_client().await?, + }) + } +} + +mod infra { + pub mod aws_s3 { + use aws_config::{BehaviorVersion, Region}; + use aws_sdk_s3::config::Credentials; + + pub async fn s3_client() -> anyhow::Result { + let shared_config = aws_config::defaults(BehaviorVersion::latest()) + .region(Region::new("eu-west-1")) + .credentials_provider(Credentials::new( + std::env::var("AWS_ACCESS_KEY_ID")?, + std::env::var("AWS_SECRET_ACCESS_KEY")?, + None, + None, + "flux_releaser", + )); + + let config = aws_sdk_s3::config::Builder::from(&shared_config.load().await) + .endpoint_url(std::env::var("AWS_ENDPOINT_URL")?) + .build(); + + let client = aws_sdk_s3::Client::from_conf(config); + + let buckets = client.list_buckets().send().await?; + + buckets + .buckets + .iter() + .flatten() + .flat_map(|b| &b.name) + .for_each(|n| tracing::debug!("test: found aws bucket: {}", n)); + + Ok(client) + } } } diff --git a/templates/docker-compose.yaml b/templates/docker-compose.yaml new file mode 100644 index 0000000..bd6bb40 --- /dev/null +++ b/templates/docker-compose.yaml @@ -0,0 +1,27 @@ +version: "3" + +services: + minio: + image: quay.io/minio/minio + container_name: minio + hostname: minio + command: server --address 0.0.0.0:10000 --console-address 0.0.0.0:10001 /data + ports: + - '127.0.0.1:10000:10000' + - '127.0.0.1:10001:10001' + environment: + - MINIO_ROOT_USER=minioadmin + - MINIO_ROOT_PASSWORD=minioadminpassword + + createbuckets: + image: minio/mc + depends_on: + - minio + entrypoint: > + /bin/sh -c " + /usr/bin/mc alias set myminio http://minio:10000 minioadmin minioadminpassword; + /usr/bin/mc admin info myminio; + /usr/bin/mc mb myminio/mybucket; + /usr/bin/mc policy set public myminio/mybucket; + exit 0; + "