From a1c45cb5ded10bd58197f97380899da19befd139 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Thu, 15 Aug 2019 12:11:14 +0800 Subject: [PATCH 1/5] updated Jenkinsfile --- Jenkinsfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index b9f99723..df12f4de 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -48,5 +48,13 @@ pipeline { """ } } + stage('Cleanup') { + steps { + echo 'Cleanup...' + sh """ + docker image prune -f + """ + } + } } } \ No newline at end of file From 7aa6afb4b52275e2c147bddc1210cddd08e9bd4c Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Fri, 16 Aug 2019 00:09:04 +0800 Subject: [PATCH 2/5] added Dockerfiles --- Jenkinsfile | 36 ++++++++++++------- docker/Dockerfile.frontend.alpine | 20 +++++++++++ .../Dockerfile.master.alpine | 0 .../Dockerfile.worker.alpine | 0 examples/frontend/Dockerfile | 12 ++++++- 5 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 docker/Dockerfile.frontend.alpine rename Dockerfile.master.apline => docker/Dockerfile.master.alpine (100%) rename Dockerfile.worker.apline => docker/Dockerfile.worker.alpine (100%) diff --git a/Jenkinsfile b/Jenkinsfile index df12f4de..1d728a4c 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,14 +45,17 @@ pipeline { stage('Deploy') { steps { echo 'Deploying....' - sh """ - echo ${ENV:GIT_BRANCH} - """ - sh """ - cd ./jenkins/${ENV:GIT_BRANCH} - docker-compose stop | true - docker-compose up -d - """ + 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') { 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 From 306303abe0223efeef647140bcf618f40452b16f Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Fri, 16 Aug 2019 00:13:24 +0800 Subject: [PATCH 3/5] updated README badges --- README-zh.md | 3 ++- README.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README-zh.md b/README-zh.md index 767d1ba7..9787f20f 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,7 +1,8 @@ # 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) diff --git a/README.md b/README.md index 6dcac157..ec356276 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # 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) From 629d859f12e3e6c316ec8470253e17efdd69d706 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Fri, 16 Aug 2019 00:18:55 +0800 Subject: [PATCH 4/5] updated README badges --- README-zh.md | 5 ++--- README.md | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README-zh.md b/README-zh.md index 9787f20f..e72065b0 100644 --- a/README-zh.md +++ b/README-zh.md @@ -3,9 +3,8 @@ ![](http://114.67.75.98:8082/buildStatus/icon?job=crawlab%2Fmaster) ![](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 ec356276..f8c550bd 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,8 @@ ![](http://114.67.75.98:8082/buildStatus/icon?job=crawlab%2Fmaster) ![](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 From 5ca969b3db9b82072979e143dfc617212f7fa38a Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Fri, 16 Aug 2019 00:20:19 +0800 Subject: [PATCH 5/5] updated README badges --- Jenkinsfile | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1d728a4c..1b448465 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,16 +45,18 @@ pipeline { stage('Deploy') { steps { echo 'Deploying....' - 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} - """ + 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} + """ + } } } }