agones.dev/agones@v1.53.0/cloudbuild.yaml (about)

     1  ---
     2  # Copyright 2017 Google LLC All Rights Reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  # Google Cloud Builder CI configuration
    17  #
    18  steps:
    19    #
    20    # Cancel the previous build for the same branch
    21    #
    22    - name: gcr.io/cloud-builders/gcloud-slim:latest
    23      id: cancelot
    24      entrypoint: bash
    25      args: [./ci/cancelot.sh, --current_build_id, $BUILD_ID]
    26  
    27    #
    28    # Print Docker version
    29    #
    30    - name: gcr.io/cloud-builders/docker:24.0.6
    31      id: docker-version
    32      args: [--version]
    33  
    34    #
    35    # Restore any caches
    36    #
    37    - name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
    38      id: htmltest-restore-cache
    39      args: [--bucket=gs://$_CACHE_BUCKET, --key=$_HTMLTEST_CACHE_KEY]
    40      waitFor: ['-']
    41    - name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
    42      id: cpp-sdk-build-restore-cache
    43      args:
    44        - --bucket=gs://$_CACHE_BUCKET
    45        - --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
    46      waitFor: ['-']
    47    - name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
    48      id: cpp-sdk-conformance-restore-cache
    49      args:
    50        - --bucket=gs://$_CACHE_BUCKET
    51        - --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
    52      waitFor: ['-']
    53    - name: us-docker.pkg.dev/$PROJECT_ID/ci/restore_cache
    54      id: rust-sdk-build-restore-cache
    55      args:
    56        - --bucket=gs://$_CACHE_BUCKET
    57        - --key=$_RUST_SDK_BUILD_CACHE_KEY-$( checksum test/sdk/rust/Cargo.toml )
    58      waitFor: ['-']
    59  
    60    #
    61    # Creates the initial make + docker build platform
    62    #
    63    - name: ubuntu
    64      args:
    65        - bash
    66        - -c
    67        - "echo 'FROM gcr.io/cloud-builders/docker:24.0.6\nRUN apt-get install make\nENTRYPOINT\
    68          \ [\"/usr/bin/make\"]' > Dockerfile.build"
    69      waitFor: ['-']
    70    - name: gcr.io/cloud-builders/docker:24.0.6
    71      id: build-make-docker
    72      args: [build, -f, Dockerfile.build, -t, make-docker, .]  # we need docker and make to run everything.
    73  
    74    #
    75    # pull the main build image if it exists
    76    #
    77    - name: make-docker
    78      id: pull-build-image
    79      dir: build
    80      env: ['REGISTRY=${_REGISTRY}']
    81      args: [pull-build-image]
    82      waitFor:
    83        - build-make-docker
    84  
    85    #
    86    # pull the sdk base image, if it exists
    87    #
    88    - name: make-docker
    89      id: pull-build-sdk-base-image
    90      dir: build
    91      env: ['REGISTRY=${_REGISTRY}']
    92      args: [pull-build-sdk-base-image]
    93      waitFor:
    94        - build-make-docker
    95  
    96    #
    97    # Ensure that there is the sdk base image, so that both tests
    98    # and build can use them
    99    #
   100    - name: make-docker
   101      id: ensure-build-sdk-image-base
   102      waitFor: [pull-build-sdk-base-image]
   103      dir: build
   104      args: [ensure-build-sdk-image-base]
   105  
   106    #
   107    # Preventing SDKs failure in CI
   108    #
   109    - name: make-docker
   110      id: test-gen-all-sdk-grpc
   111      waitFor: [ensure-build-sdk-image-base]
   112      dir: build
   113      args: [test-gen-all-sdk-grpc]
   114  
   115    #
   116    # Preventing Broken PR Merges in CI
   117    #
   118    - name: make-docker
   119      id: test-gen-crd-code
   120      waitFor: [pull-build-image]
   121      dir: build
   122      args: [test-gen-crd-code]
   123  
   124    #
   125    # Runs the linter -- but also builds the build image, if not able to download
   126    #
   127    - name: make-docker
   128      id: lint
   129      waitFor:
   130        - pull-build-image
   131        - test-gen-crd-code
   132        - test-gen-all-sdk-grpc
   133      dir: build
   134      args: [lint]  # pull the build image if it exists
   135  
   136    #
   137    # Push the build image, can run while we do other things.
   138    #
   139    - name: make-docker
   140      waitFor: [lint]
   141      dir: build
   142      env: ['REGISTRY=${_REGISTRY}']
   143      args: [push-build-image]  # push the build image (which won't do anything if it's already there)
   144  
   145    #
   146    # Push the sdk base build image, which can also run while we do other things
   147    #
   148    - name: make-docker
   149      waitFor: [ensure-build-sdk-image-base]
   150      dir: build
   151      env: ['REGISTRY=${_REGISTRY}']
   152      args: [push-build-sdk-base-image]
   153  
   154    #
   155    # Build all the images and sdks, and push them up to the repository
   156    #
   157    - name: make-docker
   158      id: build-images
   159      waitFor: [lint]
   160      dir: build
   161      env: ['REGISTRY=${_REGISTRY}']
   162      args: [-j, '4', build-images]
   163    - name: make-docker
   164      id: push-images
   165      waitFor: [build-images]
   166      dir: build
   167      env: ['REGISTRY=${_REGISTRY}']
   168      args: [-j, '4', push]
   169    - name: make-docker
   170      id: build-sdks
   171      waitFor:
   172        - lint
   173        - cpp-sdk-build-restore-cache
   174        - ensure-build-sdk-image-base
   175      dir: build
   176      args: [-j, '4', --output-sync=recurse, build-sdks]
   177  
   178    #
   179    # Example version checks
   180    #
   181    # - name: make-docker
   182    #   id: check-example-versions
   183    #   dir: build
   184    #   args: [check-example-versions]
   185    #   waitFor:
   186    #     - push-images
   187  
   188    #
   189    # Run the all the automated tests (except e2e) in parallel
   190    #
   191    - name: make-docker
   192      id: tests
   193      waitFor:
   194        - lint
   195        - ensure-build-sdk-image-base
   196        - htmltest-restore-cache
   197        - build-sdks
   198      dir: build
   199      args: [-j, '5', --output-sync=target, test]
   200  
   201    #
   202    # SDK conformance tests
   203    #
   204    - name: make-docker
   205      id: sdk-conformance
   206      dir: build
   207      env: ['REGISTRY=${_REGISTRY}']
   208      args: [-j, '5', --output-sync=target, run-sdk-conformance-tests]
   209      waitFor:
   210        - build-images
   211        - tests
   212  
   213    #
   214    # Site preview
   215    #
   216    - name: make-docker  # build a preview of the website
   217      id: site-static
   218      waitFor: [tests]
   219      dir: build
   220      args: [site-static-preview, site-gen-app-yaml, SERVICE=preview]
   221    # deploy the preview of the website; # don't promote, as it can cause failures
   222    # when two deploys try and promote at the same time.
   223    - name: gcr.io/cloud-builders/gcloud
   224      id: deploy-site-static
   225      waitFor: [site-static]
   226      dir: site
   227      args: [app, deploy, .app.yaml, --no-promote, --version=$SHORT_SHA]
   228      env:
   229        - GOPATH=/workspace/go
   230        - GO111MODULE=on
   231  
   232    #
   233    # End to end tests
   234    #
   235  
   236    # Build and Push upgrade test
   237    - name: make-docker
   238      id: push-upgrade-test
   239      dir: test/upgrade
   240      env: ['REGISTRY=${_REGISTRY}']
   241      args: [push]
   242      waitFor:
   243        - push-images
   244      timeout: 5400s  # 1.5h
   245  
   246    # Wait for us to be the oldest ongoing build before we run upgrade and e2e tests
   247    - name: gcr.io/google.com/cloudsdktool/cloud-sdk
   248      id: wait-to-become-leader
   249      waitFor: [push-images]
   250      script: |
   251        #!/usr/bin/env bash
   252        TS='date --utc +%FT%TZ'  # e.g. 2023-01-26T13:30:37Z
   253        echo "$(${TS}): Waiting to become oldest running build"
   254        while true; do
   255          # Filter to running builds with tag 'ci', which covers any builds running e2es.
   256          BUILD_FILTER="status=WORKING AND tags='ci'"
   257          OLDEST=$(gcloud builds list --filter "${BUILD_FILTER}" --format="value(id,startTime)" --sort-by=startTime --limit=1)
   258          echo "$(${TS}): Oldest is (id startTime): ${OLDEST}"
   259          if echo ${OLDEST} | grep -q "${BUILD_ID}"; then
   260            echo "$(${TS}): That's us, we're done!"
   261            break
   262          fi
   263          sleep 60
   264        done
   265      timeout: 10800s  # 3h - if you change this, change the global timeout as well
   266      env:
   267        - CLOUDSDK_CORE_PROJECT=$PROJECT_ID
   268        - BUILD_ID=$BUILD_ID
   269        - TRIGGER_NAME=$TRIGGER_NAME
   270  
   271    # Run the upgrade tests parallel, fail this step if any of the tests fail
   272    - name: gcr.io/google.com/cloudsdktool/cloud-sdk
   273      id: submit-upgrade-test-cloud-build
   274      script: |
   275        #!/usr/bin/env bash
   276        timeout 30m ./build/e2e_upgrade_test.sh ${_BASE_VERSION} ${PROJECT_ID} || echo "=== upgrade tests failed ==="
   277      env:
   278        - _BASE_VERSION=$_BASE_VERSION
   279        - PROJECT_ID=$PROJECT_ID
   280      waitFor:
   281        - wait-to-become-leader
   282        - push-upgrade-test
   283  
   284    # cancel all the orphan e2e test cloud builds, fail to cancel any of the build will fail this whole build
   285    - name: gcr.io/cloud-builders/gcloud
   286      id: cancel-orphan-e2e-tests
   287      waitFor: [wait-to-become-leader]
   288      script: |
   289        #!/usr/bin/env bash
   290        until gcloud builds list --ongoing --filter "tags:'e2e-test'" --format="value(id)" | xargs --no-run-if-empty gcloud builds cancel
   291        do
   292          echo "== encountered error; assuming retryable error and trying again =="
   293          sleep 5
   294        done
   295  
   296    # kick off the child e2e test cloud builds in parallel, fail this build if any of the child build fails
   297    - name: gcr.io/cloud-builders/gcloud
   298      id: submit-e2e-test-cloud-build
   299      entrypoint: bash
   300      args:
   301        - -c
   302        - |
   303          set -e
   304          set -o pipefail
   305          pids=()
   306          cloudProducts=("generic" "gke-autopilot")
   307          declare -A versionsAndRegions=( [1.31]=us-east1 [1.32]=us-west1 [1.33]=asia-east1 )
   308  
   309          # Keep in sync with the inverse of 'alpha' and 'beta' features in
   310          # pkg/util/runtime/features.go:featureDefaults
   311          featureWithGate="PlayerAllocationFilter=true&FleetAutoscaleRequestMetaData=true&PlayerTracking=true&CountsAndLists=false&RollingUpdateFix=false&PortRanges=false&PortPolicyNone=false&ScheduledAutoscaler=false&AutopilotPassthroughPort=false&GKEAutopilotExtendedDurationPods=false&SidecarContainers=true&WasmAutoscaler=true&Example=true"
   312          featureWithoutGate=""
   313  
   314          # Use this if specific feature gates can only be supported on specific Kubernetes versions.
   315          declare -A featureWithGateByVersion=( [1.31]="${featureWithGate}" [1.32]="${featureWithGate}" [1.33]="${featureWithGate}")
   316  
   317          for cloudProduct in ${cloudProducts[@]}
   318          do
   319            for version in "${!versionsAndRegions[@]}"
   320            do
   321              withGate=${featureWithGateByVersion[$version]}
   322              region=${versionsAndRegions[$version]}
   323              if [ $cloudProduct = generic ]
   324              then
   325                testCluster="standard-e2e-test-cluster-${version//./-}"
   326              else
   327                testCluster="gke-autopilot-e2e-test-cluster-${version//./-}"
   328              fi
   329              testClusterLocation="${region}"
   330              { stdbuf -oL -eL gcloud builds submit . --suppress-logs --config=./ci/e2e-test-cloudbuild.yaml \
   331                --substitutions _FEATURE_WITH_GATE=$withGate,_FEATURE_WITHOUT_GATE=$featureWithoutGate,_CLOUD_PRODUCT=$cloudProduct,_TEST_CLUSTER_NAME=$testCluster,_TEST_CLUSTER_LOCATION=$testClusterLocation,_REGISTRY=${_REGISTRY},_PARENT_COMMIT_SHA=${COMMIT_SHA},_PARENT_BUILD_ID=${BUILD_ID} \
   332                |& stdbuf -i0 -oL -eL grep -v " tarball " \
   333                |& stdbuf -i0 -oL -eL sed "s/^/${cloudProduct}-${version}: /"; } &
   334              pids+=($!)
   335            done
   336          done
   337  
   338          # If any of the subprocess exit with nonzero code, exit the main process and kill all subprocesses
   339          for pid in "${pids[@]}"; do
   340            if wait -n; then
   341              :
   342            else
   343              status=$?
   344              echo "One of the e2e test child cloud build exited with nonzero status $status. Aborting."
   345              for pid in "${pids[@]}"; do
   346                # Send a termination signal to all the children, and ignore errors
   347                # due to children that no longer exist.
   348                kill "$pid" 2> /dev/null || :
   349                echo "killed $pid"
   350              done
   351              exit "$status"
   352            fi
   353          done
   354          echo "all done"
   355      waitFor:
   356        - cancel-orphan-e2e-tests
   357  
   358    #
   359    # Store caches, to speed up subsequent builds (considerably)
   360    #
   361    - name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
   362      args:
   363        - --bucket=gs://$_CACHE_BUCKET
   364        - --key=$_CPP_SDK_BUILD_CACHE_KEY-$( checksum sdks/cpp/CMakeLists.txt )
   365        - --path=sdks/cpp/.build  # CPP SDK build
   366      id: cpp-sdk-build-save-cache
   367      waitFor:
   368        - build-sdks
   369    - name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
   370      args:
   371        - --bucket=gs://$_CACHE_BUCKET
   372        - --key=$_CPP_SDK_CONFORMANCE_CACHE_KEY-$( sdks/cpp/CMakeLists.txt )
   373        - --path=test/sdk/cpp/sdk  # CPP conformance test build
   374      id: cpp-sdk-conformance-save-cache
   375      waitFor:
   376        - sdk-conformance
   377    - name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
   378      args:
   379        - --bucket=gs://$_CACHE_BUCKET
   380        - --key=$_RUST_SDK_BUILD_CACHE_KEY-$( checksum test/sdk/rust/Cargo.toml )
   381        - --path=test/sdk/rust/.cargo  # Rust conformance test build
   382        - --path=test/sdk/rust/.cargo-targets
   383        - --no-clobber
   384      id: rust-build-save-cache
   385      waitFor:
   386        - sdk-conformance
   387    - name: us-docker.pkg.dev/$PROJECT_ID/ci/save_cache
   388      args:
   389        - --bucket=gs://$_CACHE_BUCKET
   390        - --key=$_HTMLTEST_CACHE_KEY
   391        - --path=site/tmp  # htmltest URL checks
   392      id: htmltest-save-cache
   393      waitFor:
   394        - tests
   395  
   396    #
   397    # Zip up artifacts and push to storage
   398    #
   399    - name: gcr.io/cloud-builders/gsutil
   400      waitFor: [build-sdks, tests]
   401      dir: sdks/cpp/.archives
   402      args: [-m, cp, '*.tar.gz', gs://agones-artifacts/cpp-sdk]
   403    - name: gcr.io/cloud-builders/gsutil
   404      waitFor: [build-images, tests]
   405      dir: cmd/sdk-server/bin
   406      args: [-m, cp, '*.zip', gs://agones-artifacts/sdk-server]
   407  
   408    #
   409    # Cleanup services "preview", "development", "default"
   410    #
   411    - name: gcr.io/cloud-builders/gcloud
   412      id: cleanup-services
   413      waitFor: [wait-to-become-leader]
   414      allowFailure: true
   415      entrypoint: bash
   416      args:
   417        - -c
   418        - |
   419          set -e
   420          set -o pipefail
   421          for service in preview development default; do
   422            echo "Cleaning up $service service..."
   423            gcloud app versions list --service=$service --filter="traffic_split<1" --sort-by=~last_deployed_time.datetime --format="table[no-heading](version.id)" | tail -n +50 | xargs --no-run-if-empty gcloud app versions delete --service=$service --quiet
   424          done
   425  
   426  substitutions:
   427    _BASE_VERSION: 1.53.0
   428    _CACHE_BUCKET: agones-build-cache
   429    _HTMLTEST_CACHE_KEY: htmltest-0.10.1
   430    _CPP_SDK_BUILD_CACHE_KEY: cpp-sdk-build
   431    _CPP_SDK_CONFORMANCE_CACHE_KEY: cpp-sdk-conformance
   432    _RUST_SDK_BUILD_CACHE_KEY: rust-sdk-build
   433    _REGISTRY: us-docker.pkg.dev/${PROJECT_ID}/ci
   434  tags: [ci, 'commit-${COMMIT_SHA}']
   435  timeout: 18000s  # 5h: 3h (wait-to-become-leader) + 1.5h (e2e timeout) + 0.5h (everything else)
   436  queueTtl: 259200s  # 72h
   437  images:
   438    - ${_REGISTRY}/agones-controller
   439    - ${_REGISTRY}/agones-extensions
   440    - ${_REGISTRY}/agones-sdk
   441    - ${_REGISTRY}/agones-ping
   442    - ${_REGISTRY}/agones-allocator
   443    - ${_REGISTRY}/agones-processor
   444  logsBucket: gs://agones-build-logs
   445  options:
   446    machineType: E2_HIGHCPU_32
   447    dynamic_substitutions: true