编程语言/Drone/示例:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 标题文本 == <syntaxhighlight lang="yaml"> kind: pipeline name: example-service trigger: branch: - master steps: - name: npm-auth image: robertstettner/drone-npm-auth settings: username: username password: password email: username@iftech.io registry: https://npm.yourcompany.com scope: '@jike' - name: install image: node:10 commands: - npm ci - name: lint image: node:10 commands:…”
 
Kangkk​(留言 | 贡献)
 
(未显示同一用户的1个中间版本)
第66行: 第66行:
     ports:
     ports:
       - 27017</syntaxhighlight>
       - 27017</syntaxhighlight>
<syntaxhighlight lang="yaml">
kind: pipeline # 定义一个管道
type: docker # 当前管道的类型
name: test # 当前管道的名称
volumes: # 声明数据卷(此为服务器中的实际目录)
  - name: node_modules # 数据卷名称
    host: # Host Volume
      path: /volumes/drone/volumes/blog/node_modules # 宿主机目录    #绝对路径
  - name: deploy_path
    host:
      path: /workspace/blog
clone:
  disable: false # 启用代码拉取
steps: # 定义管道的执行步骤
  - name: deploy # 步骤名称
    image: node:16.13.2 # 当前步骤使用的镜像
    depends_on: [clone] # 依赖的步骤
    volumes: # 挂载数据卷(此为容器内的目录)
      - name: node_modules # 数据卷名称
        path: /drone/src/node_modules # 容器内目录 绝对路径
      - name: deploy_path
        path: /drone/src/html
    commands: # 当前步骤执行的命令
      - pwd # 查看当前目录
      - npm config set registry https://registry.npm.taobao.org # 切换淘宝镜像
      - npm install # 安装node_modules包
      - npm run build # 执行编译
      # - rm -fr ./blog
      - ls /drone/src
      - 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>

2026年2月15日 (日) 13:03的最新版本

标题文本

kind: pipeline
name: example-service

trigger:
  branch:
    - master

steps:
  - name: npm-auth
    image: robertstettner/drone-npm-auth
    settings:
      username: username
      password: password
      email: username@iftech.io
      registry: https://npm.yourcompany.com
      scope: '@jike'
  - name: install
    image: node:10
    commands:
      - npm ci
  - name: lint
    image: node:10
    commands:
      - npm run lint
  - name: compile
    image: node:10
    commands:
      - npm run compile
  - name: test
    image: node:10
    commands:
      - npm t
  - name: ecr-build-push
    image: plugins/ecr
    settings:
      repo: example.ecr.region.amazonaws.com/example-service
      registry: example.ecr.region.amazonaws.com
      region: region
      create_repository: true
      tags:
        - ${DRONE_SOURCE_BRANCH//\//-}-${DRONE_COMMIT:0:7}
  - name: notify
    image: plugins/webhook
    settings:
      urls: http://jkdpy-dashboard-svc.infra:8000/api/images/
      content_type: application/x-www-form-urlencoded
      template: | 
      image_name=example.ecr.region.amazonaws.com/example-service:${DRONE_COMMIT:0:7}&\
      branch_name=${DRONE_SOURCE_BRANCH}&\
      service_name=example-service&\
      commit_message=${DRONE_COMMIT_MESSAGE}

services:
  - name: kafka
    image: spotify/kafka
    ports:
      - 9092
  - name: redis
    image: redis
    ports:
      - 6379
  - name: mongo
    image: mongo
    ports:
      - 27017
kind: pipeline # 定义一个管道
type: docker # 当前管道的类型
name: test # 当前管道的名称

volumes: # 声明数据卷(此为服务器中的实际目录)
  - name: node_modules # 数据卷名称
    host: # Host Volume
      path: /volumes/drone/volumes/blog/node_modules # 宿主机目录    #绝对路径
  - name: deploy_path
    host: 
      path: /workspace/blog

clone:
  disable: false # 启用代码拉取

steps: # 定义管道的执行步骤
  - name: deploy # 步骤名称
    image: node:16.13.2 # 当前步骤使用的镜像
    depends_on: [clone] # 依赖的步骤
    volumes: # 挂载数据卷(此为容器内的目录)
      - name: node_modules # 数据卷名称
        path: /drone/src/node_modules # 容器内目录 绝对路径
      - name: deploy_path
        path: /drone/src/html
    commands: # 当前步骤执行的命令
      - pwd # 查看当前目录
      - npm config set registry https://registry.npm.taobao.org # 切换淘宝镜像
      - npm install # 安装node_modules包
      - npm run build # 执行编译
      # - rm -fr ./blog
      - ls /drone/src
      - cp -r ./public/* ./html
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