From cebf947b028ed7657e939da8b978f079b4e5453f Mon Sep 17 00:00:00 2001 From: DefectingCat Date: Thu, 16 Feb 2023 17:42:43 +0800 Subject: [PATCH] Update dockerfile --- .npmrc | 3 ++ Dockerfile | 31 ++++++-------- docker/Dockerfile.export | 30 ------------- docker/Dockerfile.export-mirror | 35 ---------------- docker/Dockerfile.mirror | 72 -------------------------------- docker/nginx/conf.d/default.conf | 51 ---------------------- docker/nginx/nginx.conf | 32 -------------- 7 files changed, 15 insertions(+), 239 deletions(-) create mode 100644 .npmrc delete mode 100644 docker/Dockerfile.export delete mode 100644 docker/Dockerfile.export-mirror delete mode 100644 docker/Dockerfile.mirror delete mode 100644 docker/nginx/conf.d/default.conf delete mode 100644 docker/nginx/nginx.conf diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..9be5a71 --- /dev/null +++ b/.npmrc @@ -0,0 +1,3 @@ +registry = "https://registry.npmmirror.com/" +sharp_binary_host = "https://npmmirror.com/mirrors/sharp" \ +sharp_libvips_binary_host = "https://npmmirror.com/mirrors/sharp-libvips" diff --git a/Dockerfile b/Dockerfile index 86f77bf..8bf85c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,13 @@ FROM node:lts-alpine AS deps WORKDIR /app # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk update --no-cache \ - && apk upgrade --no-cache \ - && apk add --no-cache libc6-compat \ - && 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" + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ + && apk add --no-cache libc6-compat python3 g++ make \ + && yarn config set registry https://registry.npmmirror.com # Install dependencies based on the preferred package manager -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +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; \ @@ -18,25 +16,19 @@ RUN \ 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 ./ -# RUN npm ci - # Rebuild the source code only when needed FROM node:lts-alpine AS builder WORKDIR /app 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 build && yarn install --production --ignore-scripts --prefer-offline +#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ +# && apk update --no-cache \ +# && apk upgrade --no-cache # 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 @@ -44,7 +36,8 @@ RUN yarn build FROM alpine AS runner WORKDIR /app -RUN apk update --no-cache \ +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ + && apk update --no-cache \ && apk upgrade --no-cache \ && apk add nodejs --no-cache @@ -59,7 +52,7 @@ RUN adduser --system --uid 1001 nextjs COPY --from=builder /app/.env ./ COPY --from=builder /app/public ./public -# 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 COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static @@ -70,4 +63,4 @@ EXPOSE 3000 ENV PORT 3000 -CMD ["node", "server.js"] \ No newline at end of file +CMD ["node", "server.js"] diff --git a/docker/Dockerfile.export b/docker/Dockerfile.export deleted file mode 100644 index c4863d0..0000000 --- a/docker/Dockerfile.export +++ /dev/null @@ -1,30 +0,0 @@ - -# Install dependencies only when needed -FROM node:lts-alpine AS deps -WORKDIR /app -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk update --no-cache \ - && apk upgrade --no-cache \ - && apk add --no-cache libc6-compat \ - && 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 - -# Rebuild the source code only when needed -FROM node:lts-alpine AS builder -WORKDIR /app -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 build && yarn install --production --ignore-scripts --prefer-offline - && yarn build:export - -FROM nginx:alpine -WORKDIR /app -COPY --from=builder /app/docker/nginx/nginx.conf /etc/nginx/ -COPY --from=builder /app/docker/nginx/conf.d/default.conf /etc/nginx/conf.d/ -COPY --from=builder /app/out /usr/share/nginx/html diff --git a/docker/Dockerfile.export-mirror b/docker/Dockerfile.export-mirror deleted file mode 100644 index 9b035f4..0000000 --- a/docker/Dockerfile.export-mirror +++ /dev/null @@ -1,35 +0,0 @@ - -# Install dependencies only when needed -FROM node:lts-alpine AS deps -WORKDIR /app -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. - -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ - && apk update --no-cache \ - && apk upgrade --no-cache \ - && apk add --no-cache libc6-compat \ - && 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 - -# Rebuild the source code only when needed -FROM node:lts-alpine AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -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 build && yarn install --production --ignore-scripts --prefer-offline - && yarn build:export - -FROM nginx:alpine -WORKDIR /app -COPY --from=builder /app/docker/nginx/nginx.conf /etc/nginx/ -COPY --from=builder /app/docker/nginx/conf.d/default.conf /etc/nginx/conf.d/ -COPY --from=builder /app/out /usr/share/nginx/html - diff --git a/docker/Dockerfile.mirror b/docker/Dockerfile.mirror deleted file mode 100644 index 4030ec0..0000000 --- a/docker/Dockerfile.mirror +++ /dev/null @@ -1,72 +0,0 @@ -# Install dependencies only when needed -FROM node:lts-alpine AS deps -WORKDIR /app -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ - && apk update --no-cache \ - && apk upgrade --no-cache \ - && apk add --no-cache libc6-compat \ - && 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" - -# 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 ./ -# RUN npm ci - -# Rebuild the source code only when needed -FROM node:lts-alpine AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -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 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 -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 - -# 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/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 - -EXPOSE 3000 - -ENV PORT 3000 - -CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker/nginx/conf.d/default.conf b/docker/nginx/conf.d/default.conf deleted file mode 100644 index ec6abb6..0000000 --- a/docker/nginx/conf.d/default.conf +++ /dev/null @@ -1,51 +0,0 @@ -server { - listen 80; - listen [::]:80; - server_name localhost; - - # Client side render - location / { - root /usr/share/nginx/html; - try_files $uri $uri/ =404; - } - - #access_log /var/log/nginx/host.access.log main; - - # location / { - # root /usr/share/nginx/html; - # index index.html index.htm; - # } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - # error_page 500 502 503 504 /50x.html; - # location = /50x.html { - # root /usr/share/nginx/html; - # } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} -} - diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf deleted file mode 100644 index 5e076aa..0000000 --- a/docker/nginx/nginx.conf +++ /dev/null @@ -1,32 +0,0 @@ - -user nginx; -worker_processes auto; - -error_log /var/log/nginx/error.log notice; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - include /etc/nginx/conf.d/*.conf; -}