generated from uc-cdis/commons-frontend-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
63 lines (48 loc) · 1.71 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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
# Copy only the files needed for dependency installation
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
# 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
# Set production environment
ENV NODE_ENV=production
ENV PORT=3000
# Copy only necessary files from builder
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
USER nextjs
EXPOSE 3000
CMD ["npm", "start"]