- Convert all sqlx::query!() and sqlx::query_scalar!() compile-time macros to runtime sqlx::query() and sqlx::query_scalar() with .bind() - Affected files: segment_tracker.rs, processor.rs, callbacks.rs - This removes the dependency on .sqlx/ directory for offline mode - Update Dockerfile to remove SQLX_OFFLINE=true and .sqlx COPY - Stream server can now compile without a live database connection The compile-time macros required either a DATABASE_URL at build time or a .sqlx directory with cached query metadata (neither was available). Runtime queries trade compile-time SQL validation for buildability. Addresses audit finding: debt item 1 (stream server compilation). Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.8 KiB
Docker
64 lines
1.8 KiB
Docker
# Build stage
|
|
FROM rust:alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# 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
|
|
|
|
# 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 ./
|
|
|
|
# Build the application
|
|
# Using --locked to ensure reproducible builds
|
|
RUN cargo build --release --locked --target x86_64-unknown-linux-musl
|
|
|
|
# Runtime stage
|
|
FROM alpine:latest
|
|
|
|
# Install runtime dependencies
|
|
RUN apk --no-cache add ca-certificates tzdata && \
|
|
# Add wget for health checks
|
|
apk --no-cache add wget && \
|
|
# Clean up apk cache
|
|
rm -rf /var/cache/apk/*
|
|
|
|
# Create non-root user for security
|
|
RUN addgroup -g 1001 -S app && \
|
|
adduser -S app -u 1001 -G app -h /app -s /bin/sh
|
|
|
|
# Set working directory
|
|
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 migrations if they exist (Removed as directory does not exist)
|
|
# COPY --from=builder --chown=app:app /app/migrations ./migrations
|
|
|
|
# Switch to app user
|
|
USER app
|
|
|
|
# Expose port
|
|
EXPOSE 8082
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=15s --start-period=60s --retries=5 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8082/health || exit 1
|
|
|
|
# Run the application
|
|
CMD ["./stream_server"]
|