-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,24 @@ | ||
# Use Node.js 18 Alpine as the base image | ||
FROM node:18-alpine AS base | ||
FROM node:18-alpine | ||
|
||
# Install dependencies only when needed | ||
FROM base AS deps | ||
# Add libc6-compat for Alpine compatibility | ||
RUN apk add --no-cache libc6-compat | ||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy package files to set up dependencies | ||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ | ||
RUN \ | ||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ | ||
elif [ -f package-lock.json ]; then npm ci; \ | ||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ | ||
else echo "Lockfile not found." && exit 1; \ | ||
fi | ||
|
||
# Build the application | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
# Copy all files to the working directory | ||
COPY . . | ||
RUN npm run build | ||
|
||
ENV NODE_ENV production | ||
# Install dependencies | ||
RUN npm ci | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
USER nextjs | ||
# Build the application | ||
RUN npm run build | ||
|
||
EXPOSE 3004 | ||
# Expose the port the app runs on | ||
EXPOSE 3000 | ||
|
||
# Set environment variables | ||
ENV PORT 3000 | ||
ENV HOSTNAME "0.0.0.0" | ||
# Start the Next.js application | ||
CMD ["npm", "run", "start"] | ||
|
||
# Start the application | ||
CMD ["npm", "start"] |