Multiple commands in the same build step in Google Cloud Builder

后端 未结 3 1382
礼貌的吻别
礼貌的吻别 2021-01-11 19:31

I want to run our automated backend test suite on Google Cloud Builder environment. However, naturally, I bumped into the need to install various dependencies and prerequisi

相关标签:
3条回答
  • 2021-01-11 19:48

    You have 2 options to achieve this at the moment I believe:

    1. create a script that has the sequence of commands you'd like and call the script directly:
    # cloudbuild.yaml
    steps:
      - name: 'ubuntu'
        args: ['./my-awesome-script.sh']
    
    # my-awesome-script.sh
    /usr/bin/env/bash
    
    set -eo pipefail
    
    ./scripts/install-prerequisites.sh
    composer install -n -q --prefer-dist
    php init --overwrite=y
    php tests/run
    
    1. Call bash -c with all the commands you'd like to follow:
    steps:
      - name: 'ubuntu'
        args: ['bash', '-c', './scripts/install-prerequisites.sh && composer install -n -q --prefer-dist && php init --overwrite=y && php tests/run']
    
    0 讨论(0)
  • 2021-01-11 19:53

    See:

    • https://cloud.google.com/cloud-build/docs/configuring-builds/configure-build-step-order
    • https://cloud.google.com/cloud-build/docs/configuring-builds/store-images-artifacts
    • https://github.com/GoogleCloudPlatform/cloud-builders-community
    • https://github.com/GoogleCloudPlatform/cloud-builders

    By default, build steps run sequentially, but you can configure them to run concurrently.

    The order of the build steps in the steps field relates to the order in which the steps are executed. Steps will run serially or concurrently based on the dependencies defined in their waitFor fields.

    A step is dependent on every id in its waitFor and will not launch until each dependency has completed successfully.

    So you only separate command as each step.

    Like this.

    steps:
      - name: 'ubuntu'
        args: ['bash', './scripts/install-prerequisites.sh']
        id: 'bash ./scripts/install-prerequisites.sh'
      - name: 'ubuntu'
        args: ['composer', 'install', '-n', '-q', '--prefer-dist']
        id: 'composer install -n -q --prefer-dist'
      - name: 'ubuntu'
        args: ['php', 'init', '--overwrite=y']
        id: 'php init --overwrite=y'
      - name: 'ubuntu'
        args: ['php', 'tests/run']
        id: 'php tests/run'
    

    By the way, Can using ubuntu image run php and composer command?

    I think that you should use or build docker image which can run php and composer command.

    The composer docker image is here.

    steps:
    - name: 'gcr.io/$PROJECT_ID/composer'
      args: ['install']
    
    
    
    0 讨论(0)
  • 2021-01-11 20:08

    A more readable way to run the script could be to use breakout syntax (source: mastering cloud build syntax)

    steps:
    - name: 'ubuntu'
      entrypoint: 'bash'
      args:
      - '-c'
      - |
        ./scripts/install-prerequisites.sh \
        && composer install -n -q --prefer-dist \
        && php init --overwrite=y \
        && php tests/run
    
    

    However, this only works if your build step image has the appropriate deps installed (php, composer).

    0 讨论(0)
提交回复
热议问题