# Installs Node image
FROM node:18-alpine as base

# sets the working directory for any RUN, CMD, COPY command
WORKDIR /app

ENV PORT=3000
ENV DB_HOST=postgres
ENV DB_USER=postgres
ENV DB_NAME=db_name
ENV DB_PASSWORD=password
ENV DB_PORT=5432
ENV DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}

# Copies stuff to cache for install
COPY ./package.json ./package-lock.json tsconfig.json ./

RUN echo "npm install"

RUN npm install

# Copies everything in the src directory to WORKDIR/src
COPY ./src ./src
COPY ./scripts ./scripts

# Run the server
RUN echo "npm run prod-start"
CMD ["npm", "run", "prod-start"]