diff --git a/Dockerfile b/Dockerfile index 9a7fb0e..43fecbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,11 +25,11 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/work # Build the admin binary RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/admin ./cmd/admin -# Final stage - API -FROM alpine:3.19 AS api +# Final stage - Production API (default target for Dokku) +FROM alpine:3.19 # Install runtime dependencies -RUN apk add --no-cache ca-certificates tzdata +RUN apk add --no-cache ca-certificates tzdata curl # Create non-root user 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 WORKDIR /app -# Copy binary from builder +# Copy all binaries from builder 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 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 USER app -# Expose port -EXPOSE 8000 +# Expose port (Dokku will set PORT env var to 5000) +EXPOSE 5000 -# Health check -HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ - CMD wget --no-verbose --tries=1 --spider http://localhost:8000/api/health/ || exit 1 +# Health check using curl (more reliable) +HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ + CMD curl -f http://localhost:${PORT:-5000}/api/health/ || exit 1 -# Run the API +# Run the API (default command) 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"]