-1

I am following a CI-CD process for my node application. I am able to deploy it successfully, but the problem is it is taking a very long time for the whole process. How can I make this CI-CD process faster ?

Below is my cloudbuild.yaml file:

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

This process is taking me more than 15 minutes which is too much I think. How can I make it to run prettier, linting and unit tests to run all at once and not sequentially ?

Edit_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
Pritish
  • 658
  • 3
  • 16
  • 38

1 Answers1

1

I'm not sure that running the 3 stuffs in a row into the same step will help you to save time, few seconds not more.

You have here some tips to speed up your process.

  • Use the same image for all the steps, that prevent Cloud Build to download different ones. Example: your prettier step, not the same at the others
  • Use Kaniko cache to cache the images, that prevent to download the image at the first step, it's immediately in cache
  • Increase the number of CPU. You will increase the processing performances AND the internet bandwidth allowed to your job. Your image pulling and your dependencies downloading will be quicker.

Google provides tips here

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Thanks for the quick response. Please check my `Edit_1` section and tell me if this is the correct way to write. – Pritish Jun 29 '20 at 18:41
  • Yes, it's correct but by reviewing your build step, it will be useless. Kaniko cache is efficient when you build container, and here you don't build one :( – guillaume blaquiere Jun 29 '20 at 19:09
  • So, what would you suggest me to do ? – Pritish Jun 29 '20 at 19:18
  • You have fixed the multiple image pulling, now you have only one. Kaniko is useless, you can [increase the size of the Cloud Build VM](https://cloud.google.com/cloud-build/docs/speeding-up-builds#using_custom_virtual_machine_sizes). – guillaume blaquiere Jun 29 '20 at 20:08