- 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
65 lines
No EOL
1.9 KiB
Docker
65 lines
No EOL
1.9 KiB
Docker
# Build stage - context: repo root (for veza-common path dep)
|
|
FROM rust:alpine AS builder
|
|
|
|
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
|
|
|
|
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 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
|
|
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 /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 /build/veza-chat-server/migrations ./migrations
|
|
|
|
# Switch to app user
|
|
USER app
|
|
|
|
# Expose port
|
|
EXPOSE 8081
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8081/health || exit 1
|
|
|
|
# Run the application
|
|
CMD ["./chat-server"] |