Skip to content

Instantly share code, notes, and snippets.

@sinegar
Created October 30, 2013 07:53
Show Gist options
  • Save sinegar/7228687 to your computer and use it in GitHub Desktop.
Save sinegar/7228687 to your computer and use it in GitHub Desktop.
Build script for buildbox.io which checkout from a private bitbucket repository
#!/bin/bash
# Exits bash immediately if any command fails
set -e
REMOTE_KEY=~/.ssh/builderkey
# Will output commands as the run
set -x
# Want to know what ENV varibles Buildbox sets during the build?
env | grep BUILDBOX
# Buildbox will run your builds by default in:
# ~/.buildbox/account-name/project-name
# pwd
## for testing uncomment the line to refresh ssh key
# rm $REMOTE_KEY*
# generate ssh key if does not exist
# set as default key
if [ ! -f "$REMOTE_KEY" ]; then
ssh-keygen -q -t rsa -f $REMOTE_KEY -N ""
echo "IdentityFile $REMOTE_KEY" >> ~/.ssh/config
fi
# print out current public key - usefull to copy and add to bitbucket
ssh-keygen -q -y -f $REMOTE_KEY
# add bitbucket.org to ssh known_hosts
# TODO replace hardcoded git@bitbucket.org with parsing $BUILDBOX_REPO
ssh -T -o StrictHostKeyChecking=no git@bitbucket.org
# Here are some basic setup instructions for checkout out a git repository.
# You have to manage checking out and updating the repo yourself.
# If the git repo doesn't exist in the b
if [ ! -d ".git" ]; then
git clone "$BUILDBOX_REPO" . -q
fi
# Always start with a clean repo
git clean -fd
# Fetch the latest commits from origin, and checkout to the commit being tested
git fetch
git checkout -f "$BUILDBOX_COMMIT"
# added pull because 'git checkout -f master' didn't get latest changes
git pull
# Here are some basic instructions on how to run tests on a Ruby on Rails project
# with rspec. You can change these commands to be what ever you like.
# bundle install
# bundle exec rake db:schema:load
# bundle exec rspec
# npm and grunt dependency: https://github.com/buildboxhq/buildbox-heroku/pull/2
npm install
grunt
# Want to do continious delivery? It's easy to only run commands on a paticular branch.
# Here
if [ "$BUILDBOX_BRANCH" != "master" ]
then
echo "Skipping deploy for the $BUILDBOX_BRANCH branch."
exit 0
fi
# Run what ever deploy command you ususally run
# cap deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment