@ -15,13 +15,25 @@ if [ $# -eq 0 ]; then
echo
echo "Commands:"
echo " setup - Has to be run once initially. Installs backend and frontend dependencies. "
echo " reset - Resets everything by removing all containers and deleting all volumes. You need to run \`setup\` again afterwards. "
echo " start - Starts both backend and frontend in the background. Access via http://localhost:3000/ by default."
echo " run - Starts the frontend in the background and backend in the foreground. Useful for debugging using pry."
echo " rspec - Runs rspec inside the \`backend-test\` container which will be started if it's not running yet."
echo " * - Everything else will be passed straight to \`docker-compose\`."
echo
exit 1
elif [[ "$@" = "start" ]]; then
fi
if [ -f config/database.yml ]; then
echo
printf "\033[0;31mError\033[0m: Found local \`config/database.yml\` - The docker setup will not work with this file present."
echo " You could delete it or rename it for the time being."
exit 1
fi
if [[ "$@" = "start" ]]; then
# backend will be started automatically as a dependency of the frontend
docker-compose -f $COMPOSE_FILE up -d frontend
elif [[ "$@" = "run" ]]; then
@ -32,6 +44,23 @@ elif [[ "$@" = "run" ]]; then
elif [[ "$1" = "setup" ]]; then
docker-compose -f $COMPOSE_FILE run backend setup
yes no | docker-compose -f $COMPOSE_FILE run frontend npm install
elif [[ "$1" = "reset" ]]; then
docker-compose -f $COMPOSE_FILE down && docker volume rm `docker volume ls -q | grep ${PWD##*/}_`
elif [[ "$1" = "rspec" ]]; then
if ! docker ps | grep ${PWD##*/}_backend-test_1 > /dev/null; then
echo "Test backend not running yet. Starting it..."
docker-compose -f $COMPOSE_FILE up -d backend-test
while ! docker logs --since 1m ${PWD##*/}_backend-test_1 | grep "Ready for tests" > /dev/null; do
sleep 1
printf "."
done
echo "Ready for tests"
fi
docker-compose -f $COMPOSE_FILE exec backend-test bundle exec rspec "${@:2}"
else
docker-compose -f $COMPOSE_FILE $*
fi