Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update 优化 Dockerfile layer #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions Dockerfile
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在构建 1.12.0 已经不行,会报以下的报错
yarn run v1.22.19 $ NODE_ENV=production ykit pack -m (node:134) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency (Use node --trace-warnings ...` to show where the warning was created)
(node:134) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'find' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'head' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'set' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'test' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'to' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'which' of module exports inside circular dependency
[error] .//recharts/lib/polyfill.js
Module not found: Error: Cannot resolve module 'core-js/es/math' in /yapi/vendors/node_modules/recharts/lib
@ ./
/recharts/lib/polyfill.js 3:0-26

[error] .//recharts/lib/polyfill.js
Module not found: Error: Cannot resolve module 'core-js/es/number' in /yapi/vendors/node_modules/recharts/lib
@ ./
/recharts/lib/polyfill.js 5:0-28

[error] ../config.json
Module build failed: SyntaxError: Unexpected token m in JSON at position 0
at JSON.parse ()
at Object.module.exports (/yapi/vendors/node_modules/json-loader/index.js:4:49)
@ ./server/yapi.js 12:13-41

[error] .//fs-extra/lib/empty/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/fs-extra/lib/empty
@ ./
/fs-extra/lib/empty/index.js 4:11-24

[error] .//nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'net' in /yapi/vendors/node_modules/nodemailer/lib/mailer
@ ./
/nodemailer/lib/mailer/index.js 13:12-26

[error] .//nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'dns' in /yapi/vendors/node_modules/nodemailer/lib/mailer
@ ./
/nodemailer/lib/mailer/index.js 14:12-26

[error] .//nodemailer/lib/shared/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/nodemailer/lib/shared
@ ./
/nodemailer/lib/shared/index.js 5:11-24

[error] .//nodemailer/lib/sendmail-transport/index.js
Module not found: Error: Cannot resolve module 'child_process' in /yapi/vendors/node_modules/nodemailer/lib/sendmail-transport
@ ./
/nodemailer/lib/sendmail-transport/index.js 3:14-38

[error] .//nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'net' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/http-proxy-client.js 7:12-26

[error] .//nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'net' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/index.js 5:12-26

[error] .//nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'tls' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/http-proxy-client.js 8:12-26

[error] .//nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'tls' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/index.js 6:12-26

[error] .//nodemailer/lib/dkim/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/nodemailer/lib/dkim
@ ./
/nodemailer/lib/dkim/index.js 10:11-24

[error] .//graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/graceful-fs
@ ./
/graceful-fs/graceful-fs.js 1:9-22

[error] .//nodemailer/lib/mime-node/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/nodemailer/lib/mime-node
@ ./
/nodemailer/lib/mime-node/index.js 7:11-24

[error] .//jsonfile/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/jsonfile
@ ./
/jsonfile/index.js 5:8-21

[error] index@5e1419cd3b8ee11ed4be.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [../~/fs-extra/lib/util/assign.js:5,0]

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn && node /yapi/scripts/clean.js $(pwd) && yarn build-client && node /yapi/scripts/clean.js $(pwd) && rm -rf /yapi/scripts' returned a non-zero code: 1`

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在构建 1.12.0 已经不行,会报以下的报错
yarn run v1.22.19 $ NODE_ENV=production ykit pack -m (node:134) Warning: Accessing non-existent property 'cat' of module exports inside circular dependency (Use node --trace-warnings ...` to show where the warning was created)
(node:134) Warning: Accessing non-existent property 'cd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'chmod' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'cp' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'dirs' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'pushd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'popd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'echo' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'tempdir' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'pwd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'exec' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'ls' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'find' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'grep' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'head' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'ln' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'mkdir' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'rm' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'mv' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'sed' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'set' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'sort' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'tail' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'test' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'to' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'toEnd' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'touch' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'uniq' of module exports inside circular dependency
(node:134) Warning: Accessing non-existent property 'which' of module exports inside circular dependency
[error] .//recharts/lib/polyfill.js
Module not found: Error: Cannot resolve module 'core-js/es/math' in /yapi/vendors/node_modules/recharts/lib
@ ./
/recharts/lib/polyfill.js 3:0-26

[error] .//recharts/lib/polyfill.js
Module not found: Error: Cannot resolve module 'core-js/es/number' in /yapi/vendors/node_modules/recharts/lib
@ ./
/recharts/lib/polyfill.js 5:0-28

[error] ../config.json
Module build failed: SyntaxError: Unexpected token m in JSON at position 0
at JSON.parse ()
at Object.module.exports (/yapi/vendors/node_modules/json-loader/index.js:4:49)
@ ./server/yapi.js 12:13-41

[error] .//fs-extra/lib/empty/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/fs-extra/lib/empty
@ ./
/fs-extra/lib/empty/index.js 4:11-24

[error] .//nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'net' in /yapi/vendors/node_modules/nodemailer/lib/mailer
@ ./
/nodemailer/lib/mailer/index.js 13:12-26

[error] .//nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'dns' in /yapi/vendors/node_modules/nodemailer/lib/mailer
@ ./
/nodemailer/lib/mailer/index.js 14:12-26

[error] .//nodemailer/lib/shared/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/nodemailer/lib/shared
@ ./
/nodemailer/lib/shared/index.js 5:11-24

[error] .//nodemailer/lib/sendmail-transport/index.js
Module not found: Error: Cannot resolve module 'child_process' in /yapi/vendors/node_modules/nodemailer/lib/sendmail-transport
@ ./
/nodemailer/lib/sendmail-transport/index.js 3:14-38

[error] .//nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'net' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/http-proxy-client.js 7:12-26

[error] .//nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'net' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/index.js 5:12-26

[error] .//nodemailer/lib/smtp-connection/http-proxy-client.js
Module not found: Error: Cannot resolve module 'tls' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/http-proxy-client.js 8:12-26

[error] .//nodemailer/lib/smtp-connection/index.js
Module not found: Error: Cannot resolve module 'tls' in /yapi/vendors/node_modules/nodemailer/lib/smtp-connection
@ ./
/nodemailer/lib/smtp-connection/index.js 6:12-26

[error] .//nodemailer/lib/dkim/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/nodemailer/lib/dkim
@ ./
/nodemailer/lib/dkim/index.js 10:11-24

[error] .//graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/graceful-fs
@ ./
/graceful-fs/graceful-fs.js 1:9-22

[error] .//nodemailer/lib/mime-node/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/nodemailer/lib/mime-node
@ ./
/nodemailer/lib/mime-node/index.js 7:11-24

[error] .//jsonfile/index.js
Module not found: Error: Cannot resolve module 'fs' in /yapi/vendors/node_modules/jsonfile
@ ./
/jsonfile/index.js 5:8-21

[error] index@5e1419cd3b8ee11ed4be.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [../~/fs-extra/lib/util/assign.js:5,0]

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn && node /yapi/scripts/clean.js $(pwd) && yarn build-client && node /yapi/scripts/clean.js $(pwd) && rm -rf /yapi/scripts' returned a non-zero code: 1`

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
######## 构建 ########
FROM --platform=${BUILDPLATFORM:-amd64} node:12.16.3-alpine3.11 as builder
FROM --platform=${BUILDPLATFORM:-amd64} node:lts-alpine3.16 as builder

# 安装构建工具
RUN apk add --update --no-cache ca-certificates curl wget cmake build-base git bash python make gcc g++ zlib-dev autoconf automake file nasm \
&& update-ca-certificates
RUN apk add --update --no-cache build-base git bash

# YApi 版本
ENV YAPI_VERSION=1.10.2
Expand All @@ -22,30 +21,20 @@ RUN git clone \
--depth 1 \
https://github.com/YMFE/yapi.git .

# 拷贝启动脚本
RUN cp /yapi/scripts/start.js ./start.js
# 拷贝启动脚本、执行一些准备工作
RUN cp /yapi/scripts/start.js ./start.js \
&& node /yapi/scripts/prepare.js $(pwd)

# 执行一些准备工作
RUN node /yapi/scripts/prepare.js $(pwd)

# 安装依赖
RUN yarn

# 清理文件
RUN node /yapi/scripts/clean.js $(pwd)

# 构建应用
RUN yarn build-client

# 再次清理以删除构建缓存文件
RUN node /yapi/scripts/clean.js $(pwd)

# 删除脚本
RUN rm -rf /yapi/scripts
# 安装依赖、清理文件、构建应用、清理文件、删除脚本
RUN yarn \
&& node /yapi/scripts/clean.js $(pwd) \
&& yarn build-client \
&& node /yapi/scripts/clean.js $(pwd) \
&& rm -rf /yapi/scripts


######## 镜像 ########
FROM node:12.16.3-alpine3.11
FROM node:lts-alpine3.16

WORKDIR /yapi

Expand Down