From b9e42074803f0cf4be257aa80bba625cf1154921 Mon Sep 17 00:00:00 2001 From: craigrbarnes Date: Sat, 30 Nov 2024 19:12:48 -0500 Subject: [PATCH] update image --- Dockerfile | 73 ++++++++++++++++++++++++-------------------------- next.config.js | 1 + 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index 47ea19f..6818aa1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,36 @@ # Build stage FROM node:20-alpine AS builder -ARG NODE_VERSION=20 - -ARG BASE_PATH -ARG NEXT_PUBLIC_PORTAL_BASENAME -ENV NPM_CONFIG_PREFIX=/home/node/.npm-global -ENV PATH=$PATH:/home/node/.npm-global/bin - WORKDIR /gen3 -# Install Python 3.11 -RUN apk add --no-cache python3 python3-dev py3-pip build-base linux-headers && ln -sf python3 /usr/bin/python +# Add build argument for basePath +ARG BASE_PATH="/ff" +ENV BASE_PATH=$BASE_PATH + +# Install Python and build dependencies +RUN apk add --no-cache python3 python3-dev py3-pip build-base linux-headers \ + && ln -sf python3 /usr/bin/python \ + && rm -rf /var/cache/apk/* -# Copy only the files needed for dependency installation +# Copy only package files first to leverage cache COPY package*.json ./ COPY ./jupyter-lite/requirements.txt ./jupyter-lite/requirements.txt -# Install dependencies -RUN npm ci -RUN npm install \ - "@swc/core" \ - "@napi-rs/magic-string" -RUN rm /usr/lib/python*/EXTERNALLY-MANAGED && \ - pip3 install -r ./jupyter-lite/requirements.txt - -# Copy source files -COPY ./package.json ./package-lock.json ./next.config.js /tsconfig.json ./tailwind.config.js ./postcss.config.js ./start.sh ./ -COPY ./src ./src -COPY ./public ./public -COPY ./config ./config -COPY ./jupyter-lite ./jupyter-lite - -# Build jupyter-lite and Next.js application -RUN jupyter lite build --contents ./jupyter-lite/contents/files --lite-dir ./jupyter-lite/contents --output-dir ./public/jupyter -RUN npm run build +# Combine npm installations and cleanup in single layer +RUN npm ci \ + && npm install "@swc/core" "@napi-rs/magic-string" \ + && rm -rf /root/.npm/* \ + && rm /usr/lib/python*/EXTERNALLY-MANAGED \ + && pip3 install -r ./jupyter-lite/requirements.txt \ + && rm -rf /root/.cache/pip/* + +# Copy only necessary source files +COPY . . + +# Build applications +RUN jupyter lite build --contents ./jupyter-lite/contents/files --lite-dir ./jupyter-lite/contents --output-dir ./public/jupyter \ + && npm run build \ + && rm -rf ./jupyter-lite/contents/files # Production stage FROM node:20-alpine AS runner @@ -42,20 +38,21 @@ FROM node:20-alpine AS runner WORKDIR /gen3 # Create non-root user -RUN addgroup --system --gid 1001 nodejs && \ - adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs \ + && adduser --system --uid 1001 nextjs # Set production environment -ENV NODE_ENV=production -ENV PORT=3000 +ENV NODE_ENV=production \ + PORT=3000 \ + BASE_PATH="/ff" -# Copy only necessary files from builder +# Copy only production necessary files COPY --from=builder --chown=nextjs:nodejs /gen3/.next ./.next -COPY --from=builder /gen3/node_modules ./node_modules -COPY --from=builder /gen3/package.json ./package.json -COPY --from=builder /gen3/public ./public -COPY --from=builder /gen3/config ./config -# Switch to non-root user +COPY --from=builder --chown=nextjs:nodejs /gen3/public ./public +COPY --from=builder --chown=nextjs:nodejs /gen3/package.json ./package.json +COPY --from=builder --chown=nextjs:nodejs /gen3/node_modules ./node_modules +COPY --from=builder --chown=nextjs:nodejs /gen3/config ./config + USER nextjs EXPOSE 3000 diff --git a/next.config.js b/next.config.js index bcbe804..02fd9c7 100644 --- a/next.config.js +++ b/next.config.js @@ -1,3 +1,4 @@ +/** @type {import('next').NextConfig} */ 'use strict'; // eslint-disable-next-line @typescript-eslint/no-var-requires