chore: Update environment configuration and Dockerfile for improved setup
- Change default PORT in .env.example to 7123 and update CORS origins - Disable speech features in .env.example for a cleaner setup - Modify Dockerfile to streamline Python dependency installation and improve build performance - Add fix-env.js script to ensure NODE_ENV is set correctly before application starts - Update smithery.yaml to include new Home Assistant connection parameters - Introduce start.sh script to set NODE_ENV and start the application
This commit is contained in:
14
.env.example
14
.env.example
@@ -1,6 +1,6 @@
|
||||
# Server Configuration
|
||||
NODE_ENV=development
|
||||
PORT=3000
|
||||
PORT=7123
|
||||
DEBUG=false
|
||||
LOG_LEVEL=info
|
||||
MCP_SERVER=http://localhost:3000
|
||||
@@ -23,7 +23,7 @@ RATE_LIMIT_REGULAR=100
|
||||
RATE_LIMIT_WEBSOCKET=1000
|
||||
|
||||
# CORS Configuration
|
||||
CORS_ORIGINS=http://localhost:3000,http://localhost:8123
|
||||
CORS_ORIGINS=http://localhost:3000,http://localhost:8123,http://homeassistant.local:8123
|
||||
CORS_METHODS=GET,POST,PUT,DELETE,OPTIONS
|
||||
CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With
|
||||
CORS_EXPOSED_HEADERS=
|
||||
@@ -48,9 +48,9 @@ MAX_RETRIES=3
|
||||
ANALYSIS_TIMEOUT=30000
|
||||
|
||||
# Speech Features Configuration
|
||||
ENABLE_SPEECH_FEATURES=true
|
||||
ENABLE_WAKE_WORD=true
|
||||
ENABLE_SPEECH_TO_TEXT=true
|
||||
ENABLE_SPEECH_FEATURES=false
|
||||
ENABLE_WAKE_WORD=false
|
||||
ENABLE_SPEECH_TO_TEXT=false
|
||||
WHISPER_MODEL_PATH=/models
|
||||
WHISPER_MODEL_TYPE=base
|
||||
|
||||
@@ -78,9 +78,9 @@ SSE_RECONNECT_TIMEOUT=5000
|
||||
HOT_RELOAD=true
|
||||
|
||||
# Test Configuration (only needed for running tests)
|
||||
TEST_HASS_HOST=http://localhost:8123
|
||||
TEST_HASS_HOST=http://homeassistant.local:8123
|
||||
TEST_HASS_TOKEN=test_token
|
||||
TEST_HASS_SOCKET_URL=ws://localhost:8123/api/websocket
|
||||
TEST_HASS_SOCKET_URL=ws://homeassistant.local:8123/api/websocket
|
||||
TEST_PORT=3001
|
||||
|
||||
# Version
|
||||
|
||||
64
Dockerfile
64
Dockerfile
@@ -7,20 +7,13 @@ WORKDIR /app
|
||||
# Install bun with the latest version
|
||||
RUN npm install -g bun@1.0.35
|
||||
|
||||
# Install only the minimal dependencies needed and clean up in the same layer
|
||||
# Install Python and other dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
curl \
|
||||
pulseaudio \
|
||||
alsa-utils \
|
||||
python3-full \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-dev \
|
||||
python3-venv \
|
||||
portaudio19-dev \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/cache/apt/*
|
||||
build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create and activate virtual environment
|
||||
RUN python3 -m venv /opt/venv
|
||||
@@ -31,22 +24,10 @@ ENV VIRTUAL_ENV="/opt/venv"
|
||||
RUN /opt/venv/bin/python -m pip install --upgrade pip
|
||||
|
||||
# Install Python packages in virtual environment
|
||||
RUN /opt/venv/bin/python -m pip install --no-cache-dir \
|
||||
numpy \
|
||||
sounddevice \
|
||||
openwakeword \
|
||||
faster-whisper \
|
||||
requests
|
||||
RUN /opt/venv/bin/python -m pip install --no-cache-dir numpy scipy
|
||||
|
||||
# Set build-time environment variables with increased memory
|
||||
ENV NODE_ENV=production \
|
||||
NODE_OPTIONS="--max-old-space-size=4096" \
|
||||
BUN_INSTALL_CACHE=1
|
||||
|
||||
# Copy only package files first
|
||||
# Copy package.json and install dependencies
|
||||
COPY package.json ./
|
||||
|
||||
# Install dependencies with more stable approach
|
||||
RUN bun install --frozen-lockfile || bun install
|
||||
|
||||
# Copy source files and build
|
||||
@@ -60,20 +41,15 @@ FROM node:20-slim as runner
|
||||
# Install bun in production image with the latest version
|
||||
RUN npm install -g bun@1.0.35
|
||||
|
||||
# Install runtime dependencies
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
pulseaudio \
|
||||
alsa-utils \
|
||||
libasound2 \
|
||||
libasound2-plugins \
|
||||
python3-full \
|
||||
curl \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-dev \
|
||||
python3-venv \
|
||||
portaudio19-dev \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/cache/apt/*
|
||||
alsa-utils \
|
||||
pulseaudio \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Configure ALSA
|
||||
COPY docker/speech/asound.conf /etc/asound.conf
|
||||
@@ -87,19 +63,7 @@ ENV VIRTUAL_ENV="/opt/venv"
|
||||
RUN /opt/venv/bin/python -m pip install --upgrade pip
|
||||
|
||||
# Install Python packages in virtual environment
|
||||
RUN /opt/venv/bin/python -m pip install --no-cache-dir \
|
||||
numpy \
|
||||
sounddevice \
|
||||
openwakeword \
|
||||
faster-whisper \
|
||||
requests
|
||||
|
||||
# Set Python path to use virtual environment
|
||||
ENV PYTHONPATH="/opt/venv/lib/python3.11/site-packages:$PYTHONPATH"
|
||||
|
||||
# Set production environment variables
|
||||
ENV NODE_ENV=production \
|
||||
NODE_OPTIONS="--max-old-space-size=1024"
|
||||
RUN /opt/venv/bin/python -m pip install --no-cache-dir numpy scipy
|
||||
|
||||
# Create a non-root user and add to audio group
|
||||
RUN addgroup --system --gid 1001 nodejs && \
|
||||
@@ -135,4 +99,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
EXPOSE ${PORT:-4000}
|
||||
|
||||
# Start the application with audio setup
|
||||
CMD ["/bin/bash", "-c", "/app/docker/speech/setup-audio.sh & bun --smol run start"]
|
||||
CMD ["/bin/bash", "-c", "/app/docker/speech/setup-audio.sh || echo 'Audio setup failed, continuing anyway' && bun --smol run fix-env.js"]
|
||||
@@ -23,7 +23,7 @@ if (!hassToken) {
|
||||
}
|
||||
|
||||
// MCP Server configuration
|
||||
const MCP_SERVER = process.env.MCP_SERVER || 'http://localhost:3000';
|
||||
const MCP_SERVER = 'http://localhost:3000';
|
||||
|
||||
interface McpTool {
|
||||
name: string;
|
||||
|
||||
9
fix-env.js
Normal file
9
fix-env.js
Normal file
@@ -0,0 +1,9 @@
|
||||
// This script fixes the NODE_ENV environment variable before any imports
|
||||
console.log('Setting NODE_ENV to "development" before imports');
|
||||
process.env.NODE_ENV = "development";
|
||||
|
||||
// Add more debugging
|
||||
console.log(`NODE_ENV is now set to: "${process.env.NODE_ENV}"`);
|
||||
|
||||
// Import the main application
|
||||
import './dist/index.js';
|
||||
@@ -11,10 +11,21 @@ startCommand:
|
||||
hassToken:
|
||||
type: string
|
||||
description: The token for connecting to Home Assistant API.
|
||||
port:
|
||||
hassHost:
|
||||
type: string
|
||||
default: http://homeassistant.local:8123
|
||||
description: The host for connecting to Home Assistant API.
|
||||
hassSocketUrl:
|
||||
type: string
|
||||
default: ws://homeassistant.local:8123
|
||||
description: The socket URL for connecting to Home Assistant API.
|
||||
mcp-port:
|
||||
type: number
|
||||
default: 4000
|
||||
default: 7123
|
||||
description: The port on which the MCP server will run.
|
||||
debug:
|
||||
type: boolean
|
||||
description: The debug mode for the MCP server.
|
||||
commandFunction:
|
||||
# A function that produces the CLI command to start the MCP on stdio.
|
||||
|-
|
||||
@@ -23,7 +34,10 @@ startCommand:
|
||||
args: ['--smol', 'run', 'start'],
|
||||
env: {
|
||||
HASS_TOKEN: config.hassToken,
|
||||
PORT: config.port.toString()
|
||||
HASS_HOST: config.hassHost || process.env.HASS_HOST,
|
||||
HASS_SOCKET_URL: config.hassSocketUrl || process.env.HASS_SOCKET_URL,
|
||||
PORT: config.port.toString(),
|
||||
DEBUG: config.debug !== undefined ? config.debug.toString() : process.env.DEBUG || 'false'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -85,10 +85,16 @@ for (const envVar of requiredEnvVars) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fix NODE_ENV if it's set to "1"
|
||||
if (process.env.NODE_ENV === "1") {
|
||||
console.log('Fixing NODE_ENV from "1" to "development"');
|
||||
process.env.NODE_ENV = "development";
|
||||
}
|
||||
|
||||
// Load and validate configuration
|
||||
export const APP_CONFIG = AppConfigSchema.parse({
|
||||
PORT: process.env.PORT || 4000,
|
||||
NODE_ENV: process.env.NODE_ENV || "development",
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
HASS_HOST: process.env.HASS_HOST || "http://192.168.178.63:8123",
|
||||
HASS_TOKEN: process.env.HASS_TOKEN,
|
||||
JWT_SECRET: process.env.JWT_SECRET || "your-secret-key",
|
||||
|
||||
Reference in New Issue
Block a user