添加各个节点的镜像制作

This commit is contained in:
陈景阳
2019-08-15 08:08:16 +08:00
parent 7586964406
commit 86b547803f
13 changed files with 127 additions and 1 deletions

7
examples/README.md Normal file
View File

@@ -0,0 +1,7 @@
# Examples
* frontend 前端镜像制作
* master Master节点镜像制作
* worker Worker节点镜像制作
* run_docker_master.sh 运行Master节点示例脚本
* run_docker_worker.sh 运行Worker节点示例脚本

View File

@@ -0,0 +1,20 @@
FROM alpine:latest
# 安装nginx
RUN mkdir /run/nginx && apk add nginx
# 拷贝编译文件
COPY dist /app/dist
# 拷贝nginx代理文件
COPY crawlab.conf /etc/nginx/conf.d
# 拷贝执行脚本
COPY docker_init.sh /app/docker_init.sh
# 定义后端API脚本
ENV CRAWLAB_API_ADDRESS http://localhost:8000
EXPOSE 8080
CMD ["/bin/sh", "/app/docker_init.sh"]

View File

@@ -0,0 +1,3 @@
# 前端镜像制作
前端需要手动build拿到编译后的文件然后放入此目录进行镜像构建

View File

@@ -0,0 +1,13 @@
server {
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
#gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
listen 8080;
root /app/dist;
index index.html;
}

View File

@@ -0,0 +1,23 @@
#!/bin/sh
# replace default api path to new one
if [ "${CRAWLAB_API_ADDRESS}" = "" ];
then
:
else
jspath=`ls /app/dist/js/app.*.js`
sed -i "s?localhost:8000?${CRAWLAB_API_ADDRESS}?g" ${jspath}
fi
# replace base url
if [ "${CRAWLAB_BASE_URL}" = "" ];
then
:
else
indexpath=/app/dist/index.html
sed -i "s?/js/?${CRAWLAB_BASE_URL}/js/?g" ${indexpath}
sed -i "s?/css/?${CRAWLAB_BASE_URL}/css/?g" ${indexpath}
fi
# start nginx
nginx -g 'daemon off;'

View File

@@ -0,0 +1,20 @@
FROM alpine:latest
# 配置工作目录
WORKDIR /opt/crawlab
# 拷贝配置文件
COPY config.yml /opt/crawlab/conf/config.yml
# 拷贝可执行文件
COPY crawlab /usr/local/bin
# 创建spiders文件用于存放爬虫 授权可执行文件
RUN mkdir -p /opt/crawlab/spiders && chmod +x /usr/local/bin/crawlab
# 指定为Master节点
ENV CRAWLAB_SERVER_MASTER Y
EXPOSE 8000
CMD ["crawlab"]

View File

@@ -0,0 +1,8 @@
# Master 节点镜像制作
在Dockerfile里面的二进制包需要手动在源码目录下进行构建然后再放进来。
## Linux 二进制包构建
```
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o crawlab main.go
```

View File

@@ -0,0 +1,32 @@
api:
address: "localhost:8000"
mongo:
host: "192.168.235.26"
port: 27017
db: crawlab_local
username: "root"
password: "example"
authSource: "admin"
redis:
address: 192.168.235.0
password: redis-1.0
database: 29
port: 16379
log:
level: info
path: "/logs/crawlab"
server:
host: 0.0.0.0
port: 8000
master: "Y"
secret: "crawlab"
register:
# mac 或者 ip如果是ip则需要手动指定IP
type: "mac"
ip: "192.168.0.104"
spider:
path: "/spiders"
task:
workers: 4
other:
tmppath: "/tmp"

View File

@@ -1,4 +1,4 @@
# worker节点
# 本地开发环境worker节点制作
由于master和worker节点的存储信息是在redis上并且使用节点所在的mac地址作为key所以在开发本地需要启动master和worker节点会比较麻烦。
这里是一个运行worker节点的一个例子。