# Multi-stage Dockerfile for Flamenco development environment # Supports development with hot-reloading and production builds # ============================================================================= # Base stage with common dependencies # ============================================================================= FROM golang:1.24-alpine AS base # Install system dependencies RUN apk add --no-cache \ git \ make \ nodejs \ npm \ yarn \ openjdk11-jre-headless \ sqlite \ bash \ curl \ ca-certificates \ python3 \ python3-dev \ py3-pip # Set Go environment ENV CGO_ENABLED=0 ENV GOPROXY=https://proxy.golang.org,direct ENV GOSUMDB=sum.golang.org # Create app directory WORKDIR /app # ============================================================================= # Dependencies stage - Install and cache dependencies # ============================================================================= FROM base AS deps # Copy dependency files COPY go.mod go.sum ./ COPY web/app/package.json web/app/yarn.lock ./web/app/ COPY addon/pyproject.toml addon/poetry.lock* ./addon/ # Download Go dependencies RUN go mod download # Install Node.js dependencies WORKDIR /app/web/app RUN yarn install --frozen-lockfile # Install Python dependencies for add-on development WORKDIR /app/addon RUN pip3 install --no-cache-dir --break-system-packages uv RUN uv sync --no-dev || true WORKDIR /app # ============================================================================= # Build tools stage - Install Flamenco build tools # ============================================================================= FROM deps AS build-tools # Copy source files needed for build tools COPY . ./ # Install build dependencies and compile mage RUN go run mage.go -compile ./mage && chmod +x ./magefiles/mage && cp ./magefiles/mage ./mage # Install Flamenco generators RUN ./mage installGenerators || go run mage.go installDeps # ============================================================================= # Development stage - Full development environment # ============================================================================= FROM build-tools AS development # Install development tools (compatible with Go 1.24) RUN go install github.com/air-verse/air@v1.52.3 RUN go install github.com/githubnemo/CompileDaemon@latest # Copy mage binary from build-tools stage COPY --from=build-tools /app/mage ./mage # Copy full source code COPY . . # Warm build cache for better performance RUN ./mage cacheStatus || echo "No cache yet" # Use optimized build with caching and parallelization RUN ./mage buildOptimized || ./mage build # Show cache status after build RUN ./mage cacheStatus || echo "Cache status unavailable" # Copy binaries to /usr/local/bin to avoid mount override RUN cp flamenco-manager /usr/local/bin/ && cp flamenco-worker /usr/local/bin/ && cp mage /usr/local/bin/ # Expose ports EXPOSE 8080 8081 8082 # Development command with hot-reloading CMD ["./mage", "devServer"] # ============================================================================= # Builder stage - Build production binaries # ============================================================================= FROM build-tools AS builder # Copy source code COPY . . # Use optimized build for production binaries RUN ./mage buildOptimized # Verify binaries exist RUN ls -la flamenco-manager flamenco-worker # ============================================================================= # Production stage - Minimal runtime image # ============================================================================= FROM alpine:latest AS production # Install runtime dependencies RUN apk add --no-cache \ ca-certificates \ sqlite \ tzdata # Create flamenco user RUN addgroup -g 1000 flamenco && \ adduser -D -s /bin/sh -u 1000 -G flamenco flamenco # Create directories RUN mkdir -p /app /data /shared-storage && \ chown -R flamenco:flamenco /app /data /shared-storage # Copy binaries from builder COPY --from=builder /app/flamenco-manager /app/flamenco-worker /app/ COPY --from=builder /app/web/static /app/web/static # Set ownership RUN chown -R flamenco:flamenco /app USER flamenco WORKDIR /app # Default to manager, can be overridden CMD ["./flamenco-manager"] # ============================================================================= # Test stage - For running tests in CI # ============================================================================= FROM build-tools AS test COPY . . RUN ./mage generate RUN ./mage check # ============================================================================= # Tools stage - Development utilities # ============================================================================= FROM base AS tools # Install additional development tools RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest RUN go install github.com/pressly/goose/v3/cmd/goose@latest RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest CMD ["/bin/bash"]