FROM node:18-alpine as builder
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm ci
COPY . .
#EXPOSE 5173
#CMD ["npm", "run", "dev"]
RUN \
  if [ $PROFILES_ACTIVE='development' ]; then echo "env PROFILES_ACTIVE=development. exec npm run buildDev" && npm run buildDev; \
  else echo "env PROFILES_ACTIVE not found. exec npm run build" && npm run build; \
  fi

# nginx
FROM nginx:alpine as production
VOLUME ["/var/log/nginx/"]
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
ENV NODE_ENV production
# Set working directory to nginx asset directory
COPY --from=builder /app/dist /usr/share/nginx/html
#COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
# Containers run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"]