Skip to content

Instantly share code, notes, and snippets.

@sigma
Created February 5, 2015 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sigma/0d5fcf9d85b8b7a050e0 to your computer and use it in GitHub Desktop.
Save sigma/0d5fcf9d85b8b7a050e0 to your computer and use it in GitHub Desktop.
#coreos build script
#!/bin/bash
MANIFEST_URL=${MANIFEST_URL:-https://github.com/coreos/manifest.git}
MANIFEST_REF=${MANIFEST_REF:-master}
MANIFEST_LAYOUT=${MANIFEST_LAYOUT:-minilayout}
MANIFEST_NAME=${MANIFEST_NAME:-release.xml}
BUILD_ID=${BUILD_ID:-`date +%s`}
CORE_PASSWD=${CORE_PASSWD:-plop}
GOOGLE_ZONE=us-central1-b
GOOGLE_MACHINE=n1-highcpu-2
GOOGLE_PROJECT_ID=ultra-mediator-842
GOOGLE_IMAGE=debian-7-backports
GOOGLE_BUCKET=sigma-coreos-builds
GOOGLE_GS_RW=https://www.googleapis.com/auth/devstorage.full_control
GOOGLE_GE_RW=https://www.googleapis.com/auth/compute
STARTUP_SCRIPT=`mktemp`
function cleanup {
rm -f "$STARTUP_SCRIPT"
}
trap cleanup EXIT
cat > "$STARTUP_SCRIPT" <<EOF
#!/bin/bash
apt-get update
apt-get install -y git bzip2
git config --global user.email builder@example.com
git config --global user.name Builder
su - $USER -c "git config --global user.email builder@example.com"
su - $USER -c "git config --global user.name Builder"
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
mkdir coreos; cd coreos
../depot_tools/repo init -u $MANIFEST_URL -b $MANIFEST_REF -g $MANIFEST_LAYOUT -m $MANIFEST_NAME --repo-url https://chromium.googlesource.com/external/repo.git
../depot_tools/repo sync
chown -R $USER .
# download the sdk and return, to give us the opportunity to generate
# a build script in the chroot
su - $USER -c "/coreos/chromite/bin/cros_sdk /bin/true"
# script the actual build. we need to put this in the chroot to be able to call it
cat > chroot/batch_build.sh <<PLOP
#!/bin/bash
./set_shared_user_password.sh $CORE_PASSWD
echo amd64-usr > .default_board
./setup_board
./build_packages
./build_image --noenable_rootfs_verification prod
./image_to_vm.sh --format vmware_ova --from=../build/images/amd64-usr/latest --board=amd64-usr --prod_image
PLOP
chmod a+x chroot/batch_build.sh
# perform build with sdk. note that path to batch_build.sh is inside the chroot
su - $USER -c "/coreos/chromite/bin/cros_sdk /batch_build.sh"
# copy build artifacts to google storage. right now, only interested in OVAs
gsutil cp src/build/images/amd64-usr/latest/*.ova gs://$GOOGLE_BUCKET/$BUILD_ID/
# have the instance kill itself for good measure
gcloud compute instances delete builder-$BUILD_ID --zone $GOOGLE_ZONE -q
EOF
gcloud compute instances create builder-$BUILD_ID \
--scopes "$GOOGLE_GS_RW" "$GOOGLE_GE_RW" --image "$GOOGLE_IMAGE" \
--metadata-from-file startup-script="$STARTUP_SCRIPT" \
--zone "$GOOGLE_ZONE" --machine-type "$GOOGLE_MACHINE" \
--project "$GOOGLE_PROJECT_ID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment