From 600b202c5e348ef1ffaa8725f86410beccdeb6b0 Mon Sep 17 00:00:00 2001 From: luo jiyin Date: Fri, 3 Jan 2025 16:04:19 +0800 Subject: [PATCH] fix render.com return 502 (#223) --- Dockerfile | 73 ++++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index a93648d..a2dcf1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,57 +1,26 @@ -# Install dependencies only when needed -FROM node:lts-alpine AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat curl +FROM node:20-slim AS base +RUN apt-get update && \ + apt-get install ca-certificates curl libjemalloc-dev -y --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* +# set environment variable to preload JEMalloc +ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libjemalloc.so.2" +# set GC time, set arenas number, set background_thread run GC +ENV MALLOC_CONF=dirty_decay_ms:1000,narenas:2,background_thread:true +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable +COPY . /app WORKDIR /app -# Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc ./ -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; \ - else echo "Lockfile not found." && exit 1; \ - fi - - -# Rebuild the source code only when needed -FROM node:lts-alpine 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 CI=true 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 node:lts-alpine AS runner -WORKDIR /app - -ENV NODE_ENV=production -# Uncomment the following line in case you want to disable telemetry during runtime. -# ENV NEXT_TELEMETRY_DISABLED 1 - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs - -COPY --from=builder /app/public ./public - -# Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static - -USER nextjs +FROM base AS build +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm i --frozen-lockfile +RUN CI=true pnpm build +FROM base +COPY --from=build /app/.next/standalone ./ +COPY --from=build /app/public ./public +COPY --from=build /app/.next/static ./.next/static EXPOSE 3000 - ENV PORT=3000 - -CMD ["node", "server.js"] +ENV HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] \ No newline at end of file