diff --git a/Jenkinsfile b/Jenkinsfile index b9f99723..1b448465 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,13 +11,20 @@ pipeline { echo "Running Setup..." script { if (env.GIT_BRANCH == 'develop') { - env.MODE = 'develop' env.TAG = 'develop' - env.BASE_URL = '/dev' + env.DOCKERFILE = 'Dockerfile.local' } else if (env.GIT_BRANCH == 'master') { - env.MODE = 'production' env.TAG = 'master' - env.BASE_URL = '/demo' + env.DOCKERFILE = 'Dockerfile.local' + } else if (env.GIT_BRANCH == 'frontend') { + env.TAG = 'frontend-alpine' + env.DOCKERFILE = 'frontend/Dockerfile.frontend.alpine' + } else if (env.GIT_BRANCH == 'backend-master') { + env.TAG = 'master-alpine' + env.DOCKERFILE = 'frontend/Dockerfile.master.alpine' + } else if (env.GIT_BRANCH == 'backend-worker') { + env.TAG = 'worker-alpine' + env.DOCKERFILE = 'frontend/Dockerfile.worker.alpine' } } } @@ -26,7 +33,7 @@ pipeline { steps { echo "Building..." sh """ - docker build -t tikazyq/crawlab:${ENV:TAG} -f Dockerfile.local . + docker build -t tikazyq/crawlab:${ENV:TAG} -f ${ENV.DOCKERFILE} . """ } } @@ -38,13 +45,26 @@ pipeline { stage('Deploy') { steps { echo 'Deploying....' + script { + if (env.GIT_BRANCH == 'master' || env.GIT_BRANCH == 'develop') { + sh """ + cd ./jenkins/${ENV:GIT_BRANCH} + docker-compose stop | true + docker-compose up -d + """ + } else { + sh """ + docker push tikazyq/crawlab:${ENV:TAG} + """ + } + } + } + } + stage('Cleanup') { + steps { + echo 'Cleanup...' sh """ - echo ${ENV:GIT_BRANCH} - """ - sh """ - cd ./jenkins/${ENV:GIT_BRANCH} - docker-compose stop | true - docker-compose up -d + docker image prune -f """ } } diff --git a/README-zh.md b/README-zh.md index 767d1ba7..e72065b0 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,10 +1,10 @@ # Crawlab ![](http://114.67.75.98:8082/buildStatus/icon?job=crawlab%2Fmaster) -![](https://img.shields.io/badge/版本-v0.3.0-blue.svg) - - - +![](https://img.shields.io/github/release/tikazyq/crawlab.svg) +![](https://img.shields.io/github/last-commit/tikazyq/crawlab.svg) +![](https://img.shields.io/github/issues/tikazyq/crawlab.svg) +![](https://img.shields.io/github/license/tikazyq/crawlab.svg) 中文 | [English](https://github.com/tikazyq/crawlab) diff --git a/README.md b/README.md index 6dcac157..f8c550bd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Crawlab ![](http://114.67.75.98:8082/buildStatus/icon?job=crawlab%2Fmaster) -![](https://img.shields.io/badge/version-v0.3.0-blue.svg) - - - +![](https://img.shields.io/github/release/tikazyq/crawlab.svg) +![](https://img.shields.io/github/last-commit/tikazyq/crawlab.svg) +![](https://img.shields.io/github/issues/tikazyq/crawlab.svg) +![](https://img.shields.io/github/license/tikazyq/crawlab.svg) [中文](https://github.com/tikazyq/crawlab/blob/master/README-zh.md) | English diff --git a/docker/Dockerfile.frontend.alpine b/docker/Dockerfile.frontend.alpine new file mode 100644 index 00000000..d313cdcb --- /dev/null +++ b/docker/Dockerfile.frontend.alpine @@ -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"] \ No newline at end of file diff --git a/Dockerfile.master.apline b/docker/Dockerfile.master.alpine similarity index 100% rename from Dockerfile.master.apline rename to docker/Dockerfile.master.alpine diff --git a/Dockerfile.worker.apline b/docker/Dockerfile.worker.alpine similarity index 100% rename from Dockerfile.worker.apline rename to docker/Dockerfile.worker.alpine diff --git a/examples/frontend/Dockerfile b/examples/frontend/Dockerfile index d313cdcb..9ce88b35 100644 --- a/examples/frontend/Dockerfile +++ b/examples/frontend/Dockerfile @@ -1,10 +1,20 @@ +FROM node:8.16.0-alpine AS build + +ADD ./frontend /app +WORKDIR /app + +# install frontend +RUN npm install -g yarn && yarn install + +RUN npm run build:prod + FROM alpine:latest # 安装nginx RUN mkdir /run/nginx && apk add nginx # 拷贝编译文件 -COPY dist /app/dist +COPY --from=build /app/dist /app/dist # 拷贝nginx代理文件 COPY crawlab.conf /etc/nginx/conf.d