aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Edwards <jeremyedwards@google.com>2014-08-08 11:01:21 -0700
committerJeremy Edwards <jeremyedwards@google.com>2014-08-08 11:01:21 -0700
commit58778d6339c077862e62720a600c6341e0f6bfa2 (patch)
treeea56be45ba2e51ee4a85a18afbdf71ff8a4966ac
parent9fab134a7408c1d6edb46b7735e95f0d03e1a3e6 (diff)
downloadcompute-archlinux-image-builder-58778d6339c077862e62720a600c6341e0f6bfa2.tar.xz
Added deploy VM to build image scripts.
-rwxr-xr-xbuild-arch-on-gce-remote.sh52
-rwxr-xr-xbuild-arch-on-gce.sh76
2 files changed, 128 insertions, 0 deletions
diff --git a/build-arch-on-gce-remote.sh b/build-arch-on-gce-remote.sh
new file mode 100755
index 0000000..07df13f
--- /dev/null
+++ b/build-arch-on-gce-remote.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Copyright 2014 Google Inc. All Rights Reserved.
+#
+# 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.
+
+# Build an Arch Linux image from within a GCE Debian VM.
+
+BUILDER_ROOT=/mnt/archongce/source
+INSTANCE_NAME=$(/usr/share/google/get_metadata_value attributes/instance-name)
+ZONE_NAME=$(/usr/share/google/get_metadata_value attributes/instance-zone)
+SCRIPT_PARAMS=$(/usr/share/google/get_metadata_value attributes/script-params)
+SCRIPT_PARAMS="--verbose --register ${SCRIPT_PARAMS}"
+GIT_SOURCE_URI=$(/usr/share/google/get_metadata_value attributes/git-source-uri)
+REMOTE_IMAGE=$(echo "i = '${SCRIPT_PARAMS}'.split(); print i[i.index('--upload') + 1]" | python)
+
+echo "Builder Root: ${BUILDER_ROOT}"
+echo "Instance Name: ${INSTANCE_NAME}"
+echo "Instance Zone: ${ZONE_NAME}"
+echo "Source Git Repository: ${GIT_SOURCE_URI}"
+echo "Remote Image: ${REMOTE_IMAGE}"
+echo "Running script as:"
+echo " ./build-gce-arch.py ${SCRIPT_PARAMS}"
+
+echo "Setup Builder Environment"
+mkdir -p ${BUILDER_ROOT}
+
+echo "Updating Cloud SDK"
+yes | gcloud components update
+
+echo "Installing Dependencies"
+sudo apt-get install -y -qq python3 haveged git
+
+echo "Getting source code..."
+git clone ${GIT_SOURCE_URI} ${BUILDER_ROOT}
+
+cd ${BUILDER_ROOT}
+haveged -w 1024
+gsutil rm ${REMOTE_IMAGE}
+./build-gce-arch.py ${SCRIPT_PARAMS}
+cat /var/log/syslog | grep -o "startupscript.*" > builder.log
+gsutil cp builder.log ${REMOTE_IMAGE}.log
+gcloud compute -q instances delete ${INSTANCE_NAME} --zone ${ZONE_NAME}
diff --git a/build-arch-on-gce.sh b/build-arch-on-gce.sh
new file mode 100755
index 0000000..d1122e2
--- /dev/null
+++ b/build-arch-on-gce.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+# Copyright 2014 Google Inc. All Rights Reserved.
+#
+# 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.
+
+# Creates a Debian VM to build an Arch Linux image.
+
+INSTANCE_ID=${RANDOM}
+INSTANCE_NAME=archbuilder${INSTANCE_ID}
+ZONE_NAME=us-central1-f
+MACHINE_TYPE=n1-standard-2
+GIT_SOURCE_URI=https://github.com/GoogleCloudPlatform/compute-archlinux-image-builder.git
+SCRIPT_PARAMS="$*"
+
+function GcloudNotConfiguredHelp() {
+ echo "gcloud is missing or project is not set."
+ echo "Run these commands:"
+ echo " gcloud auth login"
+ echo " gcloud config set project <project>"
+ echo ""
+ echo "To install Cloud SDK go here: https://developers.google.com/cloud/sdk/"
+}
+
+function MissingRequiredFlagsHelp() {
+ echo "--upload parameter is required to build on VM."
+ echo "Example: --upload gs://cloud-storage-bucket/archlinux.tar.gz"
+ echo ""
+ echo "Cloud Storage Buckets already in your project:"
+ gsutil ls gs://
+}
+
+function PrintHelp() {
+ ./build-gce-arch.py --help
+}
+
+function DeployVm() {
+ echo "Creating Instance, ${INSTANCE_NAME}"
+ gcloud compute instances create ${INSTANCE_NAME} \
+ --image debian-7-backports \
+ --machine-type ${MACHINE_TYPE} \
+ --zone ${ZONE_NAME} \
+ --metadata-from-file startup-script=build-arch-on-gce-remote.sh \
+ --metadata \
+ script-params="${SCRIPT_PARAMS}" \
+ instance-name="${INSTANCE_NAME}" \
+ instance-zone="${ZONE_NAME}" \
+ git-source-uri="${GIT_SOURCE_URI}" \
+ --scopes compute-rw storage-full
+ echo "You can monitor progress of the build via:"
+ echo " gcloud compute instances get-serial-port-output ${INSTANCE_NAME} --zone ${ZONE_NAME} | grep startupscript"
+}
+
+
+GCLOUD_PROJECT_CONFIGURED=$(gcloud config list --all | grep project)
+if [ "${GCLOUD_PROJECT_CONFIGURED}" != "" ]; then
+ if [[ "${SCRIPT_PARAMS}" == *--help* ]]; then
+ PrintHelp
+ elif [[ "${SCRIPT_PARAMS}" == *--upload* ]]; then
+ echo "Creating VM to build Arch Linux"
+ DeployVm
+ else
+ MissingRequiredFlagsHelp
+ fi
+else
+ GcloudNotConfiguredHelp
+fi