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:
jango-blockchained
2025-03-15 18:55:53 +01:00
parent 615b05c8d6
commit 575e16f2fa
7 changed files with 58 additions and 62 deletions

View File

@@ -1,6 +1,6 @@
# Server Configuration # Server Configuration
NODE_ENV=development NODE_ENV=development
PORT=3000 PORT=7123
DEBUG=false DEBUG=false
LOG_LEVEL=info LOG_LEVEL=info
MCP_SERVER=http://localhost:3000 MCP_SERVER=http://localhost:3000
@@ -23,7 +23,7 @@ RATE_LIMIT_REGULAR=100
RATE_LIMIT_WEBSOCKET=1000 RATE_LIMIT_WEBSOCKET=1000
# CORS Configuration # 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_METHODS=GET,POST,PUT,DELETE,OPTIONS
CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With
CORS_EXPOSED_HEADERS= CORS_EXPOSED_HEADERS=
@@ -48,9 +48,9 @@ MAX_RETRIES=3
ANALYSIS_TIMEOUT=30000 ANALYSIS_TIMEOUT=30000
# Speech Features Configuration # Speech Features Configuration
ENABLE_SPEECH_FEATURES=true ENABLE_SPEECH_FEATURES=false
ENABLE_WAKE_WORD=true ENABLE_WAKE_WORD=false
ENABLE_SPEECH_TO_TEXT=true ENABLE_SPEECH_TO_TEXT=false
WHISPER_MODEL_PATH=/models WHISPER_MODEL_PATH=/models
WHISPER_MODEL_TYPE=base WHISPER_MODEL_TYPE=base
@@ -78,9 +78,9 @@ SSE_RECONNECT_TIMEOUT=5000
HOT_RELOAD=true HOT_RELOAD=true
# Test Configuration (only needed for running tests) # 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_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 TEST_PORT=3001
# Version # Version

View File

@@ -7,20 +7,13 @@ WORKDIR /app
# Install bun with the latest version # Install bun with the latest version
RUN npm install -g bun@1.0.35 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 \ RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \ python3 \
curl \
pulseaudio \
alsa-utils \
python3-full \
python3-pip \ python3-pip \
python3-dev \
python3-venv \ python3-venv \
portaudio19-dev \ build-essential \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/*
&& apt-get clean \
&& rm -rf /var/cache/apt/*
# Create and activate virtual environment # Create and activate virtual environment
RUN python3 -m venv /opt/venv 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 RUN /opt/venv/bin/python -m pip install --upgrade pip
# Install Python packages in virtual environment # Install Python packages in virtual environment
RUN /opt/venv/bin/python -m pip install --no-cache-dir \ RUN /opt/venv/bin/python -m pip install --no-cache-dir numpy scipy
numpy \
sounddevice \
openwakeword \
faster-whisper \
requests
# Set build-time environment variables with increased memory # Copy package.json and install dependencies
ENV NODE_ENV=production \
NODE_OPTIONS="--max-old-space-size=4096" \
BUN_INSTALL_CACHE=1
# Copy only package files first
COPY package.json ./ COPY package.json ./
# Install dependencies with more stable approach
RUN bun install --frozen-lockfile || bun install RUN bun install --frozen-lockfile || bun install
# Copy source files and build # Copy source files and build
@@ -60,20 +41,15 @@ FROM node:20-slim as runner
# Install bun in production image with the latest version # Install bun in production image with the latest version
RUN npm install -g bun@1.0.35 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 \ RUN apt-get update && apt-get install -y --no-install-recommends \
pulseaudio \ curl \
alsa-utils \ python3 \
libasound2 \
libasound2-plugins \
python3-full \
python3-pip \ python3-pip \
python3-dev \
python3-venv \ python3-venv \
portaudio19-dev \ alsa-utils \
&& rm -rf /var/lib/apt/lists/* \ pulseaudio \
&& apt-get clean \ && rm -rf /var/lib/apt/lists/*
&& rm -rf /var/cache/apt/*
# Configure ALSA # Configure ALSA
COPY docker/speech/asound.conf /etc/asound.conf 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 RUN /opt/venv/bin/python -m pip install --upgrade pip
# Install Python packages in virtual environment # Install Python packages in virtual environment
RUN /opt/venv/bin/python -m pip install --no-cache-dir \ RUN /opt/venv/bin/python -m pip install --no-cache-dir numpy scipy
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"
# Create a non-root user and add to audio group # Create a non-root user and add to audio group
RUN addgroup --system --gid 1001 nodejs && \ RUN addgroup --system --gid 1001 nodejs && \
@@ -135,4 +99,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
EXPOSE ${PORT:-4000} EXPOSE ${PORT:-4000}
# Start the application with audio setup # 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"]

View File

@@ -23,7 +23,7 @@ if (!hassToken) {
} }
// MCP Server configuration // MCP Server configuration
const MCP_SERVER = process.env.MCP_SERVER || 'http://localhost:3000'; const MCP_SERVER = 'http://localhost:3000';
interface McpTool { interface McpTool {
name: string; name: string;

9
fix-env.js Normal file
View 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';

View File

@@ -11,10 +11,21 @@ startCommand:
hassToken: hassToken:
type: string type: string
description: The token for connecting to Home Assistant API. 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 type: number
default: 4000 default: 7123
description: The port on which the MCP server will run. description: The port on which the MCP server will run.
debug:
type: boolean
description: The debug mode for the MCP server.
commandFunction: commandFunction:
# A function that produces the CLI command to start the MCP on stdio. # A function that produces the CLI command to start the MCP on stdio.
|- |-
@@ -23,7 +34,10 @@ startCommand:
args: ['--smol', 'run', 'start'], args: ['--smol', 'run', 'start'],
env: { env: {
HASS_TOKEN: config.hassToken, 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'
} }
}) })

View File

@@ -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 // Load and validate configuration
export const APP_CONFIG = AppConfigSchema.parse({ export const APP_CONFIG = AppConfigSchema.parse({
PORT: process.env.PORT || 4000, 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_HOST: process.env.HASS_HOST || "http://192.168.178.63:8123",
HASS_TOKEN: process.env.HASS_TOKEN, HASS_TOKEN: process.env.HASS_TOKEN,
JWT_SECRET: process.env.JWT_SECRET || "your-secret-key", JWT_SECRET: process.env.JWT_SECRET || "your-secret-key",

3
start.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
export NODE_ENV=development
exec bun --smol run start