Skip to content

Instantly share code, notes, and snippets.

@nkwhr
Created July 27, 2015 09:06
Show Gist options
  • Save nkwhr/40f6d6aef5caecb04ac2 to your computer and use it in GitHub Desktop.
Save nkwhr/40f6d6aef5caecb04ac2 to your computer and use it in GitHub Desktop.
A sample script for running rspec on docker
#!/bin/bash
set -x
uuid=$(uuidgen)
docker build -t myapp .
docker run -d --name mysql-${uuid} --env MYSQL_ROOT_PASSWORD=xxxxxx mysql:5.6
docker run -d --name memcached-${uuid} memcached
docker run -d --name redis-${uuid} redis
sleep 10
docker run \
--rm \
--link mysql-${uuid}:mysql \
-e RAILS_ENV=test \
myapp bash -c 'bin/rake db:create'
docker run \
--rm \
--link memcached-${uuid}:cache \
--link redis-${uuid}:redis \
--link mysql-${uuid}:mysql \
-v /etc/localtime:/etc/localtime:ro \
-e RAILS_ENV=test \
myapp bash -c 'bundle exec rspec'
result=$?
docker stop mysql-${uuid} >/dev/null && docker rm mysql-${uuid}
docker stop redis-${uuid} >/dev/null && docker rm redis-${uuid}
docker stop memcached-${uuid} >/dev/null && docker rm memcached-${uuid}
if [ $result -eq 0 ] ; then
docker tag myapp private_registry/myapp
docker push private_registry/myapp || exit 1
# image_id=$(docker images | grep "private_registry/myapp" | grep latest | awk '{print $3}')
# notify_slack "Pushed new revision of private_registry/myapp (${image_id})"
fi
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment