FROM node:17.1-alpine

COPY . /usr/src/app

WORKDIR /usr/src/app

RUN npm install pm2 -g && \
    npm install && \
    npm run build

# Set the environment variable for the fixed port
ENV PORT=3000

# Start the application using pm2-runtime
CMD ["pm2-runtime", "dist/main.js", "--env", "PORT=$PORT"]
