mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-16 08:25:18 +02:00
Merge 5dd9ad5c40 into 5bf7518829
This commit is contained in:
commit
867b484eac
6 changed files with 652 additions and 7 deletions
|
|
@ -1,3 +1,18 @@
|
|||
# Backend Configuration
|
||||
# =====================
|
||||
# BACKEND_URL: Used by Next.js server-side rewrites (SSR, API proxying)
|
||||
# - Should point to your backend API service
|
||||
# - In Docker Compose: http://api:8000 (internal network)
|
||||
# - In CapRover/custom: http://srv-captain--dograh-api:8000 or https://api.yourdomain.com:8000
|
||||
BACKEND_URL=http://localhost:8000
|
||||
|
||||
# NEXT_PUBLIC_BACKEND_URL: Used by client-side JavaScript (browser API calls)
|
||||
# - Available in browser console and React components
|
||||
# - For local dev: http://localhost:8000 or http://localhost:3010 (if proxied)
|
||||
# - For production: Use external URL that browsers can reach
|
||||
NEXT_PUBLIC_BACKEND_URL=http://localhost:8000
|
||||
|
||||
# Node Environment
|
||||
# ================
|
||||
# development | production | oss (default for self-hosted)
|
||||
NEXT_PUBLIC_NODE_ENV=development
|
||||
|
|
|
|||
|
|
@ -35,12 +35,19 @@ COPY ui/postcss.config.mjs ./
|
|||
COPY ui/public ./public
|
||||
COPY ui/src ./src
|
||||
|
||||
# Accept backend URL as build argument (allow customization during image build)
|
||||
ARG BACKEND_URL=http://api:8000
|
||||
ARG NEXT_PUBLIC_BACKEND_URL=http://localhost:3010
|
||||
|
||||
# Set build-time environment variables (needed for Next.js build)
|
||||
ENV NEXT_PUBLIC_NODE_ENV="oss"
|
||||
ENV NEXT_TELEMETRY_DISABLED="1"
|
||||
ENV NEXT_PUBLIC_CHATWOOT_URL="https://chat.dograh.com"
|
||||
ENV NEXT_PUBLIC_CHATWOOT_TOKEN="3fkFx2mCEjNHjM9gaNc4A82X"
|
||||
ENV BACKEND_URL="http://api:8000"
|
||||
# Server-side backend URL (used by Next.js rewrites for SSR/API proxying)
|
||||
ENV BACKEND_URL=${BACKEND_URL}
|
||||
# Client-side backend URL (used by browser-side API calls)
|
||||
ENV NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
|
||||
|
||||
# Build the application with standalone mode
|
||||
# Increase Node.js heap size to prevent out-of-memory errors during build
|
||||
|
|
@ -64,11 +71,15 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
|
||||
# Copy entrypoint script for runtime configuration
|
||||
COPY --chown=nextjs:nodejs ui/entrypoint.sh /app/entrypoint.sh
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
# Switch to non-root user
|
||||
USER nextjs
|
||||
|
||||
# Expose the port Next.js runs on
|
||||
EXPOSE 3010
|
||||
|
||||
# Start the production server using the standalone Node.js server
|
||||
CMD sh -c "echo '🚀 Application ready at http://localhost:3010' && PORT=3010 node server.js"
|
||||
# Use entrypoint script to enable runtime configuration of backend URLs
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
|
|
|
|||
56
ui/entrypoint.sh
Normal file
56
ui/entrypoint.sh
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/sh
|
||||
# Dograh UI Entrypoint Script
|
||||
# This script enables runtime configuration of backend URLs for flexible deployments
|
||||
# Supports: Docker Compose, Docker Swarm, Kubernetes, CapRover, and custom orchestration
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
UI_PORT="${PORT:-3010}"
|
||||
BACKEND_URL="${BACKEND_URL:-http://api:8000}"
|
||||
NEXT_PUBLIC_BACKEND_URL="${NEXT_PUBLIC_BACKEND_URL:-http://localhost:3010}"
|
||||
|
||||
# Logging
|
||||
log() {
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
|
||||
}
|
||||
|
||||
log "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
log "🚀 Dograh UI Server - Production Ready"
|
||||
log "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
# Validate and display configuration
|
||||
log "📋 Configuration:"
|
||||
log " UI Port: $UI_PORT"
|
||||
log " Backend URL (Server-side): $BACKEND_URL"
|
||||
log " Backend URL (Client-side): $NEXT_PUBLIC_BACKEND_URL"
|
||||
log " Node Environment: ${NODE_ENV:-production}"
|
||||
log " Telemetry: ${ENABLE_TELEMETRY:-true}"
|
||||
|
||||
# Health check for backend connectivity (informational only)
|
||||
if [ "$CHECK_BACKEND" = "true" ] || [ "$CHECK_BACKEND" = "1" ]; then
|
||||
log "🔍 Verifying backend connectivity..."
|
||||
if command -v curl > /dev/null 2>&1; then
|
||||
if curl -sf "${BACKEND_URL}/api/v1/health" > /dev/null 2>&1; then
|
||||
log "✅ Backend is reachable at ${BACKEND_URL}"
|
||||
else
|
||||
log "⚠️ Warning: Backend may not be reachable at ${BACKEND_URL}"
|
||||
log " This could be normal if backend is not yet started"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
log "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
log "✅ Starting Next.js server on port $UI_PORT..."
|
||||
log "📍 Access UI at: http://localhost:$UI_PORT"
|
||||
log "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
# Export variables for Node.js process
|
||||
export PORT=$UI_PORT
|
||||
export BACKEND_URL=$BACKEND_URL
|
||||
export NEXT_PUBLIC_BACKEND_URL=$NEXT_PUBLIC_BACKEND_URL
|
||||
export NODE_ENV=${NODE_ENV:-production}
|
||||
|
||||
# Start the Next.js server
|
||||
# Using the standalone server (specified in next.config.ts)
|
||||
exec node server.js
|
||||
Loading…
Add table
Add a link
Reference in a new issue