# syntax=docker/dockerfile:1
# Build context is the repository root.

FROM node:24-alpine AS build
ARG UNIFIED_VERSION=0.0.0.0
WORKDIR /app

COPY src/WebUI/package.json src/WebUI/package-lock.json src/WebUI/.npmrc ./
RUN npm ci

COPY src/WebUI/ .
ENV PUBLIC_BUILD_VERSION=${UNIFIED_VERSION}
RUN npm run build

FROM node:24-alpine
ARG UNIFIED_VERSION=0.0.0.0
# CI supplies these at image build time (empty on plain local builds).
ARG GIT_COMMIT=""
ARG GIT_COMMIT_SHORT=""
ARG BUILD_DATE=""
ARG SOURCE_URL="https://prod.git.gracesolution.info/gsadmin/ExecuteR"
LABEL org.opencontainers.image.title="ExecuteR Control Plane WebUI" \
      org.opencontainers.image.description="ExecuteR web console: React (MUI) UI for devices, groups, scripts, schedules and jobs" \
      org.opencontainers.image.version="${UNIFIED_VERSION}" \
      org.opencontainers.image.revision="${GIT_COMMIT}" \
      executer.revision.short="${GIT_COMMIT_SHORT}" \
      org.opencontainers.image.created="${BUILD_DATE}" \
      org.opencontainers.image.source="${SOURCE_URL}" \
      org.opencontainers.image.url="${SOURCE_URL}" \
      org.opencontainers.image.documentation="${SOURCE_URL}/wiki" \
      org.opencontainers.image.vendor="ExecuteR" \
      org.opencontainers.image.licenses="LicenseRef-EndexaSolutions-Proprietary"

# The console is a static SPA; server.mjs (no dependencies) serves dist/ with
# an index.html fallback for client-side routes.
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/server.mjs .

ENV PORT=3000 \
    NODE_ENV=production

EXPOSE 3000
USER node

CMD ["node", "server.mjs"]
