drone 编译 vue或者node之类的项目时使用缓存

59次阅读
没有评论

共计 990 个字符,预计需要花费 3 分钟才能阅读完成。

下面配置大概的思路是这样的

  1. 从本机 /tmp/cache 目录还原缓存
  2. 执行更新依赖和编译命令
  3. 把最新的依赖复制到b本机 /tmp/cache 目录供下次使用

.drone.yml 文件

kind: pipeline
name: default
type: docker

steps:
    -   name: restore-cache #把缓存目录复制到根目录下的node_modules
        image: drillster/drone-volume-cache
        volumes:
            -   name: cache
                path: /cache
        settings:
            restore: true # 这个配置还原缓存的意思
            mount: # 此处配置需要复制的路径
                - ./node_modules

    -   name: 编译
        image: node:12-alpine
        commands:
            - yarn
            - yarn build

    -   name: rebuild-cache # 保存最新缓存到本地
        image: drillster/drone-volume-cache
        volumes:
            -   name: cache
                path: /cache
        settings:
            rebuild: true # 这个配置保存最新缓存路径的内容
            mount:     # 此处配置需要复制的路径
                - ./node_modules

    -   name: 构建镜像
        image: plugins/docker
        pull: if-not-exists
        settings:
            mirror: https://xxxx.mirror.aliyuncs.com # 我自己的加速地址
            purge: false
            username:
                from_secret: docker_user # 在 drone 的 secret 里面设置的变量
            password:
                from_secret: docker_pass # 在 drone 的 secret 里面设置的变量
            registry: registry.cn-shenzhen.aliyuncs.com
            repo: registry.cn-shenzhen.aliyuncs.com/xxxxx/vue3
            tags: ${DRONE_TAG=latest}
            insecure: true
    -   name: 触发部署
        image: plugins/webhook
        settings:
            urls:
                from_secret: webhook_url
            debug: true

volumes:
    -   name: cache
        host:
            path: /tmp/cache # 本地缓存路径
正文完
 0
Eric chan
版权声明:本站原创文章,由 Eric chan 于2021-07-30发表,共计990字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。