# Install dependencies only when needed
FROM node:fermium-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /home/app/
COPY package.json package-lock.json ./ 
RUN npm ci


# Bundle static assets with nginx
FROM node:fermium-alpine as production

# Copy built assets from builder
WORKDIR /home/app/
COPY --from=deps ./home/app/node_modules ./node_modules
COPY . .

# Expose ports
EXPOSE 3000

ENV NODE_ENV production
ENV USER_NAME=node_user USER_UID=2000 GROUP_NAME=node_group GROUP_UID=2000

RUN deluser --remove-home node \
    && addgroup --g ${GROUP_UID} -S ${GROUP_NAME} \ 
    && adduser -D -S -s /sbin/nologin -u ${USER_UID} -G ${GROUP_NAME} ${USER_NAME}
USER "${USER_NAME}"


ENTRYPOINT [ "npm","start"]