ARG NODE_IMAGE=node:20.11.0-alpine
ARG NGINX_IMAGE=openeuler/nginx:1.21.5-oe2203lts
FROM --platform=${BUILDPLATFORM} ${NODE_IMAGE} AS build
WORKDIR /app
COPY --link package.json ./
RUN npm install
COPY --link index.html vite.config.js ./
COPY --link ./src ./src
RUN npm run build
FROM ${NGINX_IMAGE} AS final
USER 0
ARG PLUGIN_NAME=cluster
ARG USER=nonroot
ARG HOME=/home/${USER}
ENV USER=${USER}
ENV HOME=${HOME}
WORKDIR ${HOME}
RUN chmod g=u "${HOME}" /etc/passwd
COPY --link --from=build /app/dist/index.html /usr/share/nginx/html/
COPY --link --from=build /app/dist/${PLUGIN_NAME}/${PLUGIN_NAME}.mjs /usr/share/nginx/html/dist/
COPY --link build/nginx.conf /etc/nginx/nginx.conf
COPY --link --chmod=555 <<EOF /entrypoint
if ! whoami > /dev/null 2>& 1; then
if [ -w /etc/passwd ]; then
echo "${USER}:x:\$(id -u):0::${HOME}:/sbin/nologin" >> /etc/passwd
fi
fi
exec "\$@"
EOF
EXPOSE 8080
ENTRYPOINT ["/entrypoint"]
CMD ["nginx", "-g", "daemon off;"]