From c433229deda36f77ada944ce3b46eb3832e0bd87 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Tue, 13 Jan 2015 16:41:09 -0800 Subject: [PATCH] Revert "Revert "Make a script to run all builds in parallel"" This reverts commit 5a65a48d8a9a3487a6ae537cd34a9ac08196ac06. --- .../publish-meteor-tool-on-all-platforms.sh | 106 ++----------- scripts/admin/publish-meteor-tool-on-arch.sh | 149 ++++++++++++++++++ 2 files changed, 158 insertions(+), 97 deletions(-) create mode 100755 scripts/admin/publish-meteor-tool-on-arch.sh diff --git a/scripts/admin/publish-meteor-tool-on-all-platforms.sh b/scripts/admin/publish-meteor-tool-on-all-platforms.sh index e28af4e3f6..8e3e5aacb0 100755 --- a/scripts/admin/publish-meteor-tool-on-all-platforms.sh +++ b/scripts/admin/publish-meteor-tool-on-all-platforms.sh @@ -40,110 +40,22 @@ main () { trap - EXIT + screen -D -RR -m -S buildMeteor - UNIX_PLATFORMS=( os.osx.x86_64 os.linux.x86_64 os.linux.x86_32 ) - WINDOWS_PLATFORMS=( os.windows.x86_32 os.windows.x86_64 ) + i=0 + PLATFORMS=( os.osx.x86_64 os.linux.x86_64 os.linux.x86_32 os.windows.x86_32 os.windows.x86_64 ) + for PLATFORM in ${PLATFORMS[@]}; do + COMMAND="`dirname $0`/publish-meteor-tool-on-arch.sh $GITSHA $PLATFORM $SESSION_FILE" + screen -S buildMeteor -X screen + screen -S buildMeteor -p $i -X exec $COMMAND - echo "${green}Publishing from unixy platforms.${NC}" - for PLATFORM in ${UNIX_PLATFORMS[@]}; do - parse_keys - - echo "${green}Going to ssh into machine running $PLATFORM and publish the release${NC}" - trap 'echo "${red}Failed to publish from $PLATFORM${NC}"; clean_up' EXIT - # copy the meteor session file to the remote host - scp -oUserKnownHostsFile=$TEMP_KEY -P $PORT -i $TEMP_PRIV_KEY -q $SESSION_FILE $USERNAME@$HOST:~/session - - $METEOR admin get-machine $PLATFORM --minutes 20 <<'END' -set -e -set -u -if [ -d meteor ]; then - rm -rf meteor -fi -git clone https://github.com/meteor/meteor.git -cd meteor -git fetch --tags -END - - # checkout the SHA1 we want to publish - echo "cd meteor; git checkout $GITSHA" | $METEOR admin get-machine $PLATFORM --minutes 20 - # publish the release - echo "cd meteor/packages/meteor-tool && env METEOR_SESSION_FILE=~/session ../../meteor publish --existing-version" | $METEOR admin get-machine $PLATFORM --minutes 20 - - trap - EXIT + (( i++ )) done - echo "${green}Publishing from Windowsy platforms.${NC}" - for PLATFORM in ${WINDOWS_PLATFORMS[@]}; do - parse_keys - - echo "${green}Going to ssh into machine running $PLATFORM and publish the release${NC}" - trap 'echo "${red}Failed to publish from $PLATFORM${NC}"; clean_up' EXIT - - # copy the meteor session file to the remote host - SESSION_CONTENT=$(cat $SESSION_FILE | tr '\n' ' ') - ssh $USERNAME@$HOST -oUserKnownHostsFile=$TEMP_KEY -p $PORT -i $TEMP_PRIV_KEY "cmd /c echo $SESSION_CONTENT > C:\\meteor-session" - - # checkout the SHA1 we want to publish and publish it - SCRIPT="( \ -IF EXIST C:\\tmp ( rmdir /s /q C:\\tmp ) && \ -md C:\\tmp && \ -cd C:\\tmp && \ -C:\\git\\bin\\git.exe clone https://github.com/meteor/meteor.git && \ -cd meteor && \ -C:\\git\\bin\\git.exe fetch --tags && \ -C:\\git\\bin\\git.exe checkout $GITSHA && \ -cd C:\\tmp\\meteor\\packages\\meteor-tool && \ -set METEOR_SESSION_FILE=C:\\meteor-session && \ -rem install 7zip && \ -C:\\git\\bin\\curl -L http://downloads.sourceforge.net/sevenzip/7z920-x64.msi > - C:\\7z.msi && \ -msiexec /i C:\\7z.msi /quiet /qn /norestart && \ -set PATH=%PATH%;\"C:\\Program Files\\7-zip\" && \ -rem allow powershell script execution && \ -powershell \"Set-ExecutionPolicy RemoteSigned\" && \ -..\\..\\meteor.bat publish --existing-version \ -) || exit 1 \ -" - ssh $USERNAME@$HOST -oUserKnownHostsFile=$TEMP_KEY -p $PORT -i $TEMP_PRIV_KEY "cmd /c $SCRIPT" - - trap - EXIT - done -} - -# get keys from "meteor admin get-machine" command -parse_keys () { - trap 'echo "${red}Failed to parse the machine credentials${NC}";clean_up' EXIT - CREDS=$($METEOR admin get-machine $PLATFORM --json --minutes 20) - - # save host key and login private key to temp files - echo $CREDS | get_from_json "key" > $CHECKOUT_DIR/temp_priv_key - TEMP_PRIV_KEY=$CHECKOUT_DIR/temp_priv_key - chmod 600 $TEMP_PRIV_KEY - - USERNAME=$(echo $CREDS | get_from_json "username") - HOST=$(echo $CREDS | get_from_json "host") - PORT=$(echo $CREDS | get_from_json "port") - echo -n "$HOST " > $CHECKOUT_DIR/temp_key - echo $CREDS | get_from_json "hostKey" >> $CHECKOUT_DIR/temp_key - TEMP_KEY=$CHECKOUT_DIR/temp_key - - trap - EXIT -} - -# print a value from a JSON file by key -get_from_json () { - "$CHECKOUT_DIR/dev_bundle/bin/node" -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin').toString())['$1'])" + clean_up } clean_up () { - if [[ x$TEMP_KEY != x ]]; then - echo "Removing remaining keys" - rm $TEMP_KEY - fi - if [[ x$TEMP_KEY != x ]]; then - rm $TEMP_PRIV_KEY - fi - if [[ x$SESSION_FILE != x ]]; then echo "Removing used session file." rm $SESSION_FILE diff --git a/scripts/admin/publish-meteor-tool-on-arch.sh b/scripts/admin/publish-meteor-tool-on-arch.sh new file mode 100755 index 0000000000..c9df41d217 --- /dev/null +++ b/scripts/admin/publish-meteor-tool-on-arch.sh @@ -0,0 +1,149 @@ +#!/bin/bash + +# This scripts automates the release process of Meteor Tool. + +# Normally, after publishing a new Meteor release from checkout, you need to ssh +# to a machine running every supported platform and publish a build from it. +# This script automates ssh'ing into machines and running the publish command. + +set -e +set -u + +TEMP_PRIV_KEY= +TEMP_KEY= +SESSION_FILE= + +main () { + if [ $# -ne 3 ]; then + echo "usage: $0 " 1>&2 + echo "The passed sha1 is checked out and published from the machines." 1>&2 + echo "Options for platform:" 1>&2 + echo " os.osx.x86_64 os.linux.x86_64 os.linux.x86_32" 1>&2 + echo " os.windows.x86_32 os.windows.x86_64" 1>&2 + exit 1 + fi + + GITSHA=$1 + PLATFORM=$2 + SESSION_FILE=$3 + + ADMIN_DIR="`dirname "$0"`" + SCRIPTS_DIR="`dirname "$ADMIN_DIR"`" + CHECKOUT_DIR="`dirname "$SCRIPTS_DIR"`" + + METEOR="$CHECKOUT_DIR/meteor" + + UNIX_PLATFORMS=( os.osx.x86_64 os.linux.x86_64 os.linux.x86_32 ) + WINDOWS_PLATFORMS=( os.windows.x86_32 os.windows.x86_64 ) + + if [[ $PLATFORM =~ ^(os\.linux|os\.osx) ]] ; then + echo "${green}Publishing from unixy platform.${NC}" + + parse_keys + + echo "${green}Going to ssh into machine running $PLATFORM and publish the release${NC}" + trap 'echo "${red}Failed to publish from $PLATFORM${NC}"; clean_up' EXIT + # copy the meteor session file to the remote host + scp -oUserKnownHostsFile=$TEMP_KEY -P $PORT -i $TEMP_PRIV_KEY -q $SESSION_FILE $USERNAME@$HOST:~/session + + $METEOR admin get-machine $PLATFORM <<'END' +set -e +set -u +if [ -d meteor ]; then + rm -rf meteor +fi +git clone https://github.com/meteor/meteor.git +cd meteor +git fetch --tags +END + + # checkout the SHA1 we want to publish + echo "cd meteor; git checkout $GITSHA" | $METEOR admin get-machine $PLATFORM + # publish the release + echo "cd meteor/packages/meteor-tool && env METEOR_SESSION_FILE=~/session ../../meteor publish --existing-version" | $METEOR admin get-machine $PLATFORM + + trap - EXIT + else + echo "${green}Publishing from Windowsy platform.${NC}" + + parse_keys + + echo "${green}Going to ssh into machine running $PLATFORM and publish the release${NC}" + trap 'echo "${red}Failed to publish from $PLATFORM${NC}"; clean_up' EXIT + + # copy the meteor session file to the remote host + SESSION_CONTENT=$(cat $SESSION_FILE | tr '\n' ' ') + ssh $USERNAME@$HOST -oUserKnownHostsFile=$TEMP_KEY -p $PORT -i $TEMP_PRIV_KEY "cmd /c echo $SESSION_CONTENT > C:\\meteor-session" + + # checkout the SHA1 we want to publish and publish it + SCRIPT="( \ +IF EXIST C:\\tmp ( rmdir /s /q C:\\tmp ) && \ +md C:\\tmp && \ +cd C:\\tmp && \ +C:\\git\\bin\\git.exe clone https://github.com/meteor/meteor.git && \ +cd meteor && \ +C:\\git\\bin\\git.exe fetch --tags && \ +C:\\git\\bin\\git.exe checkout $GITSHA && \ +cd C:\\tmp\\meteor\\packages\\meteor-tool && \ +set METEOR_SESSION_FILE=C:\\meteor-session && \ +rem install 7zip && \ +C:\\git\\bin\\curl -L http://downloads.sourceforge.net/sevenzip/7z920-x64.msi > + C:\\7z.msi && \ +msiexec /i C:\\7z.msi /quiet /qn /norestart && \ +set PATH=%PATH%;\"C:\\Program Files\\7-zip\" && \ +rem allow powershell script execution && \ +powershell \"Set-ExecutionPolicy RemoteSigned\" && \ +..\\..\\meteor.bat publish --existing-version \ +) || exit 1 \ +" + ssh $USERNAME@$HOST -oUserKnownHostsFile=$TEMP_KEY -p $PORT -i $TEMP_PRIV_KEY "cmd /c $SCRIPT" + + trap - EXIT + fi + + clean_up +} + +# get keys from "meteor admin get-machine" command +parse_keys () { + trap 'echo "${red}Failed to parse the machine credentials${NC}";clean_up' EXIT + CREDS=$($METEOR admin get-machine $PLATFORM --json) + + # save host key and login private key to temp files + echo $CREDS | get_from_json "key" > $CHECKOUT_DIR/temp_priv_key + TEMP_PRIV_KEY=$CHECKOUT_DIR/temp_priv_key + chmod 600 $TEMP_PRIV_KEY + + USERNAME=$(echo $CREDS | get_from_json "username") + HOST=$(echo $CREDS | get_from_json "host") + PORT=$(echo $CREDS | get_from_json "port") + echo -n "$HOST " > $CHECKOUT_DIR/temp_key + echo $CREDS | get_from_json "hostKey" >> $CHECKOUT_DIR/temp_key + TEMP_KEY=$CHECKOUT_DIR/temp_key + + trap - EXIT +} + +# print a value from a JSON file by key +get_from_json () { + "$CHECKOUT_DIR/dev_bundle/bin/node" -e "console.log(JSON.parse(require('fs').readFileSync('/dev/stdin').toString())['$1'])" +} + +clean_up () { + if [[ x$TEMP_KEY != x ]]; then + echo "Removing remaining keys" + rm $TEMP_KEY + fi + if [[ x$TEMP_KEY != x ]]; then + rm $TEMP_PRIV_KEY + fi + + exit 1 +} + +red=`tput setaf 1` +green=`tput setaf 2` +NC=`tput sgr0` + +main $@ +