|
| 1 | +#!/usr/bin/env rake |
| 2 | + |
| 3 | +require 'mixlib/shellout' |
| 4 | +require 'rainbow/ext/string' |
| 5 | + |
| 6 | +AUTH_KEY = ENV['DEIS_TEST_KEY'] || '~/.ssh/deis' |
| 7 | +SSH_KEY = ENV['DEIS_TEST_SSH_KEY'] || '~/.vagrant.d/insecure_private_key' |
| 8 | +HOST = ENV['DEIS_TEST_HOST'] || 'local.deisapp.com' |
| 9 | +EXAMPLE_APP = ENV['DEIS_TEST_APP'] || 'example-ruby-sinatra' |
| 10 | + |
| 11 | +namespace :setup do |
| 12 | + task :all => ['create_ssh_key','clone_example_app'] |
| 13 | + task :create_ssh_key do |
| 14 | + run_command("if [ ! -f #{AUTH_KEY} ]; then ssh-keygen -q -t rsa -f #{AUTH_KEY} -N '' -C deis && ssh-add -K #{AUTH_KEY} ; fi") |
| 15 | + end |
| 16 | + task :clone_example_app do |
| 17 | + run_command("if [ ! -d ./#{EXAMPLE_APP} ]; then git clone https://github.com/opdemand/#{EXAMPLE_APP}.git ; fi") |
| 18 | + end |
| 19 | +end |
| 20 | + |
| 21 | +namespace :tests do |
| 22 | + task :all => ['register','login','add_key','create_cluster','create_app','push_app','scale_app','verify_app'] |
| 23 | + task :register do |
| 24 | + run_command("deis register http://#{HOST}:8000 --username=test --email=test@test.co.nz --password=asdf1234") |
| 25 | + end |
| 26 | + task :login do |
| 27 | + run_command("deis login http://#{HOST}:8000 --username=test --password=asdf1234") |
| 28 | + end |
| 29 | + task :add_key do |
| 30 | + run_command("deis keys:add #{AUTH_KEY}.pub") |
| 31 | + end |
| 32 | + task :create_cluster do |
| 33 | + run_command("deis init dev #{HOST} --hosts=#{HOST} --auth=#{SSH_KEY}") |
| 34 | + end |
| 35 | + task :create_app do |
| 36 | + run_command("cd #{EXAMPLE_APP} && deis apps:create testing") |
| 37 | + end |
| 38 | + task :push_app do |
| 39 | + run_command("cd #{EXAMPLE_APP} && git push deis master") |
| 40 | + end |
| 41 | + task :scale_app do |
| 42 | + run_command("cd #{EXAMPLE_APP} && deis scale web=2") |
| 43 | + end |
| 44 | + task :verify_app do |
| 45 | + run_command("curl -s http://testing.#{HOST} | grep -q 'Powered by Deis'") |
| 46 | + end |
| 47 | +end |
| 48 | + |
| 49 | +namespace :cleanup do |
| 50 | + task :all => ['destroy_app','destroy_cluster','remove_key','logout'] |
| 51 | + task :destroy_app do |
| 52 | + run_command("cd #{EXAMPLE_APP} && deis apps:destroy --app=testing --confirm=testing") |
| 53 | + end |
| 54 | + task :destroy_cluster do |
| 55 | + run_command("deis clusters:destroy dev --confirm=dev") |
| 56 | + end |
| 57 | + task :remove_key do |
| 58 | + run_command("deis keys:remove deis") |
| 59 | + end |
| 60 | + task :logout do |
| 61 | + run_command("deis auth:logout") |
| 62 | + end |
| 63 | +end |
| 64 | + |
| 65 | +def run_command(cmd) |
| 66 | + print "Running #{cmd}... ".color(:yellow) |
| 67 | + cmd = Mixlib::ShellOut.new(cmd).run_command |
| 68 | + if not cmd.error? |
| 69 | + puts "Success!".color(:green) |
| 70 | + else |
| 71 | + puts "Failed!".color(:red) |
| 72 | + puts cmd.stdout.color(:red) |
| 73 | + puts cmd.stderr.color(:red) |
| 74 | + raise "Command failed - stopping" |
| 75 | + end |
| 76 | +end |
| 77 | + |
| 78 | +task :default => ['setup:all', 'tests:all', 'cleanup:all'] |
0 commit comments