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"
|
||||
futures-util = "0.3"
|
||||
rayon = "1.10.0"
|
||||
diesel_migrations = "2.0.0"
|
||||
|
||||
[profile.release]
|
||||
debug = false
|
||||
|
|
|
@ -9,12 +9,17 @@ use std::sync::Arc;
|
|||
|
||||
use axum::{middleware, Extension, Router};
|
||||
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 rustls::crypto::ring;
|
||||
use tokio::sync::broadcast;
|
||||
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
||||
#[tokio::main]
|
||||
#[allow(unused)]
|
||||
async fn main() {
|
||||
|
@ -46,6 +51,15 @@ async fn main() {
|
|||
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 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
|
||||
|
||||
api:
|
||||
build:
|
||||
context: ./api
|
||||
dockerfile: Dockerfile
|
||||
build: ./api
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
version: "3.8"
|
||||
|
||||
services:
|
||||
studio:
|
||||
build:
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
name: supabase
|
||||
|
||||
services:
|
||||
mail:
|
||||
container_name: supabase-mail
|
||||
image: inbucket/inbucket:3.0.3
|
||||
ports:
|
||||
- '2500:2500' # SMTP
|
||||
- '9000:9000' # web interface
|
||||
- '1100:1100' # POP3
|
||||
|
||||
studio:
|
||||
container_name: supabase-studio
|
||||
image: supabase/studio:20241202-71e5240
|
||||
|
|
Loading…
Reference in New Issue