Skip to content

Containerize fronted component #392 #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: notebooks-v2
Choose a base branch
from

Conversation

Noa-limoy
Copy link

@Noa-limoy Noa-limoy commented May 29, 2025

closes #392

I've created a Dockerfile for the frontend component, which allows for containerization of the frontend application. Currently, the frontend can only be run locally via the command line.
now we can run the frontend as a k8s workload resource, and its separate from the backend container.

Build the frontend image:

docker build -f Dockerfile -t nv2-frontend-dev .

The container image runs correctly and provides the same functionality as running the frontend locally:

docker run -it --rm -p 9001:9000 -v $(pwd):/usr/src/app nv2-frontend-dev

@github-project-automation github-project-automation bot moved this to Needs Triage in Kubeflow Notebooks May 29, 2025
@Noa-limoy Noa-limoy changed the base branch from main to notebooks-v2 May 29, 2025 12:43
@google-oss-prow google-oss-prow bot added size/M and removed size/XXL labels May 29, 2025
Copy link

@andyatmiami andyatmiami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general - I think we want to approach the Dockerfile more geared to a production build of the frontend.

  • ⚠️ We should verify this with the community - so please only take this as a discussion point for now!

By "production build" - I mean making sure the image is built deterministically and focused on being as small as possible.

  • npm ci
  • only install required dependencies
  • NODE_ENV=production
  • using multi-stage built to not leak dev/optional dependencies into image

Here is a rough outline of how I could see this Dockerfile structured given the above (but just use this is a discussion point for time being)

# Build stage
FROM node:20-slim AS builder

# Set working directory
WORKDIR /usr/src/app

# Copy package files
COPY package*.json ./

# Install ALL dependencies (including devDependencies)
RUN npm ci

# Copy source code
COPY . .

# Build the application
RUN npm run build

# Production stage
FROM node:20-slim

# Set working directory
WORKDIR /usr/src/app

# Copy package files from builder stage
COPY --from=builder /usr/src/app/package*.json ./

# Install only production dependencies
RUN npm ci --only=production

# Copy built assets from builder stage
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/public ./public

# Create non-root user
RUN addgroup --system appgroup && \
    adduser --system appuser --ingroup appgroup && \
    chown -R appuser:appgroup /usr/src/app

# Switch to non-root user
USER appuser

# Expose the development port (matching webpack dev server)
EXPOSE 8080

# Set environment variables
ENV NODE_ENV=production
ENV PORT=8080

# Start the production server
CMD ["npm", "run", "start:prod"]

Copy link

@andyatmiami: changing LGTM is restricted to collaborators

In response to this:

In general - I think we want to approach the Dockerfile more geared to a production build of the frontend.

  • ⚠️ We should verify this with the community - so please only take this as a discussion point for now!

By "production build" - I mean making sure the image is built deterministically and focused on being as small as possible.

  • npm ci
  • only install required dependencies
  • NODE_ENV=production
  • using multi-stage built to not leak dev/optional dependencies into image

Here is a rough outline of how I could see this Dockerfile structured given the above (but just use this is a discussion point for time being)

# Build stage
FROM node:20-slim AS builder

# Set working directory
WORKDIR /usr/src/app

# Copy package files
COPY package*.json ./

# Install ALL dependencies (including devDependencies)
RUN npm ci

# Copy source code
COPY . .

# Build the application
RUN npm run build

# Production stage
FROM node:20-slim

# Set working directory
WORKDIR /usr/src/app

# Copy package files from builder stage
COPY --from=builder /usr/src/app/package*.json ./

# Install only production dependencies
RUN npm ci --only=production

# Copy built assets from builder stage
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/public ./public

# Create non-root user
RUN addgroup --system appgroup && \
   adduser --system appuser --ingroup appgroup && \
   chown -R appuser:appgroup /usr/src/app

# Switch to non-root user
USER appuser

# Expose the development port (matching webpack dev server)
EXPOSE 8080

# Set environment variables
ENV NODE_ENV=production
ENV PORT=8080

# Start the production server
CMD ["npm", "run", "start:prod"]

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Comment on lines +16 to +18
# Use a non-root user for security
RUN addgroup --system appgroup && adduser --system appuser --ingroup appgroup
USER appuser
Copy link

@andyatmiami andyatmiami May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not implying anything wrong with this RUN statement to define a non-root user - but we should definitely align how we do this across controller + backend + frontend for sake of consistency.

Right now, backend + controller simply use hard-coded value of USER 65532:65532

(fwiw - I like this solution better - but def want consensus from the community at large!)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I used the following method beacuse this approach is a bit more explicit and readable.
but I totally agree with you that consistency across the project definitely matters.
I’ll change it..

@Noa-limoy Noa-limoy force-pushed the feat/containerize_fronted_component/392 branch from c633d23 to 89a691b Compare June 9, 2025 15:35
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ederign for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

[TASK] Containerize frontend component
2 participants