# syntax=docker/dockerfile:1-labs
FROM ubuntu:noble AS build
# Install deps
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates build-essential
# Install Node.js from NodeSource repository
# We extract the version from .nvmrc
COPY .nvmrc /nvmrc
RUN <<EOF
# Extract major version (e.g., "18" from "18.x.x")
NODE_MAJOR=$(cat /nvmrc | cut -d. -f1 | tr -d 'v\n')
# Add NodeSource repository and its signing key
curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash -
# Install the specific version listed in the nvmrc file
NODE_VERSION=$(cat /nvmrc | tr -d 'v\n')
apt-get install -y --no-install-recommends nodejs=${NODE_VERSION}-1nodesource1
EOF
RUN --mount=type=cache,target=/root/.npm npm install -g @microsoft/rush@5
WORKDIR /app
COPY ./npm-packages ./npm-packages
# Install dependencies and build
WORKDIR /app/npm-packages/dashboard-self-hosted
RUN rush install
ENV NODE_ENV=production
RUN rush build -t dashboard-self-hosted
RUN rush-pnpm deploy --legacy --filter=dashboard-self-hosted --prod /tmp/deploy
FROM ubuntu:noble
# Install Node.js from NodeSource repository
# We extract the version from .nvmrc
COPY .nvmrc /nvmrc
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates
RUN <<EOF
# Extract major version (e.g., "18" from "18.x.x")
NODE_MAJOR=$(cat /nvmrc | cut -d. -f1 | tr -d 'v\n')
# Add NodeSource repository and its signing key
curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash -
# Install the specific version listed in the nvmrc file
NODE_VERSION=$(cat /nvmrc | tr -d 'v\n')
apt-get install -y --no-install-recommends nodejs=${NODE_VERSION}-1nodesource1
EOF
RUN groupadd --system --gid 1001 nodejs
RUN useradd --system --uid 1001 --gid nodejs nextjs
COPY --from=build --chown=nextjs:nodejs /tmp/deploy/ /app/
WORKDIR /app
RUN cp /app/.next/standalone/server.js .
USER nextjs
EXPOSE 6791
ENV PORT=6791
ENV HOSTNAME=0.0.0.0
CMD ["node", "./server.js"]