Skip to content

Commit

Permalink
feat: add support for selfhosted s3 storage (closes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomio committed May 4, 2022
1 parent 6d03259 commit da2c085
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/3ZVgSw?referralCode=tomio)

#### Changing Providers

To change the provider in railway:

1. Open the repo that railway made for you.
2. Open the [Dockerfile](./Dockerfile)
3. Edit lines 39 and 44 with `fleet build --release --no-default-features --features <your_provider>`.
4. Deploy your app again.

### Pre-built Binaries

**⚠️- You can't change the provider when using the pre-built binaries.**
Expand Down Expand Up @@ -108,12 +117,16 @@ cargo build --release --no-default-features --features cloudinary_provider
#### Environment Variables

- `S3_BUCKET_NAME` - the name of your s3 bucket (required)
- `S3_REGION` - the region of your s3 bucket (required)
- `S3_REGION` - the region of your s3 bucket (required, only optional if using [self-hosted s3](#self-hosted-s3-storage))
- `S3_ACCESS_KEY` - your access key (required)
- `S3_SECRET_KEY` - your secret key (required)
- `S3_SECURITY_TOKEN` - your security token (optional)
- `S3_SESSION_TOKEN` - your session token (optional)

#### Self-hosted S3 Storage

To use a self-hosted S3 Storage, set the `S3_ENDPOINT_URL` environment variable to the endpoint url.

#### Build Command

```sh
Expand Down
19 changes: 14 additions & 5 deletions src/providers/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result;
use async_trait::async_trait;
use redis::{AsyncCommands, Client};
use s3::creds::Credentials;
use s3::Bucket;
use s3::{Bucket, Region};

use super::Provider;

Expand Down Expand Up @@ -33,13 +33,22 @@ impl Provider for S3Provider {
},
};

let region: Region = match env::var("S3_REGION") {
Ok(region) => region.parse().expect("Failed to parse s3 region"),
Err(_) => {
let endpoint = env::var("S3_ENDPOINT_URL").expect("Failed to load s3 endpoint url");

Region::Custom {
region: "".to_owned(),
endpoint,
}
},
};

let bucket = Arc::new(
Bucket::new(
&env::var("S3_BUCKET_NAME").expect("Failed to load s3 bucket name"),
env::var("S3_REGION")
.expect("Failed to load s3 region")
.parse()
.expect("Failed to parse s3 region"),
region,
creds,
)
.expect("Failed to initialize s3 bucket"),
Expand Down

0 comments on commit da2c085

Please sign in to comment.