feat: restructure Dockerfile and add start script for multi-service setup
Browse files- Dockerfile +37 -25
- package.json +5 -1
- src/index.js +1 -1
- start.sh +42 -0
Dockerfile
CHANGED
|
@@ -1,39 +1,51 @@
|
|
| 1 |
-
|
| 2 |
-
FROM oven/bun:1.1-alpine as base
|
| 3 |
|
| 4 |
-
# Set working directory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
RUN
|
| 10 |
|
| 11 |
-
# Copy
|
| 12 |
-
COPY
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
RUN
|
| 16 |
|
| 17 |
-
# Copy
|
| 18 |
-
COPY --chown=
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Create necessary directories and set permissions
|
| 21 |
-
RUN mkdir -p /app/logs /app/temp
|
| 22 |
-
chown -R lumakit:nodejs /app
|
| 23 |
-
|
| 24 |
-
# Switch to non-root user
|
| 25 |
-
USER lumakit
|
| 26 |
|
| 27 |
-
# Expose
|
|
|
|
| 28 |
EXPOSE 7860
|
| 29 |
|
| 30 |
-
# Health check
|
| 31 |
-
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
| 32 |
-
CMD bun --version || exit 1
|
| 33 |
-
|
| 34 |
# Set environment variables
|
| 35 |
ENV NODE_ENV=production
|
| 36 |
-
ENV
|
|
|
|
| 37 |
|
| 38 |
-
# Start
|
| 39 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM oven/bun:latest as frontend-builder
|
|
|
|
| 2 |
|
| 3 |
+
# Set working directory for frontend
|
| 4 |
+
WORKDIR /build
|
| 5 |
+
# Copy frontend package files from the correct path
|
| 6 |
+
COPY frontend/lumakit-frontend/package.json frontend/lumakit-frontend/bun.lockb* ./
|
| 7 |
+
# Install dependencies
|
| 8 |
+
RUN bun install
|
| 9 |
+
# Copy frontend source
|
| 10 |
+
COPY frontend/lumakit-frontend/ ./
|
| 11 |
+
# Build the Next.js app
|
| 12 |
+
RUN bun run build
|
| 13 |
+
|
| 14 |
+
FROM oven/bun:latest
|
| 15 |
+
|
| 16 |
+
# Use the existing user with UID 1000 (the 'bun' user)
|
| 17 |
+
USER 1000
|
| 18 |
WORKDIR /app
|
| 19 |
|
| 20 |
+
# Copy package files and install dependencies for backend
|
| 21 |
+
COPY --chown=1000:1000 package.json bun.lockb* ./
|
| 22 |
+
RUN bun install --production
|
| 23 |
|
| 24 |
+
# Copy backend application code
|
| 25 |
+
COPY --chown=1000:1000 src/ ./src/
|
| 26 |
|
| 27 |
+
# Create frontend directory structure
|
| 28 |
+
RUN mkdir -p ./frontend/lumakit-frontend
|
| 29 |
|
| 30 |
+
# Copy built Next.js app from builder stage
|
| 31 |
+
COPY --from=frontend-builder --chown=1000:1000 /build/.next ./frontend/lumakit-frontend/.next
|
| 32 |
+
COPY --from=frontend-builder --chown=1000:1000 /build/public ./frontend/lumakit-frontend/public
|
| 33 |
+
COPY --from=frontend-builder --chown=1000:1000 /build/package.json ./frontend/lumakit-frontend/package.json
|
| 34 |
+
COPY --from=frontend-builder --chown=1000:1000 /build/next.config.mjs ./frontend/lumakit-frontend/next.config.mjs
|
| 35 |
|
| 36 |
# Create necessary directories and set permissions
|
| 37 |
+
RUN mkdir -p /app/logs /app/temp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
# Expose ports for both services (backend: 5000, frontend: 7860)
|
| 40 |
+
EXPOSE 5000
|
| 41 |
EXPOSE 7860
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Set environment variables
|
| 44 |
ENV NODE_ENV=production
|
| 45 |
+
ENV BACKEND_PORT=5000
|
| 46 |
+
ENV FRONTEND_PORT=7860
|
| 47 |
|
| 48 |
+
# Start both services using a start script
|
| 49 |
+
COPY --chown=1000:1000 start.sh ./
|
| 50 |
+
RUN chmod +x start.sh
|
| 51 |
+
CMD ["./start.sh"]
|
package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
| 1 |
{
|
| 2 |
-
"name": "lumakit",
|
| 3 |
"module": "index.js",
|
| 4 |
"type": "module",
|
| 5 |
"private": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"devDependencies": {
|
| 7 |
"@types/bun": "latest"
|
| 8 |
},
|
|
|
|
| 1 |
{
|
| 2 |
+
"name": "lumakit-backend",
|
| 3 |
"module": "index.js",
|
| 4 |
"type": "module",
|
| 5 |
"private": true,
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "bun run src/index.js",
|
| 8 |
+
"dev": "bun --hot src/index.js"
|
| 9 |
+
},
|
| 10 |
"devDependencies": {
|
| 11 |
"@types/bun": "latest"
|
| 12 |
},
|
src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import os from 'os';
|
|
| 3 |
import { promises as fs } from 'fs';
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
-
const PORT = process.env.PORT ||
|
| 7 |
|
| 8 |
app.get('/', (req, res) => {
|
| 9 |
res.send('Hello, This is LumaKit Backend!');
|
|
|
|
| 3 |
import { promises as fs } from 'fs';
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
+
const PORT = process.env.PORT || 5000;
|
| 7 |
|
| 8 |
app.get('/', (req, res) => {
|
| 9 |
res.send('Hello, This is LumaKit Backend!');
|
start.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Function to handle shutdown signals
|
| 4 |
+
cleanup() {
|
| 5 |
+
echo "Shutting down services..."
|
| 6 |
+
kill $FRONTEND_PID $BACKEND_PID 2>/dev/null
|
| 7 |
+
wait
|
| 8 |
+
exit 0
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
# Set up signal handlers
|
| 12 |
+
trap cleanup SIGTERM SIGINT
|
| 13 |
+
|
| 14 |
+
# Start Next.js frontend in the background on port 7860
|
| 15 |
+
echo "Starting LumaKit Frontend on port 7860..."
|
| 16 |
+
cd /app/frontend/lumakit-frontend && PORT=7860 bun run start &
|
| 17 |
+
FRONTEND_PID=$!
|
| 18 |
+
echo "Frontend started with PID: $FRONTEND_PID"
|
| 19 |
+
|
| 20 |
+
# Wait a moment for frontend to initialize
|
| 21 |
+
sleep 2
|
| 22 |
+
|
| 23 |
+
# Start the Express backend on port 5000
|
| 24 |
+
echo "Starting LumaKit Backend on port 5000..."
|
| 25 |
+
cd /app && PORT=5000 bun run src/index.js &
|
| 26 |
+
BACKEND_PID=$!
|
| 27 |
+
echo "Backend started with PID: $BACKEND_PID"
|
| 28 |
+
|
| 29 |
+
# Display service information
|
| 30 |
+
echo "================================"
|
| 31 |
+
echo "LumaKit Services Running:"
|
| 32 |
+
echo "Frontend (Next.js): http://localhost:7860"
|
| 33 |
+
echo "Backend (Express): http://localhost:5000"
|
| 34 |
+
echo "Backend Stats: http://localhost:5000/stats"
|
| 35 |
+
echo "================================"
|
| 36 |
+
|
| 37 |
+
# Wait for any process to exit
|
| 38 |
+
wait -n
|
| 39 |
+
|
| 40 |
+
# If we reach here, one of the processes has exited
|
| 41 |
+
echo "One of the services has stopped. Shutting down..."
|
| 42 |
+
cleanup
|