mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 01:01:38 +00:00
Update dockerfile
This commit is contained in:
3
.npmrc
Normal file
3
.npmrc
Normal file
@ -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"
|
31
Dockerfile
31
Dockerfile
@ -2,15 +2,13 @@
|
|||||||
FROM node:lts-alpine AS deps
|
FROM node:lts-alpine AS deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
# 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 \
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
||||||
&& apk add --no-cache libc6-compat \
|
&& apk add --no-cache libc6-compat python3 g++ make \
|
||||||
&& 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_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
|
|
||||||
|
|
||||||
# Install dependencies based on the preferred package manager
|
# 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 \
|
RUN \
|
||||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
||||||
elif [ -f package-lock.json ]; then npm ci; \
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
@ -18,25 +16,19 @@ RUN \
|
|||||||
else echo "Lockfile not found." && exit 1; \
|
else echo "Lockfile not found." && exit 1; \
|
||||||
fi
|
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
|
# Rebuild the source code only when needed
|
||||||
FROM node:lts-alpine AS builder
|
FROM node:lts-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN apk update --no-cache \
|
#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
||||||
&& apk upgrade --no-cache \
|
# && apk update --no-cache \
|
||||||
&& yarn config set registry https://registry.npmmirror.com
|
# && apk upgrade --no-cache
|
||||||
# && yarn build && yarn install --production --ignore-scripts --prefer-offline
|
|
||||||
|
|
||||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
RUN yarn build
|
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
|
||||||
|
|
||||||
@ -44,7 +36,8 @@ RUN yarn build
|
|||||||
FROM alpine AS runner
|
FROM alpine AS runner
|
||||||
WORKDIR /app
|
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 upgrade --no-cache \
|
||||||
&& apk add nodejs --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/.env ./
|
||||||
COPY --from=builder /app/public ./public
|
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
|
# 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/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
@ -70,4 +63,4 @@ EXPOSE 3000
|
|||||||
|
|
||||||
ENV PORT 3000
|
ENV PORT 3000
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
@ -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
|
|
@ -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
|
|
||||||
|
|
@ -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"]
|
|
@ -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;
|
|
||||||
#}
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
Reference in New Issue
Block a user