Skip to content

Commit

Permalink
update image
Browse files Browse the repository at this point in the history
  • Loading branch information
craigrbarnes committed Dec 1, 2024
1 parent 75dd76b commit b9e4207
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
73 changes: 35 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
# 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

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
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @type {import('next').NextConfig} */
'use strict';

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down

0 comments on commit b9e4207

Please sign in to comment.