# Build stage
FROM node:20 AS builder

ARG TENANT=tis
ARG DIST_DIR=tis

WORKDIR /app

# RUN npm config set registry "https://hub.megan.ir/npm/"

RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install

COPY . .

RUN if [ "$TENANT" = "default" ]; then \
      pnpm run build; \
    else \
      pnpm run build:$TENANT; \
    fi

FROM nginx:alpine

ARG DIST_DIR=tis

COPY nginx.conf /etc/nginx/nginx.conf

COPY --from=builder /app/dist/${DIST_DIR}/browser /usr/share/nginx/html

EXPOSE 5000

CMD ["nginx", "-g", "daemon off;"]
