github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/contrib/cirrus/build_vm_images.sh (about) 1 #!/bin/bash 2 3 set -e 4 source $(dirname $0)/lib.sh 5 6 BASE_IMAGE_VARS='FEDORA_BASE_IMAGE PRIOR_FEDORA_BASE_IMAGE UBUNTU_BASE_IMAGE PRIOR_UBUNTU_BASE_IMAGE' 7 ENV_VARS="PACKER_BUILDS BUILT_IMAGE_SUFFIX $BASE_IMAGE_VARS SERVICE_ACCOUNT GCE_SSH_USERNAME GCP_PROJECT_ID PACKER_VER SCRIPT_BASE PACKER_BASE CIRRUS_BUILD_ID CIRRUS_CHANGE_IN_REPO" 8 req_env_var $ENV_VARS 9 # Must also be made available through make, into packer process 10 export $ENV_VARS 11 12 # Everything here is running on the 'image-builder-image' GCE image 13 # Assume basic dependencies are all met, but there could be a newer version 14 # of the packer binary 15 PACKER_FILENAME="packer_${PACKER_VER}_linux_amd64.zip" 16 if [[ -d "$HOME/packer" ]] 17 then 18 cd "$HOME/packer" 19 # image_builder_image has packer pre-installed, check if same version requested 20 if [[ -r "$PACKER_FILENAME" ]] 21 then 22 cp $PACKER_FILENAME "$GOSRC/$PACKER_BASE/" 23 cp packer "$GOSRC/$PACKER_BASE/" 24 fi 25 fi 26 27 cd "$GOSRC/$PACKER_BASE" 28 # Add/update labels on base-images used in this build to prevent premature deletion 29 ARGS=" 30 " 31 for base_image_var in $BASE_IMAGE_VARS 32 do 33 # See entrypoint.sh in contrib/imgts and contrib/imgprune 34 # These updates can take a while, run them in the background, check later 35 gcloud compute images update \ 36 --update-labels=last-used=$(date +%s) \ 37 --update-labels=build-id=$CIRRUS_BUILD_ID \ 38 --update-labels=repo-ref=$CIRRUS_CHANGE_IN_REPO \ 39 --update-labels=project=$GCP_PROJECT_ID \ 40 ${!base_image_var} & 41 done 42 43 make libpod_images \ 44 PACKER_BUILDS=$PACKER_BUILDS \ 45 PACKER_VER=$PACKER_VER \ 46 GOSRC=$GOSRC \ 47 SCRIPT_BASE=$SCRIPT_BASE \ 48 PACKER_BASE=$PACKER_BASE \ 49 BUILT_IMAGE_SUFFIX=$BUILT_IMAGE_SUFFIX 50 51 # Separate PR-produced images from those produced on master. 52 if [[ "${CIRRUS_BRANCH:-}" == "master" ]] 53 then 54 POST_MERGE_BUCKET_SUFFIX="-master" 55 else 56 POST_MERGE_BUCKET_SUFFIX="" 57 fi 58 59 # When successful, upload manifest of produced images using a filename unique 60 # to this build. 61 URI="gs://packer-import${POST_MERGE_BUCKET_SUFFIX}/manifest${BUILT_IMAGE_SUFFIX}.json" 62 gsutil cp packer-manifest.json "$URI" 63 64 # Ensure any background 'gcloud compute images update' processes finish 65 wait # No -n option in CentOS, this is the best that can be done :( 66 67 echo "Finished. A JSON manifest of produced images is available at $URI"