Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active April 20, 2018 21:27
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 JoshCheek/b9cb7733e278d7064c0ac7682515530f to your computer and use it in GitHub Desktop.
Save JoshCheek/b9cb7733e278d7064c0ac7682515530f to your computer and use it in GitHub Desktop.
Bash code to deploy synseer to EC2
#!/usr/bin/env bash -l
timestamp="$(date '+%Y-%m-%d-%k:%M:%S')"
archive_name="${timestamp}.tar.gz"
ruby_version=""
pem_file="$HOME/.ssh/JoshAdmin.pem"
remote_user="ec2-user"
remote_host="ec2-54-167-223-244.compute-1.amazonaws.com"
remote_path="/home/$remote_user/app/"
=====() {
echo -e "\033[35m===== $@ =====\033[0m"
}
with_ruby() {
chruby-exec "$ruby_version" -- "$@"
}
===== 'Creating directories'
mkdir -p build
mkdir -p deploys
===== 'Clone / pull changes from GitHub'
[[ -d build/synseer ]] ||
git clone "https://github.com/JoshCheek/synseer.git" build/synseer
pushd build/synseer
git pull
popd
===== 'Get the Ruby version'
pushd build/synseer
ruby_version="$(ruby -ne $'puts $1 if /^ruby \'(.*?)\'$/' Gemfile)"
echo "ruby version: $ruby_version"
popd
===== 'Install bundler (Ruby packages)'
with_ruby which bundle ||
with_ruby gem install bundler
===== 'Package the gems into the repo'
pushd build/synseer
with_ruby bundle install --deployment
popd
===== 'Copy the files to the server'
pushd build/synseer
rsync -Paz -e "ssh -i '$pem_file'" . "$remote_user@$remote_host:$remote_path"
popd
===== 'Save an archive of the deploy'
pushd build
tar -zcf "../deploys/$archive_name" synseer
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment