97 lines
2.5 KiB
Docker
97 lines
2.5 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# =============================================================================
|
|
# Stage 1: Build Web UI
|
|
# =============================================================================
|
|
FROM node:20-alpine AS webui-builder
|
|
|
|
WORKDIR /app/webui
|
|
|
|
# Install pnpm
|
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
|
|
# Copy package files
|
|
COPY webui/package.json webui/pnpm-lock.yaml ./
|
|
|
|
# Install dependencies
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
# Copy source files
|
|
COPY webui/ ./
|
|
|
|
# Build production bundle
|
|
RUN pnpm build
|
|
|
|
# =============================================================================
|
|
# Stage 2: Build Rust Server
|
|
# =============================================================================
|
|
FROM rust:1.75-alpine AS server-builder
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static pkgconf
|
|
|
|
WORKDIR /app
|
|
|
|
# Create a new empty shell project for caching dependencies
|
|
RUN cargo new --bin galvanize
|
|
WORKDIR /app/galvanize
|
|
|
|
# Copy manifests
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
# Build and cache dependencies
|
|
RUN cargo build --release && rm src/*.rs
|
|
|
|
# Copy source code
|
|
COPY src/ ./src/
|
|
|
|
# Copy Web UI build artifacts
|
|
COPY --from=webui-builder /app/webui/dist ./webui/dist
|
|
|
|
# Build the actual binary
|
|
RUN touch src/main.rs && cargo build --release --features webui
|
|
|
|
# =============================================================================
|
|
# Stage 3: Runtime Image
|
|
# =============================================================================
|
|
FROM alpine:3.20 AS runtime
|
|
|
|
# Install runtime dependencies
|
|
RUN apk add --no-cache ca-certificates tzdata
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1000 galvanize && \
|
|
adduser -u 1000 -G galvanize -s /bin/sh -D galvanize
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=server-builder /app/galvanize/target/release/galvanize /usr/local/bin/galvanize
|
|
|
|
# Create config directory
|
|
RUN mkdir -p /app/config/devices && \
|
|
chown -R galvanize:galvanize /app
|
|
|
|
# Copy example config
|
|
COPY config/galvanize.example.toml /app/config/galvanize.toml
|
|
|
|
# Switch to non-root user
|
|
USER galvanize
|
|
|
|
# Expose port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/v1/health || exit 1
|
|
|
|
# Set environment variables
|
|
ENV GALVANIZE_HOST=0.0.0.0
|
|
ENV GALVANIZE_PORT=8080
|
|
ENV GALVANIZE_CONFIG_PATH=/app/config
|
|
|
|
# Run the binary
|
|
ENTRYPOINT ["galvanize"]
|
|
CMD ["serve", "--config", "/app/config"]
|
|
|