fix(docker): Dockerfile workspace-aware + db.rs create_if_missing
- Contexte de build depuis la racine du workspace Cargo - Rust 1.86 pour edition 2024 - Layer cache avec stubs membres du workspace - Création répertoire /data dans l'image - SQLite create_if_missing(true) pour créer la DB au premier démarrage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+18
-5
@@ -1,13 +1,26 @@
|
|||||||
FROM rust:1.82-alpine AS builder
|
FROM rust:1.86-alpine AS builder
|
||||||
RUN apk add --no-cache musl-dev
|
RUN apk add --no-cache musl-dev
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY Cargo.toml Cargo.lock* ./
|
# Workspace
|
||||||
COPY src ./src
|
COPY Cargo.toml Cargo.lock ./
|
||||||
RUN cargo build --release
|
COPY backend/Cargo.toml ./backend/Cargo.toml
|
||||||
|
COPY agents/agent-scan-network/Cargo.toml ./agents/agent-scan-network/Cargo.toml
|
||||||
|
COPY agents/agent-metric/Cargo.toml ./agents/agent-metric/Cargo.toml
|
||||||
|
# Stubs pour cacher les dépendances
|
||||||
|
RUN mkdir -p backend/src agents/agent-scan-network/src agents/agent-metric/src \
|
||||||
|
&& echo 'fn main(){}' > backend/src/main.rs \
|
||||||
|
&& echo 'fn main(){}' > agents/agent-scan-network/src/main.rs \
|
||||||
|
&& echo 'fn main(){}' > agents/agent-metric/src/main.rs \
|
||||||
|
&& cargo build --release -p sentinelmesh-backend
|
||||||
|
# Sources réelles (les stubs agents restent en place)
|
||||||
|
COPY backend/src ./backend/src
|
||||||
|
COPY backend/migrations ./backend/migrations
|
||||||
|
RUN touch backend/src/main.rs && cargo build --release -p sentinelmesh-backend
|
||||||
|
|
||||||
FROM alpine:3.21
|
FROM alpine:3.21
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates && mkdir -p /data
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/release/sentinelmesh-backend .
|
COPY --from=builder /app/target/release/sentinelmesh-backend .
|
||||||
|
COPY --from=builder /app/backend/migrations ./migrations
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD ["./sentinelmesh-backend"]
|
CMD ["./sentinelmesh-backend"]
|
||||||
|
|||||||
+6
-2
@@ -1,9 +1,13 @@
|
|||||||
use sqlx::{sqlite::SqlitePoolOptions, SqlitePool};
|
use sqlx::{sqlite::{SqliteConnectOptions, SqlitePoolOptions}, SqlitePool};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub async fn connect(database_url: &str) -> anyhow::Result<SqlitePool> {
|
pub async fn connect(database_url: &str) -> anyhow::Result<SqlitePool> {
|
||||||
|
let opts = SqliteConnectOptions::from_str(database_url)?
|
||||||
|
.create_if_missing(true);
|
||||||
|
|
||||||
let pool = SqlitePoolOptions::new()
|
let pool = SqlitePoolOptions::new()
|
||||||
.max_connections(5)
|
.max_connections(5)
|
||||||
.connect(database_url)
|
.connect_with(opts)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::migrate!("./migrations").run(&pool).await?;
|
sqlx::migrate!("./migrations").run(&pool).await?;
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
services:
|
services:
|
||||||
backend:
|
backend:
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: backend/Dockerfile
|
||||||
image: sentinelmesh-backend:latest
|
image: sentinelmesh-backend:latest
|
||||||
container_name: sentinelmesh-backend
|
container_name: sentinelmesh-backend
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
Reference in New Issue
Block a user