init
This commit is contained in:
commit
fb6af905cd
30 files changed
+8653
No files matched your search
@@ -0,0 +1,103 @@
|
||||
# Next.js Optimized Dockerfile with Dynamic Build Args
|
||||
# Auto-generated for {{ app_name }}
|
||||
# Node.js Version: {{ node_version }}
|
||||
# Package Manager: {{ package_manager }}
|
||||
|
||||
# ============================================================================
|
||||
# Build arguments - Base Configuration
|
||||
# ============================================================================
|
||||
ARG NODE_VERSION={{ node_version }}
|
||||
ARG PACKAGE_MANAGER={{ package_manager }}
|
||||
ARG BUILD_COMMAND={{ build_command }}
|
||||
ARG START_COMMAND={{ start_command }}
|
||||
ARG APP_PORT={{ framework_settings_port }}
|
||||
ARG NODE_ENV=production
|
||||
ARG APP_VERSION={{ docker_image_tag }}
|
||||
ARG FRAMEWORK=nextjs
|
||||
|
||||
# ============================================================================
|
||||
# Base stage - Alpine for smaller size
|
||||
# ============================================================================
|
||||
FROM gitlab.forlife.one:5050/share/node:${NODE_VERSION}-alpine AS base
|
||||
|
||||
# Install dependencies
|
||||
RUN apk add --no-cache \
|
||||
libc6-compat \
|
||||
python3 \
|
||||
make \
|
||||
g++ curl
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies based on the preferred package manager
|
||||
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 yarn global add pnpm && pnpm i --frozen-lockfile; \
|
||||
else {{ package_manager }} install; \
|
||||
fi
|
||||
|
||||
#RUN {{ package_manager }} install
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Next.js collects completely anonymous telemetry data about general usage.
|
||||
# Learn more here: https://nextjs.org/telemetry
|
||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
RUN yarn build
|
||||
|
||||
# If using npm comment out above and use below instead
|
||||
# RUN npm run build
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS production
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||
# ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV NODE_OPTIONS="--max-old-space-size={{ MEMORY_LIMIT_MB }}"
|
||||
|
||||
|
||||
# Create health check script
|
||||
RUN echo '#!/bin/sh\n\
|
||||
status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${APP_PORT}/health)\n\
|
||||
if [ "$status" -eq 200 ] || [ "$status" -eq 404 ]; then exit 0; fi\n\
|
||||
\n\
|
||||
status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${APP_PORT}/)\n\
|
||||
if [ "$status" -eq 200 ] || [ "$status" -eq 404 ]; then exit 0; fi\n\
|
||||
\n\
|
||||
exit 1' > /health-check.sh && \
|
||||
chmod +x /health-check.sh
|
||||
|
||||
# You only need to copy next.config.js if you are NOT using the default configuration
|
||||
# COPY --from=builder /app/next.config.js ./
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder /app/.next/standalone ./
|
||||
COPY --from=builder /app/.next/static ./.next/static
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
ENV PORT=3000
|
||||
ENV APP_PORT=3000
|
||||
|
||||
# Health check
|
||||
#HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 CMD /health-check.sh
|
||||
|
||||
#CMD ["node", "server.js"]
|
||||
CMD {{ RUN_CMD }}
|
||||
Reference in new issue
Block a user