From 8a3564451823735aef0c8d1d14417f0fbdf32ab4 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 9 Jan 2015 13:41:13 -0800 Subject: [PATCH] Implement tarball based installation * The base image contains only installer code. Installer code can only be changed with a base image change * The box code is download from s3 instead of git. The s3 tarball consists of node dependancies already Part of #115 --- installer/scripts/installer.sh | 30 +++++++--------- postinstall/postinstall.sh | 10 ++---- postinstall/setup_supervisord.sh | 8 +++-- release/publish.js | 2 +- release/versions-dev.json | 4 +-- scripts/createDigitalOceanImage.sh | 12 ++++--- scripts/initializeBaseUbuntuImage.sh | 52 ++++++---------------------- 7 files changed, 42 insertions(+), 76 deletions(-) diff --git a/installer/scripts/installer.sh b/installer/scripts/installer.sh index e3c064990..a49d01880 100755 --- a/installer/scripts/installer.sh +++ b/installer/scripts/installer.sh @@ -8,7 +8,7 @@ set -e set -x HOME_DIR="/home/yellowtent" -SRCDIR="$HOME_DIR/box" +BOX_SRCDIR="$HOME_DIR/box" CONFIG_DIR="$HOME_DIR/config" DATA_DIR="$HOME_DIR/data" CLOUDRON_SQLITE="$DATA_DIR/cloudron.sqlite" @@ -51,30 +51,26 @@ if [ -n "$PROVISION_RESTORE_URL" ]; then fi echo "Downloading box versions" -if [ "$PROVISION_VERSION" = "latest" ]; then - REVISION="origin/master" -else - while true; do - REVISION=$(curl --retry 5 --retry-delay 5 --max-time 120 -L "$PROVISION_BOX_VERSIONS_URL" | $JSON -D, "$PROVISION_VERSION,revision") - [ -n "$REVISION" ] && break - echo "Failed to download box versions, trying again" - done -fi -echo "Updating to revision : $REVISION" -cd "$SRCDIR" while true; do - timeout 3m git fetch origin && break - echo "git fetch timedout, trying again" - sleep 2 + SOURCE_TARBALL_URL=$(curl --retry 5 --retry-delay 5 --max-time 120 -L "$PROVISION_BOX_VERSIONS_URL" | $JSON -D, "$PROVISION_VERSION,sourceTarballUrl") + [ -n "$SOURCE_TARBALL_URL" ] && break + echo "Failed to download box versions, trying again" done -git reset --hard "$REVISION" +sudo -u yellowtent -H bash < /etc/supervisor/conf.d/box.conf < /etc/supervisor/conf.d/updater.conf < /root/installer.tar" + echo "Executing init script" -if ! ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $SCRIPT_DIR/ssh/id_rsa_yellowtent root@$DROPLET_IP "/bin/bash /root/initializeBaseUbuntuImage.sh $BOX_REVISION"; then +if ! ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $SCRIPT_DIR/ssh/id_rsa_yellowtent root@$DROPLET_IP "/bin/bash /root/initializeBaseUbuntuImage.sh $INSTALLER_REVISION"; then echo "Init script failed" exit 1 fi diff --git a/scripts/initializeBaseUbuntuImage.sh b/scripts/initializeBaseUbuntuImage.sh index ba93cd686..27d8031c9 100755 --- a/scripts/initializeBaseUbuntuImage.sh +++ b/scripts/initializeBaseUbuntuImage.sh @@ -6,8 +6,8 @@ USER=yellowtent USER_HOME="/home/$USER" DATA_DIR="$USER_HOME/data" APPDATA=$DATA_DIR/appdata -SRCDIR=$USER_HOME/box -BOX_REVISION=$1 +INSTALLER_SOURCE_DIR=$USER_HOME/installer +INSTALLER_REVISION=$1 echo "==== Create User $USER ====" id $USER @@ -19,7 +19,7 @@ fi # now exit on failure set -e -echo "== Yellowtent base image preparation ($BOX_REVISION) ==" +echo "== Yellowtent base image preparation (installer revision - $INSTALLER_REVISION) ==" export DEBIAN_FRONTEND=noninteractive @@ -40,11 +40,6 @@ echo "==== Install nodejs ====" apt-get -y install nodejs npm ln -sf /usr/bin/nodejs /usr/bin/node - -echo "==== Install git ====" -apt-get -y install git - - echo "==== Install docker ====" # see http://idolstarastronomer.com/painless-docker.html echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list @@ -129,26 +124,13 @@ echo "/root/user_home.img $USER_HOME btrfs loop,nosuid 0 0" >> /etc/fstab mount -a btrfs subvolume create $USER_HOME/data -echo "==== Cloning box repo ====" -echo "Cloning the box repo" -mkdir -p $USER_HOME -cd $USER_HOME -git clone http://bootstrap:not4long@yellowtent.girish.in/yellowtent/box.git -cd $SRCDIR -git reset --hard $BOX_REVISION -echo "git HEAD is `git rev-parse HEAD`" - -NPM_INSTALL="npm install --production" -rm -rf ./node_modules -eval $NPM_INSTALL -RET=$? -while [[ $RET -ne 0 ]]; do - echo "[EE] npm install failed, try again" - rm -rf ./node_modules - eval $NPM_INSTALL - RET=$? -done +echo "==== Extracting installer source ====" +mkdir -p "$INSTALLER_SOURCE_DIR" +tar xvf /root/installer.tar -C "$INSTALLER_SOURCE_DIR" && rm /root/installer.tar +echo "$INSTALLER_REVISION" > "$INSTALLER_SOURCE_DIR/REVISION" +echo "=== Rebuilding npm packages ===" +cd "$INSTALLER_SOURCE_DIR" && npm install echo "==== Make the user own his home ====" chown $USER:$USER -R /home/$USER @@ -197,26 +179,12 @@ echo "==== Install init script ====" cat > /etc/init.d/cloudron-bootstrap <&1 1> "/var/log/cloudron/bootstrap.log" - DEBUG="box*,connect-lastmile" $SRCDIR/installer/server.js provision-mode 2>&1 1> /var/log/cloudron/installserver.log & + DEBUG="box*,connect-lastmile" $INSTALLER_SOURCE_DIR/installer/server.js provision-mode 2>&1 1> /var/log/cloudron/installserver.log & echo "Disabling cloudron-bootstrap init script" update-rc.d cloudron-bootstrap remove