feat: Add Dockerfile for containerization and implement database migrations for both SQLite and Postgres.
This commit is contained in:
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
FROM rust:1.92 AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the release binary
|
||||||
|
RUN cargo build --release -p template-api
|
||||||
|
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install OpenSSL (required for many Rust networking crates) and CA certificates
|
||||||
|
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY --from=builder /app/target/release/template-api .
|
||||||
|
|
||||||
|
|
||||||
|
# Create data directory for SQLite
|
||||||
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
|
ENV DATABASE_URL=sqlite:///app/data/template.db
|
||||||
|
ENV SESSION_SECRET=supersecretchangeinproduction
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["./template-api"]
|
||||||
@@ -2,17 +2,15 @@ pub use k_core::db::{DatabaseConfig, DatabasePool};
|
|||||||
|
|
||||||
pub async fn run_migrations(pool: &DatabasePool) -> Result<(), sqlx::Error> {
|
pub async fn run_migrations(pool: &DatabasePool) -> Result<(), sqlx::Error> {
|
||||||
match pool {
|
match pool {
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
DatabasePool::Sqlite(pool) => {
|
DatabasePool::Sqlite(pool) => {
|
||||||
|
// Point specifically to the sqlite folder
|
||||||
sqlx::migrate!("../migrations_sqlite").run(pool).await?;
|
sqlx::migrate!("../migrations_sqlite").run(pool).await?;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
DatabasePool::Postgres(_) => {
|
DatabasePool::Postgres(pool) => {
|
||||||
// Postgres migrations would go here
|
// Point specifically to the postgres folder
|
||||||
tracing::warn!("Postgres migrations not implemented in template yet");
|
sqlx::migrate!("../migrations_postgres").run(pool).await?;
|
||||||
// Pass through the types from the core library
|
|
||||||
// This allows you to change k-core later without breaking imports in template-infra
|
|
||||||
// The `pub use` statement cannot be placed inside a match arm.
|
|
||||||
// It is already present at the top of the file.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user