From aeda9120b380272780af3477f8a4c72a596fc8c1 Mon Sep 17 00:00:00 2001 From: senke Date: Wed, 18 Feb 2026 12:38:16 +0100 Subject: [PATCH] fix(chat-server): ensure sqlx-data.json available for Docker build - Remove sqlx-data.json from .dockerignore to allow SQLX_OFFLINE build - Use repo root as build context for veza-common path dependency - Add SQLX_OFFLINE=true and COPY sqlx-data.json in Dockerfile --- docker-compose.yml | 6 ++++-- veza-chat-server/.dockerignore | 6 +++--- veza-chat-server/Dockerfile | 26 ++++++++++++++++---------- veza-stream-server/Dockerfile | 30 ++++++++++++++---------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 541c26749..fe4c8b715 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -199,7 +199,8 @@ services: # Chat Server (Rust) - v0.101 chat-server: build: - context: ./veza-chat-server + context: . + dockerfile: veza-chat-server/Dockerfile container_name: veza_chat_dev environment: - DATABASE_URL=postgresql://${POSTGRES_USER:-veza}:${POSTGRES_PASSWORD:-devpassword}@postgres:5432/${POSTGRES_DB:-veza}?sslmode=disable @@ -225,7 +226,8 @@ services: # Stream Server (Rust) - v0.101 stream-server: build: - context: ./veza-stream-server + context: . + dockerfile: veza-stream-server/Dockerfile container_name: veza_stream_dev environment: - DATABASE_URL=postgresql://${POSTGRES_USER:-veza}:${POSTGRES_PASSWORD:-devpassword}@postgres:5432/${POSTGRES_DB:-veza}?sslmode=disable diff --git a/veza-chat-server/.dockerignore b/veza-chat-server/.dockerignore index 9e3cb93c4..5e716a2e6 100644 --- a/veza-chat-server/.dockerignore +++ b/veza-chat-server/.dockerignore @@ -58,9 +58,9 @@ tmp/ temp/ *.tmp -# SQLx metadata (optional, can be regenerated) -sqlx-data.json -SQLX_METADATA.md +# SQLx metadata - KEEP sqlx-data.json for SQLX_OFFLINE build (v0.101) +# sqlx-data.json removed from ignore to allow Docker build without DB +# SQLX_METADATA.md # Config files (not needed in container if using env vars) config/ diff --git a/veza-chat-server/Dockerfile b/veza-chat-server/Dockerfile index 8123490f5..3c0751b50 100644 --- a/veza-chat-server/Dockerfile +++ b/veza-chat-server/Dockerfile @@ -1,22 +1,28 @@ -# Build stage +# Build stage - context: repo root (for veza-common path dep) FROM rust:alpine AS builder -WORKDIR /app +WORKDIR /build + +# Copy veza-common (path dependency) and chat-server +COPY veza-common ./veza-common +COPY veza-chat-server/Cargo.toml veza-chat-server/Cargo.lock ./veza-chat-server/ # Install build dependencies RUN apk add --no-cache musl-dev ca-certificates perl make pkgconfig openssl-dev protobuf-dev openssl-libs-static -# Copy Cargo files first for better caching -COPY Cargo.toml Cargo.lock ./ +WORKDIR /build/veza-chat-server # Fetch dependencies (this layer will be cached if Cargo.toml/Cargo.lock don't change) RUN cargo fetch --locked # Copy source code -COPY src ./src -COPY migrations ./migrations -COPY proto ./proto -COPY build.rs ./ +COPY veza-chat-server/src ./src +COPY veza-chat-server/migrations ./migrations +# SQLx offline build (v0.101) - no DB needed at compile time +COPY veza-chat-server/sqlx-data.json ./ +ENV SQLX_OFFLINE=true +COPY veza-chat-server/proto ./proto +COPY veza-chat-server/build.rs ./ # Build the application # Using --locked to ensure reproducible builds @@ -40,10 +46,10 @@ RUN addgroup -g 1001 -S app && \ WORKDIR /app # Copy binary from builder -COPY --from=builder --chown=app:app /app/target/x86_64-unknown-linux-musl/release/chat-server /app/chat-server +COPY --from=builder --chown=app:app /build/veza-chat-server/target/x86_64-unknown-linux-musl/release/chat-server /app/chat-server # Copy migrations if they exist -COPY --from=builder --chown=app:app /app/migrations ./migrations +COPY --from=builder --chown=app:app /build/veza-chat-server/migrations ./migrations # Switch to app user USER app diff --git a/veza-stream-server/Dockerfile b/veza-stream-server/Dockerfile index 2ee5975bc..c4ee12f8b 100644 --- a/veza-stream-server/Dockerfile +++ b/veza-stream-server/Dockerfile @@ -1,30 +1,28 @@ -# Build stage +# Build stage - context: repo root (for veza-common path dep) FROM rust:alpine AS builder -WORKDIR /app +WORKDIR /build + +# Copy veza-common (path dependency) and stream-server +COPY veza-common ./veza-common +COPY veza-stream-server/Cargo.toml veza-stream-server/Cargo.lock ./veza-stream-server/ +COPY veza-stream-server/benches ./veza-stream-server/benches # Install build dependencies RUN apk add --no-cache musl-dev ca-certificates perl make pkgconfig openssl-dev protobuf-dev openssl-libs-static -# Copy Cargo files first for better caching -COPY Cargo.toml Cargo.lock ./ -COPY benches ./benches -COPY benches ./benches +WORKDIR /build/veza-stream-server # Fetch dependencies (this layer will be cached if Cargo.toml/Cargo.lock don't change) RUN cargo fetch --locked # Copy source code -COPY src ./src -# No longer using sqlx compile-time macros (query!), so no .sqlx dir or SQLX_OFFLINE needed -ENV SQLX_OFFLINE=false -# Copy migrations if they exist (Removed as directory does not exist) -# COPY migrations ./migrations -COPY proto ./proto -COPY build.rs ./ +COPY veza-stream-server/src ./src +COPY veza-stream-server/migrations ./migrations +COPY veza-stream-server/proto ./proto +COPY veza-stream-server/build.rs ./ -# Build the application -# Using --locked to ensure reproducible builds +# Build the application (runtime queries only, no SQLX_OFFLINE needed) RUN cargo build --release --locked --target x86_64-unknown-linux-musl # Runtime stage @@ -45,7 +43,7 @@ RUN addgroup -g 1001 -S app && \ WORKDIR /app # Copy binary from builder -COPY --from=builder --chown=app:app /app/target/x86_64-unknown-linux-musl/release/stream_server /app/stream_server +COPY --from=builder --chown=app:app /build/veza-stream-server/target/x86_64-unknown-linux-musl/release/stream_server /app/stream_server # Copy migrations if they exist (Removed as directory does not exist) # COPY --from=builder --chown=app:app /app/migrations ./migrations