FROM node:lts AS development

ARG service

COPY . /opt/${service}

WORKDIR /opt/${service}

RUN npm install && npm install -g vite

CMD vite dev --port=80 --host=0.0.0.0 --strictPort --logLevel info

FROM node:lts AS build

ARG service

ENV PROTOCOL_HEADER=x-forwarded-proto
ENV HOST_HEADER=x-forwarded-host

WORKDIR /opt/${service}

COPY . /opt/${service}

RUN npm ci && npm run build \
	&& cp -v /opt/${service}/package.json /opt/${service}/build \
	&& cp -v /opt/${service}/package-lock.json /opt/${service}/build \
	&& cd /opt/${service}/build && npm ci --omit dev

FROM node:lts AS production

ARG service

LABEL com.barretthousen.service=${service}
LABEL com.barretthousen.tags="frontend,public"
LABEL com.barretthousen.release-date="2023-05-01"
LABEL com.barretthousen.version="alpha-0.0.1"
LABEL com.barretthousen.git-ref="000000000000000000000000000000000000000000000000"

ENV ENV=production
ENV PROTOCOL_HEADER=x-forwarded-proto
ENV HOST_HEADER=x-forwarded-host
ENV BH_CLIENT_SERVICE=${service}
ENV ORIGIN="https://barretthousen.com"


COPY --from=build /opt/${service}/build/ /opt/${service}/

WORKDIR /opt/${service}

ENV PORT 80

EXPOSE 80

ENTRYPOINT ["node", "."]

