copy-e2e-image.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. # Copyright 2016 The Kubernetes Authors.
  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. # Usage: copy-e2e-image.sh <image-name> <from-project-name> <to-project-name>
  16. # See *.properties for list of images to copy,
  17. # typically from kubernetes-node-e2e-images
  18. set -e
  19. print_usage() {
  20. echo "This script helps copy a GCE image from a source to a target project"
  21. echo -e "\nUsage:\n$0 <from-image-name> <from-project-name> <to-project-name> <to-image-name>\n"
  22. }
  23. if [ $# -ne 4 ]; then
  24. print_usage
  25. exit 1
  26. fi
  27. FROM_IMAGE=$1
  28. FROM_PROJECT=$2
  29. TO_PROJECT=$3
  30. TO_IMAGE=$4
  31. echo "Copying image $FROM_IMAGE from project $FROM_PROJECT to project $TO_PROJECT as image $TO_IMAGE..."
  32. gcloud compute --project "${TO_PROJECT}" disks create "${TO_IMAGE}" --image=https://www.googleapis.com/compute/v1/projects/"${FROM_PROJECT}/global/images/""${FROM_IMAGE}"
  33. gcloud compute --project "${TO_PROJECT}" images create "${TO_IMAGE}" \
  34. --source-disk="${TO_IMAGE}" \
  35. --description="Cloned from projects/$2/global/images/$1 by $USER on $(date)"
  36. gcloud -q compute --project "${TO_PROJECT}" disks delete "${TO_IMAGE}"