编程语言/Drone/drone-volume-cache:修订间差异
来自康健生活
创建页面,内容为“== 标题文本 == [https://github.com/drillster/drone-volume-cache drillster/drone-volume-cache]: Drone plugin for caching to a locally mounted volume. == 标题文本 == <syntaxhighlight lang="yaml"> - name: restore-cache # 把之前缓存好的数据取出 image: drillster/drone-volume-cache settings: restore: true mount: # 缓存挂载的文件夹 - ./.npm-cache - ./node_modules volumes: - name: cache path: /cache</syntax…” |
|||
| (未显示同一用户的2个中间版本) | |||
| 第13行: | 第13行: | ||
- name: cache | - name: cache | ||
path: /cache</syntaxhighlight> | path: /cache</syntaxhighlight> | ||
<syntaxhighlight lang="yaml"> | |||
kind: pipeline # 定义对象类型,还有secret和signature两种类型 | |||
type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型 | |||
name: report-cli-pipeline # 定义流水线名称 | |||
#声明挂载卷 | |||
volumes: | |||
- name: cache #挂载卷名称 | |||
host: | |||
path: /root/cache #挂载卷挂载到主机的目录 | |||
steps: | |||
- name: restore-cache #步骤名称,读取缓存 | |||
image: drillster/drone-volume-cache #使用的镜像 | |||
settings: | |||
restore: true #restore: true会将文件从主机复制到容器 | |||
mount: #需要缓存的文件夹 | |||
- ./.npm-cache | |||
- ./node_modules | |||
volumes: #使用的缓存和容器内挂载目录 | |||
- name: cache #使用的缓存名称,和上面对应 | |||
path: /cache #把主机命为cache的缓存挂载到/cache下面在容器内挂载的目录 | |||
- name: install | |||
pull: if-not-exists # 如果镜像不存在则拉取,免去每次都要重新下载 | |||
image: node:alpine | |||
commands: | |||
- npm config set cache ./.npm-cache --global #设置npm缓存 | |||
- npm install | |||
- name: build | |||
pull: if-not-exists # 如果镜像不存在则拉取,免去每次都要重新下载 | |||
image: jarmour/vue-cli:latest | |||
commands: | |||
- npm run build:h5 | |||
- name: rebuild-cache #步骤名称,构建缓存 | |||
image: drillster/drone-volume-cache | |||
settings: | |||
rebuild: true #把容器内容复制到主机 | |||
mount: #先加载缓存 | |||
- ./.npm-cache | |||
- ./node_modules | |||
volumes: #再复制到主机 | |||
- name: cache | |||
path: /cache | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="yaml"> | |||
kind: pipeline | |||
type: docker #在docker runner中运行 | |||
name: web | |||
#定义setups,每个setup有属于自己的name,最后会显示在Drone CI管理页面的侧边栏 | |||
steps: | |||
- name: restore-cache # 把之前缓存好的数据取出 | |||
image: drillster/drone-volume-cache | |||
settings: | |||
restore: true | |||
mount: # 缓存挂载的文件夹 | |||
- ./.npm-cache | |||
- ./node_modules | |||
volumes: | |||
- name: cache | |||
path: /cache | |||
- name: compile #编译 | |||
image: node:12 | |||
commands: | |||
- yarn config set registry https://registry.npm.taobao.org -g | |||
- yarn config set cache ./.npm-cache --global | |||
- yarn install | |||
- yarn run build | |||
- name: build image #打成docker镜像 | |||
image: docker | |||
failure: ignore | |||
volumes: | |||
- name: sock | |||
path: /var/run/docker.sock | |||
commands: | |||
- docker build -t localhost:v1.0 -f Dockerfile . | |||
- docker image prune -f --filter "dangling=true" # 清理无用镜像 | |||
- name: rebuild-cache # 把依赖和 npm 缓存放到缓存里 | |||
image: drillster/drone-volume-cache | |||
settings: | |||
rebuild: true | |||
mount: | |||
- ./.npm-cache | |||
- ./node_modules | |||
volumes: | |||
- name: cache | |||
path: /cache | |||
- name: deploy #部署到服务器上 | |||
image: docker | |||
failure: ignore | |||
volumes: | |||
- name: sock | |||
path: /var/run/docker.sock | |||
commands: | |||
- docker service ls|grep test || export SERVICE=down #先检查服务是否存在,存在更新,不存在创建 | |||
- | | |||
if [ "$SERVICE" != "down" ] | |||
then | |||
docker service update --image test:v1.0 test_test | |||
else | |||
docker stack deploy -c deploy.yaml autocd-web | |||
fi | |||
# 循环检测服务是否启动成功 | |||
- | | |||
while true | |||
do | |||
docker service ps test_test|awk '{print $6}'|awk 'NR==2'|grep 'Running' || export SERVICE=down | |||
if [ "$SERVICE" == "down" ] | |||
then | |||
echo -e "\033[5;35;40m 正在启动中请稍后 ... \033[0m" | |||
export SERVICE=up | |||
continue | |||
else | |||
docker service logs -n 200 test_test | |||
sleep 3 | |||
break | |||
fi | |||
done | |||
# 挂载宿主机文件到docker容器中 | |||
volumes: | |||
- name: sock | |||
host: | |||
path: /var/run/docker.sock | |||
- name: cache | |||
host: | |||
path: /tmp/cache | |||
# 创建触发器,绑定分支及事件及上一次成功时才运行 | |||
trigger: | |||
branch: | |||
- master | |||
event: | |||
- pull_request | |||
- push | |||
status: | |||
- success | |||
- failure | |||
node: | |||
machine1:runner1 | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="yaml"> | |||
pipeline: | |||
# 加载缓存 node_modules | |||
restore-cache: | |||
image: drillster/drone-volume-cache | |||
restore: true | |||
mount: | |||
- ./node_modules | |||
volumes: | |||
- /tmp/cache:/cache | |||
when: | |||
# 触发事件类型[push], [pull_request] | |||
event: [push, pull_request] | |||
# 触发分支 | |||
branch: [devlopment, test, master] | |||
# install | |||
install: | |||
image: node:12-alpine | |||
commands: | |||
# 删除文件 npm install | |||
- rm -rf package-lock.json | |||
- npm --registry https://registry.npm.taobao.org install | |||
when: | |||
event: [push, pull_request] | |||
branch: [devlopment, test, master] | |||
# 更新node_modules缓存 | |||
rebuild-cache: | |||
image: drillster/drone-volume-cache | |||
rebuild: true | |||
mount: | |||
- ./node_modules | |||
volumes: | |||
- /tmp/cache:/cache | |||
when: | |||
event: [push, pull_request] | |||
branch: [devlopment, test, master] | |||
# push | |||
dev-push: | |||
image: appleboy/drone-scp | |||
host: xxx # 可以写到secret中 | |||
port: 22 | |||
username: xxx | |||
password: xxx | |||
target: /app/vue-manage-server | |||
source: . | |||
rm: true | |||
when: | |||
event: [push, pull_request] | |||
branch: [devlopment] | |||
# push | |||
test-push: | |||
image: appleboy/drone-scp | |||
host: xxx # 可以写到secret中 | |||
port: 22 | |||
username: xxx | |||
password: xxx | |||
target: /app/vue-manage-server | |||
source: . | |||
rm: true | |||
when: | |||
event: [push, pull_request] | |||
branch: [test] | |||
# push | |||
master-push: | |||
image: appleboy/drone-scp | |||
host: xxx # 实际应用中,可以写到secret中 | |||
port: 22 | |||
username: xxx | |||
password: xxx | |||
target: /app/vue-manage-server | |||
source: . | |||
rm: true | |||
when: | |||
event: [push, pull_request] | |||
branch: [master] | |||
# run | |||
dev-run: | |||
image: appleboy/drone-ssh | |||
host: xxx | |||
username: xxx | |||
password: xxx | |||
port: 22 | |||
command_timeout: 300s | |||
script: | |||
- cd /app/vue-manage-server | |||
- mkdir seresr | |||
when: | |||
event: [push, pull_request] | |||
branch: [devlopment] | |||
# run | |||
test-run: | |||
image: appleboy/drone-ssh | |||
host: xxx | |||
username: xxx | |||
password: xxx | |||
port: 22 | |||
command_timeout: 300s | |||
script: | |||
- cd /app/vue-manage-server | |||
- mkdir seresr | |||
when: | |||
event: [push, pull_request] | |||
branch: [test] | |||
# run | |||
master-run: | |||
image: appleboy/drone-ssh | |||
host: xxx | |||
username: xxx | |||
password: xxx | |||
port: 22 | |||
command_timeout: 300s | |||
script: | |||
- cd /app/vue-manage-server | |||
- docker build -t vue-manage-server . | |||
- docker run -d -p 4000:4000 vue-manage-server | |||
when: | |||
event: [push, pull_request] | |||
branch: [master] | |||
</syntaxhighlight> | |||