Skip to content

Commit 7a525d1

Browse files
authored
nextjs docker template update (#61)
* chore: reactjs, preactjs, vuejs dockerfile updated * chore: update build directory from build to dist * feat: nextjs docker template updated to bullseye and os support
1 parent 317dad7 commit 7a525d1

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

docker_config_generator/config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ templates:
204204
nextjs:
205205
name: nextjs.Dockerfile
206206
variables:
207+
SETUP_COMMAND:
208+
type: string
209+
description: Setup and install dependencies
210+
default: npm install
207211
BUILD_COMMAND:
208212
type: string
209213
description: Build command for nextjs
210214
default: npm run build
211-
PORT:
212-
type: string
213-
description: Port for nextjs
214-
default: 80
215215
nodejs:
216216
name: nodejs.Dockerfile
217217
variables:
Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,55 @@
1-
# Install dependencies only when needed
2-
FROM node:18.11-slim AS deps
3-
WORKDIR /app
4-
# Install dependencies based on the preferred package manager
5-
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
6-
RUN \
7-
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
8-
elif [ -f package-lock.json ]; then npm ci; \
9-
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
10-
else echo "Lockfile not found." && exit 1; \
11-
fi
12-
13-
# Rebuild the source code only when needed
141
FROM node:18.11-slim AS builder
2+
WORKDIR /app
153

16-
# Build args
17-
ARG BUILD_COMMAND="npm run build"
4+
# Copy AptFile [optional]
5+
COPY AptFile* ./
6+
RUN test -f AptFile && apt update -yqq && xargs -a AptFile apt install -yqq || true
187

19-
WORKDIR /app
8+
# Copy SetupCommand [optional]
9+
COPY SetupCommand* ./
10+
RUN test -f SetupCommand && while read -r cmd; do eval "$cmd"; done < SetupCommand || true
11+
12+
# Copy source code
2013
COPY . .
21-
COPY --from=deps /app/node_modules ./node_modules
14+
15+
# Install dependencies
16+
ARG SETUP_COMMAND="npm install"
17+
RUN ${SETUP_COMMAND}
18+
19+
# Prepare script
2220
RUN touch ./modify.js
2321
RUN echo 'let data = require("./next.config.js");' >> ./modify.js
2422
RUN echo 'data.output = "standalone";' >> ./modify.js
2523
RUN echo 'require("fs").writeFileSync("./next.config.js", `module.exports = ${JSON.stringify(data, null, 4)}`);' >> ./modify.js
2624
RUN node ./modify.js
2725
RUN rm ./modify.js
28-
ENV NODE_ENV production
29-
RUN ${BUILD_COMMAND} && npm prune --production
26+
27+
# Build nextjs app
28+
ARG BUILD_COMMAND="npm run build"
29+
RUN ${BUILD_COMMAND}
3030

3131
# Production image, copy all the files and run next
3232
FROM node:18.11-slim AS runner
3333

34-
# Build args
35-
ARG PORT="80"
34+
# Copy AptFile [optional]
35+
COPY AptFile* ./
36+
RUN test -f AptFile && apt update -yqq && xargs -a AptFile apt install -yqq || true
37+
38+
# Copy SetupCommand [optional]
39+
COPY SetupCommand* ./
40+
RUN test -f SetupCommand && while read -r cmd; do eval "$cmd"; done < SetupCommand || true
3641

3742
WORKDIR /app
38-
ENV NODE_ENV production
43+
3944
RUN addgroup --gid 1001 nodejs
4045
RUN adduser --disabled-password --gecos "" --uid 1001 --ingroup nodejs nextjs
4146
COPY --from=builder /app/next.config.js ./
4247
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
4348
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
4449

4550
USER nextjs
46-
EXPOSE ${PORT}
47-
ENV PORT ${PORT}
51+
52+
EXPOSE 80
53+
ENV PORT 80
54+
4855
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)