mirror of https://github.com/buster-so/buster.git
Refactor Docker Compose and API for enhanced functionality and migration support
- Simplified the API service build configuration in `docker-compose.yml` by consolidating the build context and Dockerfile path. - Added `diesel_migrations` dependency to `Cargo.toml` for database migration management. - Implemented database migration logic in `main.rs`, including error handling and logging for migration success or failure. - Introduced a new mail service in `supabase/docker-compose.yml` for handling SMTP, POP3, and web interface. - Removed version specification from `supabase/dev/docker-compose.dev.yml` for cleaner configuration. These changes improve the overall structure and functionality of the application, facilitating better database management and service orchestration.
This commit is contained in:
parent
bb8fd621c9
commit
73822945bf
|
@ -88,6 +88,7 @@ tokio-postgres-rustls = "0.13"
|
||||||
tokio-postgres = "0.7"
|
tokio-postgres = "0.7"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
rayon = "1.10.0"
|
rayon = "1.10.0"
|
||||||
|
diesel_migrations = "2.0.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = false
|
debug = false
|
||||||
|
|
|
@ -9,12 +9,17 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{middleware, Extension, Router};
|
use axum::{middleware, Extension, Router};
|
||||||
use buster_middleware::{auth::auth, cors::cors};
|
use buster_middleware::{auth::auth, cors::cors};
|
||||||
|
use database::lib::get_pg_pool;
|
||||||
|
use diesel::{Connection, PgConnection};
|
||||||
|
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use rustls::crypto::ring;
|
use rustls::crypto::ring;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
|
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||||
|
|
||||||
|
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -46,6 +51,15 @@ async fn main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tracing::info!("Running database migrations");
|
||||||
|
|
||||||
|
if let Err(e) = run_migrations().await {
|
||||||
|
tracing::error!("Failed to run database migrations: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::info!("Successfully ran database migrations");
|
||||||
|
|
||||||
let protected_router = Router::new().nest("/api/v1", routes::protected_router());
|
let protected_router = Router::new().nest("/api/v1", routes::protected_router());
|
||||||
let public_router = Router::new().route("/health", axum::routing::get(|| async { "OK" }));
|
let public_router = Router::new().route("/health", axum::routing::get(|| async { "OK" }));
|
||||||
|
|
||||||
|
@ -83,3 +97,17 @@ async fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn run_migrations() -> Result<(), anyhow::Error> {
|
||||||
|
let database_url = std::env::var("DATABASE_URL")
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to get DATABASE_URL: {}", e))?;
|
||||||
|
|
||||||
|
let mut connection = PgConnection::establish(&database_url)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to establish database connection: {}", e))?;
|
||||||
|
|
||||||
|
connection
|
||||||
|
.run_pending_migrations(MIGRATIONS)
|
||||||
|
.map_err(|e| anyhow::anyhow!("Failed to run migrations: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -14,9 +14,7 @@ services:
|
||||||
retries: 30
|
retries: 30
|
||||||
|
|
||||||
api:
|
api:
|
||||||
build:
|
build: ./api
|
||||||
context: ./api
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
ports:
|
ports:
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
version: "3.8"
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
studio:
|
studio:
|
||||||
build:
|
build:
|
||||||
|
|
|
@ -8,6 +8,14 @@
|
||||||
name: supabase
|
name: supabase
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
mail:
|
||||||
|
container_name: supabase-mail
|
||||||
|
image: inbucket/inbucket:3.0.3
|
||||||
|
ports:
|
||||||
|
- '2500:2500' # SMTP
|
||||||
|
- '9000:9000' # web interface
|
||||||
|
- '1100:1100' # POP3
|
||||||
|
|
||||||
studio:
|
studio:
|
||||||
container_name: supabase-studio
|
container_name: supabase-studio
|
||||||
image: supabase/studio:20241202-71e5240
|
image: supabase/studio:20241202-71e5240
|
||||||
|
|
Loading…
Reference in New Issue