Skip to content

Commit df076f9

Browse files
authored
chore: nodejs docker template updated (#62)
* chore: reactjs, preactjs, vuejs dockerfile updated * chore: update build directory from build to dist * feat: nodejs dockerfile updated to node bullseye image with os package installation support
1 parent 7a525d1 commit df076f9

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

docker_config_generator/config.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,14 @@ templates:
215215
nodejs:
216216
name: nodejs.Dockerfile
217217
variables:
218-
PORT:
218+
SETUP_COMMAND:
219219
type: string
220-
description: Exposed Port [Ignore if not required]
221-
default: 80
220+
description: Setup and install dependencies
221+
default: npm install
222+
START_COMMAND:
223+
type: string
224+
description: Start command for nodejs application
225+
default: npm run start
222226
django-pip:
223227
name: django-pip.Dockerfile
224228
variables:
Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
# Install dependencies only when needed
2-
FROM node:lts-slim AS deps
1+
FROM node:18.18.0-bullseye
32
WORKDIR /app
4-
# Install dependencies based on the preferred package manager
5-
COPY package.json yarn.lock* package.json* 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. \nFallback : Running `npm install`" && npm install; \
11-
fi
123

13-
# Production image, copy all the files and run
14-
FROM node:lts-slim AS runner
4+
# Copy source code
5+
COPY . .
156

16-
ARG PORT="80"
17-
ARG START_COMMAND="npm run start"
7+
# Copy AptFile [optional]
8+
RUN test -f AptFile && apt update -yqq && xargs -a AptFile apt install -yqq || true
189

19-
WORKDIR /app
20-
ENV NODE_ENV production
21-
RUN addgroup --gid 1001 nodejs
22-
RUN adduser --disabled-password --gecos "" --uid 1001 --ingroup nodejs nodejs
23-
RUN chown nodejs:nodejs /app
24-
COPY . .
25-
COPY --from=deps /app/node_modules ./node_modules
10+
# Copy SetupCommand [optional]
11+
RUN test -f SetupCommand && while read -r cmd; do eval "$cmd"; done < SetupCommand || true
2612

27-
EXPOSE ${PORT}
28-
ENV PORT ${PORT}
13+
# Install dependencies
14+
ARG SETUP_COMMAND="npm install"
15+
RUN ${SETUP_COMMAND}
2916

17+
# Start the app
18+
ARG START_COMMAND="npm run start"
3019
RUN echo "${START_COMMAND}" > /app/entrypoint.sh
3120
RUN chmod +x /app/entrypoint.sh
32-
USER nodejs
3321

3422
ENTRYPOINT ["sh", "-c", "/app/entrypoint.sh"]

0 commit comments

Comments
 (0)