Fix Dockerfile for Dokku deployment

- Simplified to single final stage (no named targets)
- Dokku sets PORT=5000 automatically, app reads from env
- Added curl for health check reliability
- Include all binaries in single image for flexibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-26 20:10:38 -06:00
parent 1f12f3f62a
commit 71075e913e

View File

@@ -25,11 +25,11 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/work
# Build the admin binary # Build the admin binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/admin ./cmd/admin RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/admin ./cmd/admin
# Final stage - API # Final stage - Production API (default target for Dokku)
FROM alpine:3.19 AS api FROM alpine:3.19
# Install runtime dependencies # Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata RUN apk add --no-cache ca-certificates tzdata curl
# Create non-root user # Create non-root user
RUN addgroup -g 1000 app && adduser -u 1000 -G app -s /bin/sh -D app RUN addgroup -g 1000 app && adduser -u 1000 -G app -s /bin/sh -D app
@@ -37,9 +37,17 @@ RUN addgroup -g 1000 app && adduser -u 1000 -G app -s /bin/sh -D app
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Copy binary from builder # Copy all binaries from builder
COPY --from=builder /app/api /app/api COPY --from=builder /app/api /app/api
COPY --from=builder /app/templates /app/templates COPY --from=builder /app/worker /app/worker
COPY --from=builder /app/admin /app/admin
# Copy templates directory if it exists
COPY --from=builder /app/templates /app/templates 2>/dev/null || true
# Copy migrations and seeds for production use
COPY --from=builder /app/migrations /app/migrations
COPY --from=builder /app/seeds /app/seeds
# Create uploads directory # Create uploads directory
RUN mkdir -p /app/uploads && chown -R app:app /app RUN mkdir -p /app/uploads && chown -R app:app /app
@@ -47,61 +55,12 @@ RUN mkdir -p /app/uploads && chown -R app:app /app
# Switch to non-root user # Switch to non-root user
USER app USER app
# Expose port # Expose port (Dokku will set PORT env var to 5000)
EXPOSE 8000 EXPOSE 5000
# Health check # Health check using curl (more reliable)
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8000/api/health/ || exit 1 CMD curl -f http://localhost:${PORT:-5000}/api/health/ || exit 1
# Run the API # Run the API (default command)
CMD ["/app/api"] CMD ["/app/api"]
# Final stage - Worker
FROM alpine:3.19 AS worker
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user
RUN addgroup -g 1000 app && adduser -u 1000 -G app -s /bin/sh -D app
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/worker /app/worker
COPY --from=builder /app/templates /app/templates
# Switch to non-root user
USER app
# Run the worker
CMD ["/app/worker"]
# Final stage - Admin
FROM alpine:3.19 AS admin
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user
RUN addgroup -g 1000 app && adduser -u 1000 -G app -s /bin/sh -D app
# Set working directory
WORKDIR /app
# Copy binary from builder
COPY --from=builder /app/admin /app/admin
# Create uploads directory for GoAdmin
RUN mkdir -p /app/uploads && chown -R app:app /app
# Switch to non-root user
USER app
# Expose port
EXPOSE 9000
# Run the admin panel
CMD ["/app/admin"]