|
| 1 | +# Copyright 2023 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +# timeout needs to be longer than the total run time, with some padding to allow |
| 17 | +# enough time to gracefully tear down resources. Otherwise if Cloud Build aborts |
| 18 | +# a build in the middle of Packer or Terraform GCP resources will be left behind. |
| 19 | +timeout: 18000s # 5h |
| 20 | + |
| 21 | +substitutions: |
| 22 | + _REGION: ${LOCATION} |
| 23 | + _ZONE: ${LOCATION}-a |
| 24 | + _NETWORK: projects/${PROJECT_ID}/global/networks/default |
| 25 | + _SUBNETWORK: projects/${PROJECT_ID}/regions/${_REGION}/subnetworks/default |
| 26 | + _WORKER_POOL: "" |
| 27 | + |
| 28 | + # This is to support running the various tests (e.g. smoke tests) with an |
| 29 | + # existing image. Useful when developing the tests themselves. |
| 30 | + # At the moment the image build step is unconditional, so you'll need to |
| 31 | + # comment out the image build step while developing tests. |
| 32 | + _IMAGE_NAME: nfs-test-${BUILD_ID} |
| 33 | + |
| 34 | +options: |
| 35 | + dynamicSubstitutions: true |
| 36 | + pool: |
| 37 | + name: ${_WORKER_POOL} |
| 38 | + env: |
| 39 | + - CI=cloudbuild |
| 40 | + - PROJECT_ID=${PROJECT_ID} |
| 41 | + - REGION=${_REGION} |
| 42 | + - ZONE=${_ZONE} |
| 43 | + - NETWORK=${_NETWORK} |
| 44 | + - SUBNETWORK=${_SUBNETWORK} |
| 45 | + - BUILD_ID=${BUILD_ID} |
| 46 | + - IMAGE_NAME=${_IMAGE_NAME} |
| 47 | + |
| 48 | +steps: |
| 49 | + - name: golang:1.20 |
| 50 | + id: filter-exports:test |
| 51 | + dir: image/resources/filter-exports |
| 52 | + script: make test |
| 53 | + waitFor: ['-'] |
| 54 | + timeout: 1200s # 20m |
| 55 | + |
| 56 | + - name: golang:1.20 |
| 57 | + id: knfsd-agent:test |
| 58 | + dir: image/resources/knfsd-agent |
| 59 | + script: make test |
| 60 | + waitFor: ['-'] |
| 61 | + timeout: 1200s # 20m |
| 62 | + |
| 63 | + - name: golang:1.20 |
| 64 | + id: knfsd-metrics-agent:test |
| 65 | + dir: image/resources/knfsd-metrics-agent |
| 66 | + script: make test |
| 67 | + waitFor: ['-'] |
| 68 | + timeout: 1200s # 20m |
| 69 | + |
| 70 | + - name: golang:1.20 |
| 71 | + id: netapp-exports:test |
| 72 | + dir: image/resources/netapp-exports |
| 73 | + script: make test |
| 74 | + waitFor: ['-'] |
| 75 | + timeout: 1200s # 20m |
| 76 | + |
| 77 | + - name: golang:1.20 |
| 78 | + id: mig-scaler:test |
| 79 | + dir: tools/mig-scaler |
| 80 | + script: make test |
| 81 | + waitFor: ['-'] |
| 82 | + timeout: 1200s # 20m |
| 83 | + |
| 84 | + |
| 85 | + - name: gcr.io/cloud-builders/docker |
| 86 | + id: knfsd-fsidd:database-up |
| 87 | + dir: image/resources/knfsd-fsidd |
| 88 | + script: ./test.sh up |
| 89 | + waitFor: ['-'] |
| 90 | + timeout: 1200s # 20m |
| 91 | + |
| 92 | + - name: golang:1.20 |
| 93 | + id: knfsd-fsidd:test |
| 94 | + dir: image/resources/knfsd-fsidd |
| 95 | + script: ./test.sh run |
| 96 | + waitFor: ['knfsd-fsidd:database-up'] |
| 97 | + timeout: 1200s # 20m |
| 98 | + |
| 99 | + - name: gcr.io/cloud-builders/docker |
| 100 | + id: knfsd-fsidd:database-down |
| 101 | + dir: image/resources/knfsd-fsidd |
| 102 | + script: ./test.sh down |
| 103 | + waitFor: ['knfsd-fsidd:test'] |
| 104 | + timeout: 1200s # 20m |
| 105 | + |
| 106 | + # For a production build you would want to set an image_family, and use a more |
| 107 | + # readable image_name (if you leave image_name blank packer will default it to |
| 108 | + # "{image_family}-{timestamp}"). |
| 109 | + # Using BUILD_ID for test images to easily associate a test image with a |
| 110 | + # specific build. Though this isn't very useful in normal use as BUILD_ID is |
| 111 | + # just a random UUID. |
| 112 | + # Not using an image_family for the test builds, as you wouldn't want to |
| 113 | + # deploy the latest test build. It might be the latest main or the latest pull |
| 114 | + # request, who knows? |
| 115 | + # If you wanted to run these tests yourself as part of CI/CD before releasing |
| 116 | + # an image for general use, to avoid building the image twice, once the tests |
| 117 | + # are complete you could copy the image to a proper image_family and more |
| 118 | + # usable name (such as using a timestamp or version tag). |
| 119 | + - name: hashicorp/packer:1.9 |
| 120 | + id: knfsd-image:build |
| 121 | + script: | |
| 122 | + packer init image && |
| 123 | + packer build \ |
| 124 | + -var-file=image/cloudbuild.pkrvars.hcl \ |
| 125 | + -var project=${PROJECT_ID} \ |
| 126 | + -var zone=${ZONE} \ |
| 127 | + -var build_instance_name=nfs-build-${BUILD_ID} \ |
| 128 | + -var image_family="" \ |
| 129 | + -var image_name=${IMAGE_NAME} \ |
| 130 | + -var subnetwork=${SUBNETWORK} \ |
| 131 | + image |
| 132 | + timeout: 7200s # 2h |
| 133 | + |
| 134 | + - name: ${_DOCKER_REPOSITORY}/knfsd-terratest:1.0 |
| 135 | + id: knfsd-image:test |
| 136 | + dir: image/smoke-tests |
| 137 | + script: make test |
| 138 | + env: |
| 139 | + - TF_VAR_project=${PROJECT_ID} |
| 140 | + - TF_VAR_region=${_REGION} |
| 141 | + - TF_VAR_zone=${_ZONE} |
| 142 | + - TF_VAR_network=${_NETWORK} |
| 143 | + - TF_VAR_subnetwork=${_SUBNETWORK} |
| 144 | + - TF_VAR_proxy_image=${_IMAGE_NAME} |
| 145 | + timeout: 3600s # 1h |
| 146 | + |
| 147 | + - name: ${_DOCKER_REPOSITORY}/knfsd-terratest:1.0 |
| 148 | + id: examples:tests |
| 149 | + dir: testing/examples |
| 150 | + script: make test |
| 151 | + env: |
| 152 | + - TF_VAR_project=${PROJECT_ID} |
| 153 | + - TF_VAR_region=${_REGION} |
| 154 | + - TF_VAR_zone=${_ZONE} |
| 155 | + - TF_VAR_network=${_NETWORK} |
| 156 | + - TF_VAR_subnetwork=${_SUBNETWORK} |
| 157 | + - TF_VAR_proxy_image=${_IMAGE_NAME} |
| 158 | + - TF_VAR_proxy_service_account=${_PROXY_SERVICE_ACCOUNT} |
| 159 | + timeout: 3600s # 1h |
0 commit comments