FROM node:16-alpine as build
WORKDIR /app

# ENV NODE_ENV production

RUN apk add --no-cache curl
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm

COPY package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install

COPY . .

RUN pnpm build


FROM nginx:1.21-alpine as production

LABEL org.opencontainers.image.source https://git.app.ygg/mtps/gentlemans
EXPOSE 80

RUN echo 'server { \
        listen 80; \
        root /build; \
        location / { \
                try_files $uri $uri/ /index.html; \
        } \
}' > /etc/nginx/conf.d/default.conf

COPY --from=build /app/build /build

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