mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Upgrade dockerfile
This commit is contained in:
28
Dockerfile
28
Dockerfile
@ -8,8 +8,15 @@ RUN apk update --no-cache \
|
|||||||
&& yarn config set registry https://registry.npmmirror.com \
|
&& yarn config set registry https://registry.npmmirror.com \
|
||||||
&& yarn config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" \
|
&& yarn config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" \
|
||||||
&& yarn config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
|
&& 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
|
# If using npm with a `package-lock.json` comment out above and use below instead
|
||||||
# COPY package.json package-lock.json ./
|
# COPY package.json package-lock.json ./
|
||||||
@ -22,18 +29,25 @@ COPY --from=deps /app/node_modules ./node_modules
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN apk update --no-cache \
|
RUN apk update --no-cache \
|
||||||
&& apk upgrade --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 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
|
# If using npm comment out above and use below instead
|
||||||
# RUN npm run build
|
# RUN npm run build
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
# Production image, copy all the files and run next
|
||||||
FROM node:lts-alpine AS runner
|
FROM alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN apk update --no-cache \
|
||||||
|
&& apk upgrade --no-cache \
|
||||||
|
&& apk add nodejs --no-cache
|
||||||
|
|
||||||
ENV NODE_ENV production
|
ENV NODE_ENV production
|
||||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
# 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
|
# 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/.env ./
|
||||||
COPY --from=builder /app/next.config.mjs ./
|
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
# COPY --from=builder /app/package.json ./package.json
|
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
# Automatically leverage output traces to reduce image size
|
||||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
@ -58,4 +70,4 @@ EXPOSE 3000
|
|||||||
|
|
||||||
ENV PORT 3000
|
ENV PORT 3000
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
@ -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 registry https://registry.npmmirror.com \
|
||||||
&& yarn config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" \
|
&& yarn config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" \
|
||||||
&& yarn config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
|
&& 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
|
# If using npm with a `package-lock.json` comment out above and use below instead
|
||||||
# COPY package.json package-lock.json ./
|
# 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 \
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
||||||
&& apk update --no-cache \
|
&& apk update --no-cache \
|
||||||
&& apk upgrade --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 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
|
# 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
|
# 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/.env ./
|
||||||
COPY --from=builder /app/next.config.mjs ./
|
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
# COPY --from=builder /app/package.json ./package.json
|
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
# Automatically leverage output traces to reduce image size
|
||||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
|
Reference in New Issue
Block a user