FROM node:20-alpine

WORKDIR /var/www/wkvs/websocket

# Install pm2 globally
RUN npm install -g pm2

# Copy package files from the websocket folder
COPY websocket/package*.json ./

# Install dependencies strictly following lockfile
RUN npm ci

# Copy the rest of the application source code from websocket folder
COPY websocket/ ./

# Change ownership to the non-root node user for security
RUN chown -R node:node /var/www/wkvs/websocket
USER node

EXPOSE 3000

CMD ["pm2-runtime", "start", "index.js"]