# Installs Node image
FROM node:18-buster 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}

# intentionally here only for temporary cache-busting test
# COPY ./client ./client

RUN apt-get update
RUN apt-get -y install libsdl2-dev
RUN apt-get -y install xorg-dev

COPY ./pico8 ./pico8
# RUN echo "chmoding pico8"
# RUN chmod +x ./usr/bin/pico8

# 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"]