5 changed files with 174 additions and 27 deletions
@ -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 |
@ -1,29 +1,22 @@ |
|||||||
FROM nginx |
# 基础镜像 |
||||||
MAINTAINER jeecgos@163.com |
FROM nginx:1.23 |
||||||
VOLUME /tmp |
# 维护者信息 |
||||||
ENV LANG en_US.UTF-8 |
MAINTAINER shuai.niu@foxmail.com |
||||||
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 |
|
||||||
|
|
||||||
|
# 设置环境变量 |
||||||
|
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/ |
ADD dist/ /var/www/html/ |
||||||
EXPOSE 80 |
|
||||||
EXPOSE 443 |
# 拷贝镜像启动程序 |
||||||
|
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"] |
@ -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" |
@ -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;" |
@ -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; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue