| # Copyright 2021 Google LLC | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the License); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an AS IS BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| substitutions: | |
| '_ZONE': 'us-west1-b' | |
| '_TEST': 'ubuntu_ova_test' | |
| '_INPUT_IMAGE': 'https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.ova' | |
| '_SERVICE_ACCOUNT': 'compute@cloud-image-docker-builder.google.com.iam.gserviceaccount.com' | |
| '_COS_CUSTOMIZER': 'cos_customizer' | |
| steps: | |
| # Build cos-customizer and tools container | |
| - name: 'gcr.io/cloud-builders/docker' | |
| entrypoint: '/bin/bash' | |
| args: | |
| - '-c' | |
| - | | |
| if [[ ${_COS_CUSTOMIZER} == 'cos_customizer' ]]; then | |
| docker build -f src/cmd/cos_customizer/Dockerfile -t cos_customizer . | |
| fi | |
| - name: 'gcr.io/cloud-builders/docker' | |
| entrypoint: 'bash' | |
| args: | |
| - '-c' | |
| - | | |
| cat <<EOF| docker build -t tools - | |
| FROM ubuntu | |
| RUN apt-get update && apt-get install -y qemu-utils | |
| EOF | |
| # Download input | |
| - name: 'gcr.io/cloud-builders/wget' | |
| args: ['-O', 'input.ova', '${_INPUT_IMAGE}'] | |
| # Convert to GCE image | |
| - name: 'tools' | |
| entrypoint: 'bash' | |
| args: | |
| - '-c' | |
| - | | |
| set -e | |
| mkdir ova | |
| pushd ova | |
| mv ../input.ova . | |
| tar xf input.ova | |
| echo "Converting vmdk to disk.raw" | |
| qemu-img convert -O raw *.vmdk disk.raw | |
| tar czf ubuntu_gce.tar.gz disk.raw | |
| - name: 'gcr.io/cloud-builders/gsutil' | |
| args: ['cp', 'ova/ubuntu_gce.tar.gz', 'gs://${_PROJECT_NAME}_cloudbuild/build-ova-${BUILD_ID}/ubuntu_gce.tar.gz'] | |
| - name: 'gcr.io/cloud-builders/gcloud' | |
| args: ['compute', 'images', 'create', 'input-${BUILD_ID}', | |
| '--source-uri', 'gs://${_PROJECT_NAME}_cloudbuild/build-ova-${BUILD_ID}/ubuntu_gce.tar.gz', | |
| '--project', '${PROJECT_ID}'] | |
| - name: 'gcr.io/cloud-builders/gsutil' | |
| args: ['rm', 'gs://${_PROJECT_NAME}_cloudbuild/build-ova-${BUILD_ID}/ubuntu_gce.tar.gz'] | |
| # Run cos-customizer | |
| - name: '${_COS_CUSTOMIZER}' | |
| args: ['start-image-build', | |
| '-build-context=testing/${_TEST}', | |
| '-image-name=input-${BUILD_ID}', | |
| '-image-project=${PROJECT_ID}', | |
| '-gcs-bucket=${_PROJECT_NAME}_cloudbuild', | |
| '-gcs-workdir=customizer-$BUILD_ID'] | |
| - name: '${_COS_CUSTOMIZER}' | |
| args: ['run-script', | |
| '-script=preload.sh'] | |
| - name: '${_COS_CUSTOMIZER}' | |
| args: ['finish-image-build', | |
| '-zone=${_ZONE}', | |
| '-project=${PROJECT_ID}', | |
| '-image-name=preload-test-$BUILD_ID', | |
| '-image-project=${PROJECT_ID}', | |
| '-service-account=${_SERVICE_ACCOUNT}'] | |
| # Delete input image | |
| - name: 'gcr.io/cloud-builders/gcloud' | |
| args: ['compute', 'images', 'delete', 'input-${BUILD_ID}', '-q'] | |
| # Validate output image | |
| - name: 'gcr.io/compute-image-tools/daisy' | |
| args: ['-project=$PROJECT_ID', '-zone=${_ZONE}', '-var:image_name', | |
| 'preload-test-$BUILD_ID', '-var:image_project', '$PROJECT_ID', | |
| '-var:daisy_gcs_bucket', '${_PROJECT_NAME}-daisy-bkt', | |
| '-var:test_cfg', '../${_TEST}/preload_test.cfg', 'testing/util/run_test.wf.json'] | |
| options: | |
| machineType: 'N1_HIGHCPU_8' | |
| timeout: '7200s' |