# Use the official Node.js 18 image (slim version to save space)
FROM node:18-bullseye-slim

# Install Python and FFmpeg (required since ytdlp-nodejs downloads yt-dlp python script and needs ffmpeg)
# We use apt-get to install these system dependencies
RUN apt-get update && apt-get install -y python3 ffmpeg && rm -rf /var/lib/apt/lists/*

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json first
COPY package*.json ./

# Install npm dependencies
RUN npm install

# Copy the rest of the backend files
COPY . .

# Expose the port (Cloud Run defaults to 8080)
ENV PORT=8080
EXPOSE 8080

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