Skip to content

[WIP] Simplify publishing image and license attaching step #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions scripts/attach-license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -eu

# Ensure all required env vars are supplied.
for var in PRE_IMAGE FINAL_IMAGE ZONE LICENSE LICENSE_PROJECT_NAME; do
for var in PRE_IMAGE FINAL_IMAGE LICENSE LICENSE_PROJECT_NAME; do
if ! [[ -v "${var}" ]]; then
echo "${var} env variable is required"
exit 1
Expand All @@ -25,20 +25,10 @@ done

echo "==> Creating a new image with license attached"

readonly DISK_NAME="${PRE_IMAGE}-disk"
echo "--> Creating disk with the pre-image..."
gcloud beta compute disks create "${DISK_NAME}" \
--image="${PRE_IMAGE}" \
--zone="${ZONE}" \
--labels="auto=pre"

echo "--> Creating the image with license..."
gcloud beta compute images create "${FINAL_IMAGE}" \
--source-disk="${DISK_NAME}" \
--source-disk-zone="${ZONE}" \
gcloud compute images create "${FINAL_IMAGE}" \
--source-image="${PRE_IMAGE}" \
--licenses="https://www.googleapis.com/compute/v1/projects/${LICENSE_PROJECT_NAME}/global/licenses/${LICENSE}" \
--labels="auto=final"

echo "--> Deleting disk and pre-image..."
gcloud -q compute disks delete "${DISK_NAME}" --zone="${ZONE}"
echo "--> Deleting pre-image..."
gcloud -q compute images delete "${PRE_IMAGE}"
22 changes: 3 additions & 19 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -eu

# Ensure all required env vars are supplied.
for var in PROJECT FINAL_IMAGE ZONE PUBLISH_TO_PROJECT; do
for var in PROJECT FINAL_IMAGE PUBLISH_TO_PROJECT; do
if ! [[ -v "${var}" ]]; then
echo "${var} env variable is required"
exit 1
Expand All @@ -25,25 +25,9 @@ done

echo "==> Publishing image ${FINAL_IMAGE} to ${PUBLISH_TO_PROJECT}"

readonly DISK_NAME="${FINAL_IMAGE}-disk"

echo "--> Creating disk in the target project..."
gcloud beta compute disks create "${DISK_NAME}" \
--image="${FINAL_IMAGE}" \
--image-project="${PROJECT}" \
--zone="${ZONE}" \
--project="${PUBLISH_TO_PROJECT}" \
--labels="auto=publish"

echo "--> Creating image in the target project..."
gcloud compute images create "${FINAL_IMAGE}" \
--source-disk="${DISK_NAME}" \
--source-disk-zone="${ZONE}" \
--project="${PUBLISH_TO_PROJECT}"

echo "--> Deleting disk..."
gcloud -q compute disks delete "${DISK_NAME}" \
--zone="${ZONE}" \
--source-image="${FINAL_IMAGE}" \
--source-image-project="${PROJECT}" \
--project="${PUBLISH_TO_PROJECT}"

echo "==> Image ${FINAL_IMAGE} published to ${PUBLISH_TO_PROJECT}!"