From 1631ce662830e3a1783550bb0f1852b74352f89b Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Fri, 30 Dec 2022 10:09:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8B=E8=AF=95=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 77 +++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 47 ++++++++++++----------------- deploy.sh | 23 ++++++++++++++ entry-point.sh | 17 +++++++++++ nginx-server.conf | 37 +++++++++++++++++++++++ 5 files changed, 174 insertions(+), 27 deletions(-) create mode 100644 .drone.yml create mode 100644 deploy.sh create mode 100644 entry-point.sh create mode 100644 nginx-server.conf diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..76b2dcb --- /dev/null +++ b/.drone.yml @@ -0,0 +1,77 @@ +kind: pipeline +type: docker +name: drone-dev-db-bastion-vue + +# 触发器 +trigger: + # 触发分支 + branch: + - master + # 触发事件 + event: + - push + # 事件状态 + status: + - success + +# 共享目录 +volumes: + - name: node-cache + host: + path: /data/drone/node/cache + - name: node-build + host: + path: /data/drone/node/build + - name: docker-sock + host: + path: /var/run/docker.sock + - name: env-files + host: + path: /niushuai233/env + +# ci 步骤 +steps: + # node install + - name: node-package + image: node:14.12.0 + volumes: + - name: node-cache + path: ./node_modules + - name: node-build + path: /app/build + commands: + - echo 'node package start' + # 打包 + - npm config set registry https://registry.npm.taobao.org -g + - npm install + - npm run build + # 拷贝打包结果到宿主机 + - mkdir -p /app/build/db-bastion-vue + - cp -R dist/ /app/build/db-bastion-vue/ + + # 构建镜像 + - name: build-image + image: docker:dind + volumes: + - name: docker-sock + path: /var/run/docker.sock + commands: + - echo 'build image start' + # 构建新镜像 + - docker build -t niushuai233/db-bastion-vue:latest . + # 清理无用镜像 + - docker image prune -f --filter "dangling=true" + + # 启动服务 + - name: deploy + image: docker:dind + volumes: + - name: docker-sock + path: /var/run/docker.sock + - name: env-files + path: /niushuai233/env + commands: + - echo 'deploy start' + - pwd + - ls -alh + - sh deploy.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 13b8769..527ebfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,22 @@ -FROM nginx -MAINTAINER jeecgos@163.com -VOLUME /tmp -ENV LANG en_US.UTF-8 -RUN echo "server { \ - listen 80; \ - location ^~ /jeecg-boot { \ - proxy_pass http://jeecg-boot-system:8080/jeecg-boot/; \ - proxy_set_header Host jeecg-boot-system; \ - proxy_set_header X-Real-IP \$remote_addr; \ - proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; \ - } \ - #解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 \ - location / { \ - root /var/www/html/; \ - index index.html index.htm; \ - if (!-e \$request_filename) { \ - rewrite ^(.*)\$ /index.html?s=\$1 last; \ - break; \ - } \ - } \ - access_log /var/log/nginx/access.log ; \ - } " > /etc/nginx/conf.d/default.conf \ - && mkdir -p /var/www \ - && mkdir -p /var/www/html +# 基础镜像 +FROM nginx:1.23 +# 维护者信息 +MAINTAINER shuai.niu@foxmail.com +# 设置环境变量 +ENV DEV_API_URL http://localhost:8080 +ENV TEST_API_URL http://localhost:8080 +ENV PROD_API_URL http://localhost:8080 + +# 拷贝前端工程文件 ADD dist/ /var/www/html/ -EXPOSE 80 -EXPOSE 443 \ No newline at end of file + +# 拷贝镜像启动程序 +ADD entry-point.sh /entry-point.sh + +# 设置时区 +RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime +RUN echo 'Asia/Shanghai' >/etc/timezone + +# 入口程序 +ENTRYPOINT ["/entry-point.sh"] \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..1e68321 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +d_group_name=niushuai233 +d_app_name=db-bastion-vue +d_app_version=latest +d_app_port_inner=80 +d_app_port_export=31014 + +if [[ -n $(docker ps -q -f "name=^${d_app_name}$") ]];then + echo "${d_app_name} already started before ==> rm" + docker rm -f ${d_app_name} + echo "${d_app_name} rm success" +else + echo "${d_app_name} never started" +fi + +docker run -dit \ + -p ${d_app_port_export}:${d_app_port_inner} \ + --env-file=/niushuai233/env/${d_app_name}/main.env \ + --name=${d_app_name} \ + ${d_group_name}/${d_app_name}:${d_app_version} + +echo "${d_app_name} started" \ No newline at end of file diff --git a/entry-point.sh b/entry-point.sh new file mode 100644 index 0000000..834419f --- /dev/null +++ b/entry-point.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +NGINX_CONFIG=/etc/nginx/conf.d/nginx-server.conf + +echo "DEV_API_URL=${DEV_API_URL}" +sed -i "s#DEV_API_URL#${DEV_API_URL}#g" ${NGINX_CONFIG} + +echo "TEST_API_URL=${TEST_API_URL}" +sed -i "s#TEST_API_URL#${TEST_API_URL}#g" ${NGINX_CONFIG} + +echo "PROD_API_URL=${PROD_API_URL}" +sed -i "s#PROD_API_URL#${PROD_API_URL}#g" ${NGINX_CONFIG} + +cat ${NGINX_CONFIG} + +echo "start nginx" +nginx -g "daemon off;" \ No newline at end of file diff --git a/nginx-server.conf b/nginx-server.conf new file mode 100644 index 0000000..e4b3130 --- /dev/null +++ b/nginx-server.conf @@ -0,0 +1,37 @@ +server { + listen 80; + + location / { + root /var/www/html/; + index index.html index.htm; + # 解决Router(mode: 'history')模式下,刷新路由地址不能找到页面的问题 + if (!-e \$request_filename) { + rewrite ^(.*)\$ /index.html?s=\$1 last; + break; + } + } + + location /devApi/ { + proxy_pass DEV_API_URL; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-PORT $remote_port; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /testApi/ { + proxy_pass TEST_API_URL; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-PORT $remote_port; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /prodApi/ { + proxy_pass PROD_API_URL; + proxy_set_header Host $host:$server_port; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-PORT $remote_port; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file