FROM node:16

WORKDIR /app

ARG APP_ENV=development
ARG APP_HOST=app
ARG APP_PORT=3000

ARG MARIADB_HOST=mariadb
ARG MARIADB_PORT=3306
ARG MARIADB_USER=root
ARG MARIADB_PASSWORD=root
ARG MARIADB_DATABASE=db

ARG MONGODB_HOST=mongodb
ARG MONGODB_PORT=27017
ARG MONGODB_USER=root
ARG MONGODB_PASSWORD=root
ARG MONGODB_DATABASE=db

ENV APP_ENV=$APP_ENV
ENV PORT=$APP_PORT

ENV MARIADB_HOST=$MARIADB_HOST
ENV MARIADB_PORT=$MARIADB_PORT
ENV MARIADB_USER=$MARIADB_USER
ENV MARIADB_PASSWORD=$MARIADB_PASSWORD
ENV MARIADB_DATABASE=$MARIADB_DATABASE

ENV MONGODB_HOST=$MONGODB_HOST
ENV MONGODB_PORT=$MONGODB_PORT
ENV MONGODB_USER=$MONGODB_USER
ENV MONGODB_PASSWORD=$MONGODB_PASSWORD
ENV MONGODB_DATABASE=$MONGODB_DATABASE

COPY package.json .
COPY tsconfig.json .
COPY .prettierrc .
COPY .prettierignore .

VOLUME /app/src

RUN npm install
CMD sh -c "if [ \"$APP_ENV\" = \"production\" ]; then npm run start; else npm run dev; fi"

EXPOSE $PORT
