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
This commit is contained in:
senke 2026-02-18 12:38:16 +01:00
parent cd5f07ee35
commit aeda9120b3
4 changed files with 37 additions and 31 deletions

View file

@ -199,7 +199,8 @@ services:
# Chat Server (Rust) - v0.101 # Chat Server (Rust) - v0.101
chat-server: chat-server:
build: build:
context: ./veza-chat-server context: .
dockerfile: veza-chat-server/Dockerfile
container_name: veza_chat_dev container_name: veza_chat_dev
environment: environment:
- DATABASE_URL=postgresql://${POSTGRES_USER:-veza}:${POSTGRES_PASSWORD:-devpassword}@postgres:5432/${POSTGRES_DB:-veza}?sslmode=disable - 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 (Rust) - v0.101
stream-server: stream-server:
build: build:
context: ./veza-stream-server context: .
dockerfile: veza-stream-server/Dockerfile
container_name: veza_stream_dev container_name: veza_stream_dev
environment: environment:
- DATABASE_URL=postgresql://${POSTGRES_USER:-veza}:${POSTGRES_PASSWORD:-devpassword}@postgres:5432/${POSTGRES_DB:-veza}?sslmode=disable - DATABASE_URL=postgresql://${POSTGRES_USER:-veza}:${POSTGRES_PASSWORD:-devpassword}@postgres:5432/${POSTGRES_DB:-veza}?sslmode=disable

View file

@ -58,9 +58,9 @@ tmp/
temp/ temp/
*.tmp *.tmp
# SQLx metadata (optional, can be regenerated) # SQLx metadata - KEEP sqlx-data.json for SQLX_OFFLINE build (v0.101)
sqlx-data.json # sqlx-data.json removed from ignore to allow Docker build without DB
SQLX_METADATA.md # SQLX_METADATA.md
# Config files (not needed in container if using env vars) # Config files (not needed in container if using env vars)
config/ config/

View file

@ -1,22 +1,28 @@
# Build stage # Build stage - context: repo root (for veza-common path dep)
FROM rust:alpine AS builder 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 # Install build dependencies
RUN apk add --no-cache musl-dev ca-certificates perl make pkgconfig openssl-dev protobuf-dev openssl-libs-static 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 WORKDIR /build/veza-chat-server
COPY Cargo.toml Cargo.lock ./
# Fetch dependencies (this layer will be cached if Cargo.toml/Cargo.lock don't change) # Fetch dependencies (this layer will be cached if Cargo.toml/Cargo.lock don't change)
RUN cargo fetch --locked RUN cargo fetch --locked
# Copy source code # Copy source code
COPY src ./src COPY veza-chat-server/src ./src
COPY migrations ./migrations COPY veza-chat-server/migrations ./migrations
COPY proto ./proto # SQLx offline build (v0.101) - no DB needed at compile time
COPY build.rs ./ 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 # Build the application
# Using --locked to ensure reproducible builds # Using --locked to ensure reproducible builds
@ -40,10 +46,10 @@ RUN addgroup -g 1001 -S app && \
WORKDIR /app WORKDIR /app
# Copy binary from builder # 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 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 # Switch to app user
USER app USER app

View file

@ -1,30 +1,28 @@
# Build stage # Build stage - context: repo root (for veza-common path dep)
FROM rust:alpine AS builder 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 # Install build dependencies
RUN apk add --no-cache musl-dev ca-certificates perl make pkgconfig openssl-dev protobuf-dev openssl-libs-static 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 WORKDIR /build/veza-stream-server
COPY Cargo.toml Cargo.lock ./
COPY benches ./benches
COPY benches ./benches
# Fetch dependencies (this layer will be cached if Cargo.toml/Cargo.lock don't change) # Fetch dependencies (this layer will be cached if Cargo.toml/Cargo.lock don't change)
RUN cargo fetch --locked RUN cargo fetch --locked
# Copy source code # Copy source code
COPY src ./src COPY veza-stream-server/src ./src
# No longer using sqlx compile-time macros (query!), so no .sqlx dir or SQLX_OFFLINE needed COPY veza-stream-server/migrations ./migrations
ENV SQLX_OFFLINE=false COPY veza-stream-server/proto ./proto
# Copy migrations if they exist (Removed as directory does not exist) COPY veza-stream-server/build.rs ./
# COPY migrations ./migrations
COPY proto ./proto
COPY build.rs ./
# Build the application # Build the application (runtime queries only, no SQLX_OFFLINE needed)
# Using --locked to ensure reproducible builds
RUN cargo build --release --locked --target x86_64-unknown-linux-musl RUN cargo build --release --locked --target x86_64-unknown-linux-musl
# Runtime stage # Runtime stage
@ -45,7 +43,7 @@ RUN addgroup -g 1001 -S app && \
WORKDIR /app WORKDIR /app
# Copy binary from builder # 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 migrations if they exist (Removed as directory does not exist)
# COPY --from=builder --chown=app:app /app/migrations ./migrations # COPY --from=builder --chown=app:app /app/migrations ./migrations