FROM node:20

WORKDIR /app

# Install build dependencies for node-pty
RUN apt-get update && apt-get install -y \
    python3 \
    make \
    g++ \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy all files first
COPY . .

# Install dependencies without running scripts
RUN npm install --ignore-scripts

# Rebuild node-pty for the container's architecture
RUN npm rebuild node-pty

# Build TypeScript
RUN npm run build

# Expose port
EXPOSE 3000

# Start the application
CMD ["npm", "start"]
