Last active
December 15, 2016 15:37
-
-
Save mraxus/f177f3f9c587e2461986303f7434ea91 to your computer and use it in GitHub Desktop.
Generalized commands to initialize docker-compose/wait for db
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
def postgres_url() | |
postgres_str = `docker-compose port postgres 5432`.strip | |
return "postgres://postgres:postgres@#{postgres_str}/postgres" | |
end | |
desc "Run initial setups needed to get service running locally (also runs all setup_x tasks)" | |
task :setup => [:start_doc, :setup_db] | |
desc "Start docker-compose in background" | |
task :start_doc do | |
sh "docker-compose up -d --remove-orphans" | |
end | |
desc "setup local db with test data" | |
task :setup_db do | |
while system("psql #{postgres_url()} -c 'SELECT 1;' &> /dev/null") != true do | |
print "database is starting...\n" | |
sleep(1) | |
end | |
sh "psql #{postgres_url()} -v ON_ERROR_STOP=1 -f schema.sql" | |
end | |
desc "Tear down the docker-compose" | |
task :teardown do | |
sh "docker-compose stop && docker-compose rm -f" | |
sh "rm -rf local-data/" | |
end | |
desc "Run service locally" | |
task :run => :start_doc do | |
sh "run-command" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment