-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
50 lines (36 loc) · 1.27 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
# Install the app dependencies in a full Node docker image
FROM registry.access.redhat.com/ubi9/nodejs-20:latest
# Set the environment variables
ARG NEXT_PUBLIC_SERVER_URL
ENV NEXT_PUBLIC_SERVER_URL=${NEXT_PUBLIC_SERVER_URL}
ARG NEXT_PUBLIC_IN_PRODUCTION
ENV NEXT_PUBLIC_IN_PRODUCTION=${NEXT_PUBLIC_IN_PRODUCTION}
ARG NEXT_PUBLIC_KLAMM_URL
ENV NEXT_PUBLIC_KLAMM_URL=$NEXT_PUBLIC_KLAMM_URL
# Create a non-root user and group named 'node'
USER root
RUN groupadd -r node && useradd -r -g node -s /bin/bash -m node
# Set the working directory
WORKDIR /opt/app-root/src
# Copy package.json, and optionally package-lock.json if it exists
COPY package.json package-lock.json* ./
# Adjust permissions for the package files
RUN chown -R node:node /opt/app-root/src
# Switch to the node user
USER node
# Clear npm cache
RUN npm cache clean --force
# Install app dependencies
RUN npm ci --no-strict-ssl --no-shrinkwrap --verbose || npm install --prefer-online --verbose
# Switch back to root user to copy the application code
USER root
# Copy the application code
COPY . ./
# Adjust permissions for the application code
RUN chown -R node:node /opt/app-root/src
# Switch back to the node user
USER node
# Build the Next.js application
RUN npm run build
# Start the application
CMD ["npm", "start"]