Upgrade dockerfile

Update length calculate
This commit is contained in:
DefectingCat
2022-11-23 14:16:27 +08:00
parent f40b079b4f
commit 3305129b89
3 changed files with 42 additions and 19 deletions

View File

@ -8,8 +8,15 @@ RUN apk update --no-cache \
&& yarn config set registry https://registry.npmmirror.com \
&& yarn config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" \
&& yarn config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# 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 echo "Lockfile not found." && exit 1; \
fi
# If using npm with a `package-lock.json` comment out above and use below instead
# COPY package.json package-lock.json ./
@ -22,18 +29,25 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN apk update --no-cache \
&& apk upgrade --no-cache \
&& yarn config set registry https://registry.npmmirror.com \
&& yarn config set registry https://registry.npmmirror.com
# && yarn build && yarn install --production --ignore-scripts --prefer-offline
&& yarn build
# 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 node:lts-alpine AS runner
FROM alpine AS runner
WORKDIR /app
RUN apk update --no-cache \
&& apk upgrade --no-cache \
&& apk add nodejs --no-cache
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
@ -43,9 +57,7 @@ RUN adduser --system --uid 1001 nextjs
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/.env ./
COPY --from=builder /app/next.config.mjs ./
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

View File

@ -9,8 +9,15 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
&& yarn config set registry https://registry.npmmirror.com \
&& yarn config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" \
&& yarn config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# 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 echo "Lockfile not found." && exit 1; \
fi
# If using npm with a `package-lock.json` comment out above and use below instead
# COPY package.json package-lock.json ./
@ -24,9 +31,13 @@ COPY . .
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update --no-cache \
&& apk upgrade --no-cache \
&& yarn config set registry https://registry.npmmirror.com \
&& yarn config set registry https://registry.npmmirror.com
# && yarn build && yarn install --production --ignore-scripts --prefer-offline
&& yarn build
# && yarn build
# 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
@ -45,9 +56,7 @@ RUN adduser --system --uid 1001 nextjs
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/.env ./
COPY --from=builder /app/next.config.mjs ./
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

View File

@ -61,10 +61,12 @@ export const getStaticProps: GetStaticProps<{
const post = await readSinglePost(slug);
const toc = generateToc(post);
let tocLength = toc.length;
toc.forEach(
(item) => item.children.length && (tocLength += item.children.length)
);
const calcLength = (prev: number, cur: SingleToc) => {
const childLen = cur.children.length;
return childLen ? prev + childLen + 1 : prev + 1;
};
const tocLength = toc.reduce(calcLength, 0);
const mdxSource = await serialize(post, {
mdxOptions: {