-
-
Save dermatologist/6a37c5f40cd0318a77fc470f996f452f to your computer and use it in GitHub Desktop.
This is a script that takes a fresh Compute Canada Ubuntu 16.04 cloud instance, installs docker, docker-compose, ruby, grabs avalon source, and starts services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BIND_NETWORK='192.168' | |
RUBY_VERSION='2.4' | |
BUNDLER_VERSION='1.14' | |
AVALON_REPO='https://github.com/cwant/avalon' | |
AVALON_BRANCH='cwant/docker-refactor' | |
SRC_DIR=$HOME/gitwork | |
AVALON_DIR=$SRC_DIR/avalon | |
main() { | |
setup_hostname || exit | |
install_packages || exit | |
install_docker || exit | |
install_ruby || exit | |
install_sources || exit | |
configure_sources || exit | |
launch_services || exit | |
} | |
setup_hostname() { | |
# sudo complains that hostname isn't set, so we set it | |
hostname=`hostname` | |
grep '127.0.1.1.*'$hostname /etc/hosts && return 0 | |
sudo sh -c "echo 127.0.1.1 $hostname >> /etc/hosts" || exit 1 | |
} | |
install_packages() { | |
sudo apt-get -y update || exit 1 | |
sudo apt-get -y dist-upgrade || exit 1 | |
sudo apt-get install -y \ | |
tmux \ | |
emacs-nox \ | |
lynx \ | |
htop \ | |
git \ | |
phantomjs \ | |
mediainfo \ | |
libmysqlclient-dev \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
software-properties-common \ | |
cmake \ | |
nodejs \ | |
libpq-dev \ | |
python3-pip \ | |
libyazpp-dev \ | |
zlib1g-dev \ | |
libyaml-dev \ | |
libsqlite3-dev \ | |
sqlite3 \ | |
autoconf \ | |
libgmp-dev \ | |
libgdbm-dev \ | |
libncurses5-dev \ | |
automake \ | |
libtool \ | |
bison \ | |
pkg-config \ | |
libffi-dev \ | |
libgmp-dev \ | |
libreadline6-dev \ | |
libssl-dev || exit 1 | |
} | |
install_docker() { | |
(sudo apt-key list | grep 0EBFCD87) || \ | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ | |
sudo apt-key add - || exit 1 | |
(apt-cache policy | grep docker) || \ | |
sudo add-apt-repository \ | |
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) stable" || exit 1 | |
sudo apt-get -y update || exit 1 | |
sudo apt-get -y install docker-ce || exit 1 | |
which docker-compose || pip3 install docker-compose || exit 1 | |
sudo service docker start || exit 1 | |
# Note, probably need to log in and out for the next one to stick | |
sudo adduser $USER docker || exit 1 | |
} | |
install_ruby() { | |
# After this runs, if you want to use ruby/bundler you can either login | |
# again, or run in the current shell by doing: source $HOME/.rvm/scripts/rvm | |
cd $HOME | |
[ -d .rvm ] || gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB | |
[ -d .rvm ] || \curl -sSL https://get.rvm.io | bash -s stable | |
source $HOME/.rvm/scripts/rvm | |
rvm install $RUBY_VERSION | |
gem install bundler -v $BUNDLER_VERSION | |
} | |
install_sources() { | |
mkdir -p $SRC_DIR | |
cd $SRC_DIR | |
[ -d avalon ] || git clone $AVALON_REPO || exit | |
cd $AVALON_DIR | |
git checkout $AVALON_BRANCH || exit | |
} | |
configure_sources() { | |
cd $AVALON_DIR | |
cp config/controlled_vocabulary.yml.example \ | |
config/controlled_vocabulary.yml | |
} | |
launch_services() { | |
cd $AVALON_DIR | |
bundle install --path=vendor/bundle --with development test postgres aws \ | |
|| exit | |
# The su to $USER is to ensure that shell has user in docker group | |
sudo su -c "(cd $AVALON_DIR; pwd; docker-compose up -d)" - $USER || exit | |
sleep 120 | |
bundle exec rake db:setup || exit | |
bundle exec rake db:migrate || exit | |
IP=`ifconfig | grep $BIND_NETWORK | sed 's/^.*addr://' | sed 's/ .*$//'` | |
bundle exec rails s -b $IP -d | |
} | |
main || exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment