mirror of
https://github.com/pysunday/sdenv.git
synced 2025-04-05 01:03:51 +08:00
feat: 在docker中使用 #4
This commit is contained in:
parent
da840d4245
commit
b87cab8a21
15
Dockerfile.base
Normal file
15
Dockerfile.base
Normal file
@ -0,0 +1,15 @@
|
||||
FROM ubuntu:20.04
|
||||
MAINTAINER pysunday <https://howduudu.tech>
|
||||
|
||||
ENV LANG C.UTF-8
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
RUN apt-get update && apt-get install -y vim curl git software-properties-common \
|
||||
build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev pkg-config
|
||||
RUN add-apt-repository ppa:deadsnakes/ppa && apt-get update \
|
||||
&& apt-get install -y python3.12 python3-dev python3-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev \
|
||||
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 \
|
||||
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2
|
||||
RUN apt-get install -y nodejs npm && npm install -g n
|
||||
RUN n stable
|
||||
RUN npm install -g node-gyp
|
8
Dockerfile.example
Normal file
8
Dockerfile.example
Normal file
@ -0,0 +1,8 @@
|
||||
# FROM pysunday/sdenv_base:arm64
|
||||
# FROM pysunday/sdenv_base:x86_64
|
||||
|
||||
RUN git clone https://github.com/pysunday/sdenv.git
|
||||
WORKDIR /sdenv
|
||||
RUN npm i
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/node"]
|
45
README.md
45
README.md
@ -45,15 +45,56 @@ const { jsdomFromText, jsdomFromUrl, browser } = require('sdenv');
|
||||
|
||||
### 样例代码运行
|
||||
|
||||
clone项目仓库后执行依赖安装`npm i`,确保依赖安装成功后即可运行example目录下的样例文件了。
|
||||
|
||||
注意:样例代码仅供参考,作者建议使用npm包方式使用sdenv框架!
|
||||
|
||||
#### 源码方式
|
||||
|
||||
clone项目仓库后执行依赖安装`npm i`,确保依赖安装成功后即可运行example目录下的样例文件了。
|
||||
|
||||
1. 运行本地代码:[use-local](./example/use-local/README.md)
|
||||

|
||||
2. 运行网站代码:[use-remote](./example/use-remote/README.md)
|
||||

|
||||
|
||||
#### docker方式
|
||||
|
||||
提供docker方式运行样例代码.
|
||||
|
||||
首先执行`uname -a`后查看架构类型,支持`arm64`和`x86_64`
|
||||
|
||||
如果是`arm64`架构则执行命令:
|
||||
|
||||
1. 运行本地代码:`docker run --rm pysunday/sdenv:arm64 ./example/use-local/index.js`
|
||||
2. 运行网站代码:`docker run --rm pysunday/sdenv:arm64 ./example/use-remote/index.js`
|
||||
|
||||
如果是`x86_64`架构则执行命令:
|
||||
|
||||
1. 运行本地代码:`docker run --rm pysunday/sdenv:x86_64 ./example/use-local/index.js`
|
||||
2. 运行网站代码:`docker run --rm pysunday/sdenv:x86_64 ./example/use-remote/index.js`
|
||||
|
||||
### docker打包
|
||||
|
||||
可以参考项目的`Dockerfile.example`文件,通过命令`uname -a`查看架构类型,然后取消对应的`FROM`语句注释,修改文件名为`Dockerfile`,如arm64架构的Dockerfile文件内容:
|
||||
|
||||
```docker
|
||||
FROM pysunday/sdenv_base:arm64
|
||||
|
||||
RUN git clone https://github.com/pysunday/sdenv.git
|
||||
WORKDIR /sdenv
|
||||
RUN npm i
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/node"]
|
||||
```
|
||||
|
||||
最后执行命令`docker build -t pysunday/sdenv ./`生成容器
|
||||
|
||||
运行容器内的样例代码与前面类似:
|
||||
|
||||
1. 运行本地代码:`docker run --rm pysunday/sdenv ./example/use-local/index.js`
|
||||
2. 运行网站代码:`docker run --rm pysunday/sdenv ./example/use-remote/index.js`
|
||||
|
||||
**如果需要在docker内调试代码,作者建议使用npm包的方式使用sdenv,然后通过映射方式调用docker**
|
||||
|
||||
## API
|
||||
|
||||
sdenv设计极其简单,它的核心API只有一个,即browser!
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sdenv",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "补环境框架",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
@ -20,7 +20,7 @@
|
||||
"homepage": "https://github.com/pysunday/sdenv#readme",
|
||||
"bugs": "https://github.com/pysunday/sdenv/issues",
|
||||
"author": "pysunday",
|
||||
"license": "ISC",
|
||||
"license": "BSD 3-Clause",
|
||||
"dependencies": {
|
||||
"bindings": "^1.5.0",
|
||||
"canvas": "^2.11.2",
|
||||
|
Loading…
Reference in New Issue
Block a user