Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Updates and drop main
Browse files Browse the repository at this point in the history
Can now run using `cargo shuttle run` so main.rs isn't necessary!
  • Loading branch information
jming422 committed Jul 26, 2022
1 parent c6f4d40 commit fac8b1a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 65 deletions.
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
[package]
name = "birdie"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "Split group expenses using the minimal number of transactions"
license = "GPL-3.0-or-later"
repository = "https://github.com/jming422/birdie.git"
include = ["/src", "/*", "!.*", "!/js", "!/js.tar.gz", "!/frontend"]

[lib]
crate-type = ["cdylib", "lib"]

[dependencies]
async-compression = { version = "0.3", features = ["tokio", "gzip"] }
aws-config = "0.12"
aws-sdk-s3 = "0.12"
aws-config = "0.46"
aws-sdk-s3 = "0.16"
axum = "0.5"
chrono = { version = "0.4", features = ["serde"] }
harsh = "0.2"
lazy_static = "1"
rust_decimal = { version = "1", features = ["serde-with-float", "serde-with-arbitrary-precision"] }
serde = "1"
serde_json = "1"
shuttle-service = { version = "0.3.3", features = ["secrets", "sqlx-postgres", "web-axum"] }
shuttle-service = { version = "0.4.0", features = ["secrets", "sqlx-postgres", "web-axum"] }
sqlx = { version = "0.5", features = ["runtime-tokio-native-tls", "postgres", "decimal", "chrono"] }
sync_wrapper = "0.1"
tokio = { version = "1", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ js/package-lock.json: js/package.json
cd js && npm install

deploy: deploy-s3
cargo shuttle deploy --allow-dirty
cargo shuttle deploy

deploy-s3: js.tar.gz
aws s3 cp js.tar.gz s3://jming422-deploy/birdie-js.tar.gz
Expand Down
29 changes: 18 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,29 +316,36 @@ pub async fn app(pool: PgPool, js_build_dir: &str) -> Result<Router, shuttle_ser
Ok(router)
}

pub async fn unpack_frontend(pool: &PgPool) -> Result<(), shuttle_service::Error> {
pub async fn unpack_frontend(pool: &PgPool, build_dir: &str) -> Result<(), shuttle_service::Error> {
info!("Downloading frontend bundle from S3");
let bucket = pool.get_secret("DEPLOY_BUCKET").await?;
let s3_result = s3::download_object(pool, bucket, "birdie-js.tar.gz").await?;

info!("Unpacking frontend bundle");
let gz = StreamReader::new(
s3_result
.body
// StreamReader requires that the Item's Result Error type is an
// io::Error, not just any error (like an AWS SdkError), so we have
// to wrap any SdkErrors in io::Errors.
.map(|item| item.map_err(|e| io::Error::new(io::ErrorKind::Other, e))),
// StreamReader requires that the Item's Result Error type is an
// io::Error, not just any error (like an AWS SdkError), so we have
// to wrap any SdkErrors in io::Errors.
StreamExt::map(s3_result.body, |item| {
item.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
}),
);
let tar = GzipDecoder::new(gz);
let mut archive = Archive::new(tar);
archive.unpack("./frontend").await?;
archive.unpack(build_dir).await?;
Ok(())
}

#[shuttle_service::main]
async fn axum(pool: PgPool) -> ShuttleAxum {
unpack_frontend(&pool).await?;
async fn axum(#[shared::Postgres] pool: PgPool) -> ShuttleAxum {
let frontend_dir = if std::env::var("BIRDIE_LOCAL").is_err() {
let dir = "./frontend";
unpack_frontend(&pool, dir).await?;
dir
} else {
"./js/build"
};

migrate(&pool).await.map_err(CustomError::new)?;
Ok(SyncWrapper::new(app(pool, "./frontend").await?))
Ok(SyncWrapper::new(app(pool, frontend_dir).await?))
}
48 changes: 0 additions & 48 deletions src/main.rs

This file was deleted.

0 comments on commit fac8b1a

Please sign in to comment.