chore(gtm): Optimize Docker container with multi-stage build and flat structure
This commit is contained in:
@@ -1,28 +1,59 @@
|
||||
# Base image for Python
|
||||
FROM python:3.10-slim
|
||||
# Stage 1: Build the React frontend
|
||||
FROM node:20-slim AS frontend-builder
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy shared modules first
|
||||
COPY helpers.py /app/
|
||||
COPY config.py /app/
|
||||
# Copy package.json and install dependencies
|
||||
# We are inside the build context root, so path is gtm-architect/package.json
|
||||
COPY gtm-architect/package.json ./
|
||||
RUN npm install
|
||||
|
||||
# Copy application-specific files
|
||||
COPY gtm_architect_orchestrator.py /app/
|
||||
COPY gtm-architect /app/gtm-architect
|
||||
# Copy the source code
|
||||
COPY gtm-architect/ .
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
# ---
|
||||
|
||||
# Stage 2: Final application image
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install Node.js (minimal runtime)
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl ca-certificates && \
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
||||
apt-get install -y --no-install-recommends nodejs && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r /app/gtm-architect/requirements.txt
|
||||
# We use the requirements from the subdirectory
|
||||
COPY gtm-architect/requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Install Node.js and npm
|
||||
RUN apt-get update && apt-get install -y nodejs npm && npm cache clean --force
|
||||
# Copy the Node.js server script and package.json for runtime deps
|
||||
COPY gtm-architect/server.cjs .
|
||||
COPY gtm-architect/package.json .
|
||||
|
||||
# Install Node.js dependencies for the frontend bridge
|
||||
RUN npm install --prefix /app/gtm-architect
|
||||
# Install only production Node.js dependencies
|
||||
RUN npm install --omit=dev
|
||||
|
||||
# Expose the port the app runs on
|
||||
# Copy the built frontend from the builder stage
|
||||
COPY --from=frontend-builder /app/dist ./dist
|
||||
|
||||
# Copy the Python Orchestrator and shared modules
|
||||
COPY gtm_architect_orchestrator.py .
|
||||
COPY helpers.py .
|
||||
COPY config.py .
|
||||
COPY market_db_manager.py .
|
||||
|
||||
# Copy API Key if available (handled by docker-compose usually, but good for standalone)
|
||||
# COPY gemini_api_key.txt .
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3005
|
||||
|
||||
# Command to run the application
|
||||
CMD ["node", "/app/gtm-architect/server.cjs"]
|
||||
# Start the server
|
||||
CMD ["node", "server.cjs"]
|
||||
Reference in New Issue
Block a user