# matches node:lts-alpine at time of writing, but we don't want to risk updates we have not checked, so we manually define this version
FROM node:24.4-alpine
# context is from host machine app/ to make sure we can include the shared dir

WORKDIR /app

# add bash since alpine doesn't come with a shell
RUN apk update && apk add bash curl

COPY backend/package.json backend/yarn.lock ./

ARG NODE_ENV

RUN if [ "$NODE_ENV" = "internal" ]; \
      then yarn install; \
      else yarn install --production=true; \
      fi;

# make sure our raclette packages are being resolved by adding a symlink to handle nodes module resolution
RUN mkdir -p /app/node_modules/@raclettejs/core
RUN ln -sf /app/src /app/node_modules/@raclettejs/core/backend

# copy everything else that is not ignored (see .dockerignore)
COPY backend ./

# set default values
ENV PORT 3000

# Note: when running production mode locally, make sure there is no node_modules folder under frontend in your filesystem
# otherwise this will not work because it overwrites the installed deps
RUN if [ "$NODE_ENV" != "internal" ]; then \
      yarn run build; \
      fi


# set port
EXPOSE $PORT
EXPOSE 9229

# default command
CMD ["yarn", "run", "dev"]
