FROM node:18.13.0-buster AS build-container
WORKDIR /app
RUN mkdir license_client \
    && mkdir license_server
COPY license_client/ license_client/
COPY license_server/ license_server/
RUN npm install --force -g n && n 18.13.0 \
    && cd license_client \
    && npm ci \
    && npm run build \
    && cd ../license_server \
    && npm ci \
    && npm run build \
    && cd ..

FROM node:18.13.0-alpine
RUN apk --no-cache add tzdata \
    && cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
    && apk del tzdata \
    && rm -rf /var/cache/apk/*
WORKDIR /app
RUN mkdir build \
    && mkdir dist \
    && mkdir node_modules
COPY --from=build-container app/license_client/build/ build/
COPY --from=build-container app/license_server/dist/ dist/
COPY --from=build-container app/license_server/.env ./
COPY --from=build-container app/license_server/node_modules/ node_modules/
CMD ["node", "./dist/main.js" ]