编程语言/Drone/示例:修订间差异
来自康健生活
| 第100行: | 第100行: | ||
- ls /drone/src | - ls /drone/src | ||
- cp -r ./public/* ./html</syntaxhighlight> | - cp -r ./public/* ./html</syntaxhighlight> | ||
<syntaxhighlight lang="yaml"> | |||
kind: pipeline | |||
name: ctools | |||
type: docker | |||
# 私有镜像站认证信息 | |||
image_pull_secrets: | |||
- dockerconfigjson | |||
# 因为有个性化的 clone 需求,所以这里关闭默认的 clone 动作 | |||
clone: | |||
disable: true | |||
steps: | |||
- name: 克隆仓库 | |||
# image: drone/git | |||
image: registry.wait/cwx/drone/git | |||
pull: if-not-exists | |||
settings: | |||
# clone 时截断以前的提交记录, 即克隆深度 | |||
depth: 1 | |||
skip_verify: true | |||
# 读取 git 的 tag 作为环境变量 ${DRONE_TAG} | |||
tags: true | |||
# 因为没能解析到名字,临时加一下 hosts | |||
# extra_hosts: | |||
# - "git.services.wait:10.2.1.5" | |||
commands: | |||
- git config --global http.sslVerify false | |||
- git clone https://git.services.wait/chenwx/ctools.git . | |||
- ls -a | |||
- git log --oneline -n 5 | |||
# 使用缓存避免反复从网络上下载依赖包 | |||
# - name: restore-cache | |||
- name: 加载编译缓存 | |||
image: registry.wait/cwx/drone/drillster/drone-volume-cache | |||
# image: drillster/drone-volume-cache | |||
# 默认各阶段是并行处理的, 需要定义依赖关系 | |||
depends_on: [克隆仓库] | |||
volumes: | |||
- name: cache | |||
path: /cache | |||
settings: | |||
# 从以前的构建中恢复缓存,即拷贝这个目录下的内容到容器内 | |||
restore: true | |||
mount: | |||
- ./node_modules | |||
# - name: build | |||
- name: 开发环境-编译 | |||
# image: node:19.9.0 | |||
image: registry.wait/cwx/node:19.9.0 | |||
pull: if-not-exists | |||
depends_on: [加载编译缓存] | |||
commands: | |||
- ls -a | |||
- node -v | |||
- npm get registry | |||
- npm config set registry http://10.2.1.5:4873/ | |||
- npm install | |||
- npm run build | |||
- cd dist | |||
- tar zcvf ctools-0.1.tar.gz ./* | |||
# 排除全部tag,即不匹配任何 tag | |||
when: | |||
ref: | |||
exclude: | |||
- refs/tags/** | |||
# 具有 tag 时的编译动作 | |||
# - name: build-tag | |||
- name: 生产环境-编译 | |||
# image: node:19.9.0 | |||
image: registry.wait/cwx/node:19.9.0 | |||
pull: if-not-exists | |||
depends_on: [加载编译缓存] | |||
commands: | |||
- ls -a | |||
- node -v | |||
- npm install | |||
- npm run build | |||
- cd dist | |||
- tar zcvf ctools-${DRONE_TAG##v}.tar.gz ./* | |||
- ls | |||
# 匹配全部tag | |||
when: | |||
ref: | |||
- refs/tags/** | |||
# 将缓存文件卸载 | |||
# - name: rebuild-cache | |||
- name: 开发环境-卸载缓存 | |||
image: registry.wait/cwx/drone/drillster/drone-volume-cache | |||
# image: drillster/drone-volume-cache | |||
pull: if-not-exists | |||
depends_on: [开发环境-编译] | |||
volumes: | |||
- name: cache | |||
path: /cache | |||
settings: | |||
# 重新创建缓存, 即将文件写回到宿主机 | |||
rebuild: true | |||
mount: | |||
- ./node_modules | |||
when: | |||
ref: | |||
exclude: | |||
- refs/tags/** | |||
# 为有 tag 的情况 | |||
# - name: rebuild-cache-tag | |||
- name: 生产环境-卸载缓存 | |||
# image: drillster/drone-volume-cache | |||
image: registry.wait/cwx/drone/drillster/drone-volume-cache | |||
pull: if-not-exists | |||
depends_on: [生产环境-编译] | |||
volumes: | |||
- name: cache | |||
path: /cache | |||
settings: | |||
rebuild: true | |||
mount: | |||
- ./node_modules | |||
when: | |||
ref: | |||
- refs/tags/** | |||
# 提交一个 release 版本到 gitea | |||
# gitea-release 插件只适用于有 tag 的情况 | |||
# - name: gitea_release | |||
- name: 生产环境-gitea-release | |||
# image: plugins/gitea-release | |||
image: registry.wait/cwx/drone/plugins/gitea-release | |||
pull: if-not-exists | |||
depends_on: [生产环境-编译] | |||
settings: | |||
api_key: 2a5ab57061a66a6f37233a3fac07029cb5ad6b76 | |||
base_url: https://git.services.wait/ | |||
files: | |||
# 上传文件时,把那个 v 前缀去掉 | |||
- dist/ctools-${DRONE_TAG##v}.tar.gz | |||
# 如果存在则覆盖 | |||
file_exists: overwrite | |||
title: 新版本发布-${DRONE_TAG} | |||
# 忽略 https 证书 | |||
insecure: true | |||
volumes: | |||
- name: cwxCA | |||
path: /etc/ssl/certs/ca-certificates.crt | |||
# extra_hosts: | |||
# - "git.services.wait:10.2.1.5" | |||
when: | |||
ref: | |||
- refs/tags/** | |||
# 使用 scp 传输到其它主机 | |||
# - name: deployment | |||
- name: 开发环境-推送 | |||
# image: appleboy/drone-scp | |||
image: registry.wait/cwx/drone/appleboy/drone-scp | |||
pull: if-not-exists | |||
depends_on: [开发环境-编译] | |||
settings: | |||
host: 10.2.1.5 | |||
username: wait | |||
# password: | |||
# # 密码使用单独存储在 drone 上的密码 | |||
# from_secret: wcn7_wait_pw | |||
key: | |||
from_secret: wcn7_wait_key | |||
port: 22 | |||
# 目标: /home/wait/chenwx/ctools/ctools-0.1.tar.gz | |||
target: /home/wait/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME} | |||
source: dist/ctools-0.1.tar.gz | |||
when: | |||
ref: | |||
exclude: | |||
- refs/tags/** | |||
# 推送到生产环境 | |||
# - name: deployment-production | |||
- name: 生产环境-推送 | |||
# image: appleboy/drone-scp | |||
image: registry.wait/cwx/drone/appleboy/drone-scp | |||
pull: if-not-exists | |||
depends_on: [生产环境-编译] | |||
settings: | |||
host: 10.3.0.2 | |||
username: wait | |||
key: | |||
from_secret: wcn7_wait_key | |||
port: 39022 | |||
# 目标: /home/wait/data/pkg/ctools-0.1.tar.gz | |||
target: /home/wait/data/pkg | |||
source: dist/ctools-${DRONE_TAG##v}.tar.gz | |||
when: | |||
ref: | |||
- refs/tags/** | |||
# 到远程主机执行命令 | |||
# - name: ssh | |||
- name: 开发环境-部署 | |||
# image: appleboy/drone-ssh | |||
image: registry.wait/cwx/drone/appleboy/drone-ssh | |||
pull: if-not-exists | |||
depends_on: [开发环境-推送] | |||
settings: | |||
host: | |||
- 10.2.1.5 | |||
username: wait | |||
# password: | |||
# from_secret: wcn7_wait_pw | |||
key: | |||
from_secret: wcn7_wait_key | |||
port: 22 | |||
command_timeout: 1m | |||
script: | |||
- cd /home/wait/chenwx/ctools | |||
- rm -rf tmp2 && mkdir tmp2 | |||
- tar xvf dist/ctools-0.1.tar.gz -C tmp2/ | |||
- rm -rf /home/wait/data/tools/* | |||
- mv tmp2/* /home/wait/data/tools/ | |||
when: | |||
ref: | |||
exclude: | |||
- refs/tags/** | |||
# 生产环境-部署命令 | |||
# - name: ssh-production | |||
- name: 生产环境-部署 | |||
# image: appleboy/drone-ssh | |||
image: registry.wait/cwx/drone/appleboy/drone-ssh | |||
pull: if-not-exists | |||
depends_on: [生产环境-推送] | |||
settings: | |||
host: | |||
- 10.3.0.2 | |||
username: wait | |||
key: | |||
from_secret: wcn7_wait_key | |||
port: 39022 | |||
command_timeout: 1m | |||
script: | |||
- cd /home/wait/data/pkg | |||
- rm -rf tmp2 && mkdir tmp2 | |||
- tar xvf dist/ctools-${DRONE_TAG##v}.tar.gz -C tmp2/ | |||
- rm -rf /home/wait/data/tools/* | |||
- mv tmp2/* /home/wait/data/tools/ | |||
when: | |||
ref: | |||
- refs/tags/** | |||
volumes: | |||
- name: cache | |||
host: | |||
path: /data/cache | |||
- name: cwxCA | |||
host: | |||
path: /home/wait/data/ca/cwxCA.pem | |||
# path: /home/wait/code/ssl/ca/cwxCA.pem | |||
</syntaxhighlight> | |||