【问题标题】:Why does it take long time for the whole CI-CD process to complete?为什么整个 CI-CD 过程需要很长时间才能完成?
【发布时间】:2020-06-29 14:45:19
【问题描述】:

我正在为我的节点应用程序遵循 CI-CD 流程。我能够成功部署它,但问题是整个过程需要很长时间。我怎样才能使这个 CI-CD 过程更快?

下面是我的 cloudbuild.yaml 文件:

steps:
    # Install npm
    - name: 'node:10.10.0'
      args: ['npm', 'install']
      dir: './UI'

    # Make the app prettier
    - name: 'node:10.13.0'
      entrypoint: bash
      args: ['-c', 'npx prettier --check "**/*"']
      dir: './UI'

    # Execute the lint command
    - name: 'node:10.10.0'
      args: ['npm', 'run', 'lint']
      dir: './UI'

    # Install Phantom JS -g karma-cli
    - name: 'node:10.10.0'
      args: ['npm', 'install', '--save-dev karma-phantomjs-launcher']
      dir: './UI'

    # NPM test
    - name: 'node:10.10.0'
      args: ['npm', 'run', 'test']
      dir: './UI'

    # Build dev file
    - name: 'node:10.10.0'
      args: ['npm', 'run', 'build_dev']
      dir: './UI'
      timeout: 1800s

    # List the files in the UI directory
    - name: 'node:10.10.0'
      entrypoint: bash
      args: ['-c', 'ls -la']
      dir: './UI'

    # Deploy UI build to CS-D Portal
    - name: 'gcr.io/cloud-builders/gcloud'
      args: ['app', 'deploy', './']
      dir: './UI'

timeout: 1801s

这个过程比15 minutes 花费的更多,我认为这太多了。我怎样才能让它运行 prettier, linting and unit tests 一次运行而不是顺序运行?

编辑_1:

steps:
        - name: 'gcr.io/kaniko-project/executor:latest'
          args:
          - --destination=gcr.io/xoxoxoxoxo/node:10.13.0
          - --cache=true
          - --cache-ttl=48h

        # Install npm
        - name: 'node:10.13.0'
          args: ['npm', 'install']
          dir: './UI'
    
        # Make the app prettier
        - name: 'node:10.13.0'
          entrypoint: bash
          args: ['-c', 'npx prettier --check "**/*"']
          dir: './UI'
    
        # Execute the lint command
        - name: 'node:10.13.0'
          args: ['npm', 'run', 'lint']
          dir: './UI'
    
        # Install Phantom JS -g karma-cli
        - name: 'node:10.13.0'
          args: ['npm', 'install', '--save-dev karma-phantomjs-launcher']
          dir: './UI'
    
        # NPM test
        - name: 'node:10.13.0'
          args: ['npm', 'run', 'test']
          dir: './UI'
    
        # Build dev file
        - name: 'node:10.13.0'
          args: ['npm', 'run', 'build_dev']
          dir: './UI'
          timeout: 1800s
    
        # List the files in the UI directory
        - name: 'node:10.13.0'
          entrypoint: bash
          args: ['-c', 'ls -la']
          dir: './UI'
    
        # Deploy UI build to CS-D Portal
        - name: 'gcr.io/cloud-builders/gcloud'
          args: ['app', 'deploy', './']
          dir: './UI'
    
    timeout: 1801s

【问题讨论】:

    标签: google-cloud-platform yaml devops google-cloud-build


    【解决方案1】:

    我不确定将 3 个内容连续运行到同一个步骤中是否会帮助您节省时间,而不是几秒钟。

    这里有一些提示可以加快您的流程。

    • 对所有步骤使用相同的映像,以防止 Cloud Build 下载不同的映像。 例如:您的prettier 步骤,其他步骤不一样
    • 使用 Kaniko 缓存来缓存图片,防止在第一步下载图片,它立即在缓存中
    • 增加 CPU 数量。您将提高处理性能和您的工作允许的互联网带宽。您的图像拉取和依赖项下载会更快。

    谷歌提供提示here

    【讨论】:

    • 感谢您的快速回复。请检查我的Edit_1 部分并告诉我这是否是正确的写作方式。
    • 是的,这是正确的,但是通过查看您的构建步骤,它将毫无用处。 Kaniko 缓存在您构建容器时非常高效,而这里您不构建一个 :(
    • 那么,你建议我做什么?
    • 你已经修复了多个图像拉取,现在你只有一个。 Kaniko没用,你可以increase the size of the Cloud Build VM
    猜你喜欢
    • 2013-02-06
    • 2020-02-28
    • 2018-02-07
    • 2016-07-30
    相关资源
    最近更新 更多