-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39a532c
commit f11825f
Showing
17 changed files
with
2,043 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules | ||
.dockerignore | ||
Dockerfile | ||
*-debug.log | ||
*-error.log | ||
.git | ||
.hg | ||
.svn | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module.exports = { | ||
// 解析器 | ||
parser: "@typescript-eslint/parser", // 把 TS 转换成 ESTree 兼容格式的解析器,这样就可以在 eslint 中使用了 | ||
|
||
// 拓展:用来继承已有的 ESLint 配置 | ||
extends: ["plugin:@typescript-eslint/recommended"], | ||
|
||
// 插件 | ||
plugins: ["@typescript-eslint"], | ||
|
||
// 环境:设置代码环境,eslint 能够自动识别对应环境所有的全局变量 | ||
env: { | ||
node: true, | ||
commonjs: true, | ||
amd: true, | ||
es6: true, | ||
}, | ||
|
||
/** | ||
* "off" 或 0 - 关闭规则 | ||
* "warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出), | ||
* "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出) | ||
*/ | ||
rules: { | ||
/* Possible Errors - 这些规则与 JavaScript 可能的错误或者逻辑错误有关 */ | ||
"no-dupe-args": 2, // 禁止 function 定义中出现重名参数 | ||
"no-dupe-keys": 2, // 禁止对象字面量中出现重复的 key | ||
"no-empty": 2, // 禁止出现空语句块 | ||
"no-func-assign": 2, // 禁止对 function 声明重新赋值 | ||
"no-irregular-whitespace": 2, // 禁止不规则的空白 | ||
"no-unreachable": 2, // 禁止在 return、throw、continue 和 break 语句之后出现不可达代码 | ||
|
||
/* Best Practices - 这些规则是关于最佳实践的,帮助避免一些问题 */ | ||
"eqeqeq": 2, // 要求使用 === 和 !== | ||
"curly": 2, // 强制所有控制语句使用一致的括号风格 | ||
|
||
/* Variables - 这些规则与变量有关 */ | ||
"no-delete-var": 2, // 禁止删除变量 | ||
"no-unused-vars": 2, // 进制出现未使用过的变量 | ||
|
||
/* Node.js and CommonJS - 关于 Node.js 相关的规则 */ | ||
"global-require": 2, // 要求 require() 出现在顶层模块作用域中 | ||
"handle-callback-err": 2, // 要求回调函数中有容错处理 | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"[markdown]": { | ||
"editor.quickSuggestions": { | ||
"other": true, | ||
"comments": false, | ||
"strings": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 官方文档 https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker | ||
# 基于 Alpine Linux 的最小 Docker 图像,具有完整的包索引,大小仅为 5 MB! | ||
FROM alpine:edge | ||
|
||
# 指定执行 CMD 的目录,即先 cd 到该目录上 | ||
WORKDIR /home/docker/we_render | ||
|
||
# 安装最新版 Chromium(89) 的包 | ||
RUN apk add --no-cache \ | ||
chromium \ | ||
nss \ | ||
freetype \ | ||
harfbuzz \ | ||
ca-certificates \ | ||
ttf-freefont \ | ||
nodejs \ | ||
yarn | ||
|
||
# 跳过自动安装 Chrome 包. 使用上面已经安装的 Chrome | ||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \ | ||
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser | ||
|
||
# Puppeteer v6.0.0 配套 Chromium 89 | ||
RUN yarn add [email protected] | ||
|
||
# 拷贝宿主机的文件到容器中的 we_render 目录 | ||
COPY . /home/docker/we_render | ||
|
||
# 通过 yarn 设置淘宝源和装包,并清除缓存 | ||
RUN yarn config set registry 'https://registry.npm.taobao.org' && \ | ||
yarn global add pm2 && \ | ||
yarn install && \ | ||
yarn cache clean | ||
|
||
# 声明容器提供的服务端口 | ||
EXPOSE 9527 | ||
|
||
# 容器主进程的启动命令 | ||
CMD ["yarn", "run", "robot"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Docker for Puppeteer | ||
=== | ||
|
||
> Create by **jsliang** on **2022-03-02 00:07:31** | ||
> Recently revised in **2022-03-02 00:07:31** | ||
## 一、开发环境 | ||
|
||
* 装包:`npm i` | ||
* 启动服务:`npm run robot-test` | ||
|
||
## 二、部署上线 | ||
|
||
* 创建镜像(Image):`docker image build ./ -t docker-node:1.0.0` | ||
* 创建容器(Container)且退出后容器直接删除:`docker run -it --rm docker-node:1.0.0` | ||
* 创建容器(Container):`docker container create -p 3333:80 docker-node:1.0.0` | ||
* 启动容器(Container):`docker container start dd420fc4267ad3bdb9eadfdbf37d89e2592dbc9d030a501b96fe10b07ac565ff` | ||
* 注:如果不能起来,则通过 `docker ps -a` 查看到 `CONTAINER ID`,再通过 `docker restart CONTAINER ID` 起服务 | ||
* 查看容器(Container)运行情况:`docker ps -a` | ||
* 查看容器(Container)的日志:`docker logs -f dd420fc4267a` | ||
* 进入容器(Container):`docker exec -it dd420fc4267a bash` | ||
* 查看 README.md 文件:`cat -n README.md` | ||
* 退出容器(Container):`exit` | ||
|
||
## 三、同步代码 | ||
|
||
* 将宿主机代码复制到容器: | ||
|
||
```shell | ||
docker cp "E:/MyWeb/036-Docker for Node/README.md" 8e1910aa2a12:/usr/src/app/README.md | ||
docker cp 宿主机的路径 容器名|容器 ID:容器中的文件路径 | ||
``` | ||
|
||
> 注 1:如果是 Windows,且目录包含空格的话,最好通过 `"路径"` 包裹 | ||
> 注 2:目录的话最好后退一层,例如 `docker cp E:/MyWeb/036-Docker for Node/src /usr/src/app/` | ||
> 注 3:`cp` 即 `copy`,拷贝的意思 | ||
* 将容器代码复制到宿主机: | ||
|
||
```shell | ||
docker cp 8e1910aa2a12:/usr/src/app/tsconfig.json E:\MyWeb\all-for-one | ||
docker cp 容器名 :容器中的文件路径 宿主机的路径 | ||
``` | ||
|
||
* 让容器代码实时同步宿主机代码: | ||
|
||
```shell | ||
docker run -d -v E:\MyWeb\all-for-one\src:/usr/src/app/src docker-node:1.0.0 | ||
docker run -d -v 容器中文件路径 :宿主机文件路径 容器名 :版本号 | ||
``` | ||
|
||
我们需要知道的是: | ||
|
||
1. `-d`:后台运行 | ||
2. `-v A:B`:将宿主机 A 路径的文件/文件夹挂载到容器 B 的路径上面(两者都是绝对路径) | ||
3. `docker-node:1.0.0`:即 `docker image ls` 查看到的 `REPOSITORY` 和 `TAG` | ||
|
||
--- | ||
|
||
**不折腾的前端,和咸鱼有什么区别!** | ||
|
||
觉得文章不错的小伙伴欢迎点赞/点 Star。 | ||
|
||
如果小伙伴需要联系 **jsliang**: | ||
|
||
* [Github](https://github.com/LiangJunrong/document-library) | ||
|
||
个人联系方式存放在 Github 首页,欢迎一起折腾~ | ||
|
||
争取打造自己成为一个充满探索欲,喜欢折腾,乐于扩展自己知识面的终身学习横杠程序员。 | ||
|
||
> jsliang 的文档库由 [梁峻荣](https://github.com/LiangJunrong) 采用 [知识共享 署名-非商业性使用-相同方式共享 4.0 国际 许可协议](http://creativecommons.org/licenses/by-nc-sa/4.0/) 进行许可。<br/>基于 [https://github.com/LiangJunrong/document-library](https://github.com/LiangJunrong/document-library) 上的作品创作。<br/>本许可协议授权之外的使用权限可以从 [https://creativecommons.org/licenses/by-nc-sa/2.5/cn/](https://creativecommons.org/licenses/by-nc-sa/2.5/cn/) 处获得。 |
Oops, something went wrong.