debox 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ tmp
18
18
  *~
19
19
  #*
20
20
  .#*
21
+ config/database.yml
data/Gemfile CHANGED
@@ -11,5 +11,7 @@ gemspec
11
11
  group :test do
12
12
  gem 'debox_server'
13
13
  gem 'rspec'
14
- gem 'thin'
14
+ gem 'thin' # We need it for eventsource
15
+ gem 'database_cleaner'
16
+ gem 'mysql2'
15
17
  end
@@ -0,0 +1,116 @@
1
+ * Debox
2
+
3
+ This gem is the client for the Debox Server. It allow you to create and update capistrano recipes, run tasks and manage users in the server.
4
+
5
+ * Installation
6
+
7
+ To install the latest version, run:
8
+
9
+ #+BEGIN_SRC sh
10
+ $ [sudo] gem install debox
11
+ #+END_SRC
12
+
13
+ * Usage
14
+
15
+ First thing to do after install the gem is login into your debox server.
16
+
17
+ #+BEGIN_SRC sh
18
+ $ debox login -h deboxserver.com -u youruser@email.com
19
+ #+END_SRC
20
+
21
+ ** Getting help
22
+
23
+ To get a list of available commands run:
24
+
25
+ #+BEGIN_SRC sh
26
+ $ debox -h
27
+
28
+ Usage: debox command [options]
29
+ Commands:
30
+ recipes application # List recipes for the application
31
+ recipes:show application environment # Show a new capistrano recipe
32
+ recipes:new application environment # Create a new capistrano recipe
33
+ recipes:edit application environment # Edit a capistrano recipe
34
+ recipes:delete application environment # Delete a capistrano recipe
35
+ users # List all users in the debox server
36
+ users:new # Create user
37
+ users:delete email # Delete user with a given email
38
+ apps # List apps and envs
39
+ log application [environment] [index] # Show log. Last by default
40
+ logs application [environment] # List logs for application and env
41
+ deploy application enviroment # Deploy application
42
+ cap task application [environment] # Deploy application
43
+ login # Login in the debox server. Require -h param.
44
+ live application enviroment # Live log for application
45
+ key:show # Show the server ssh public key
46
+ key:copy target_host # Copy the server ssh public key to the target host
47
+ Options:
48
+ -h, --host SERVER_HOST Debox server url
49
+ -p, --port PORT Debox server port
50
+ -u, --user EMAIL User name
51
+ -?, --help Show this help
52
+ #+END_SRC
53
+
54
+ ** Keys setup
55
+
56
+ You must add the public key for the user runnin the debox server to the server where capistrano have to connect and run task.
57
+ The debox client includes a command for help with this, you can run:
58
+
59
+ #+BEGIN_SRC sh
60
+ $ debox key:copy your_application_server
61
+ #+END_SRC
62
+
63
+ If you haven't access to this server, you can get the key with this command:
64
+
65
+ #+BEGIN_SRC sh
66
+ $ debox key:show
67
+ #+END_SRC
68
+
69
+ ** Display applications configured in the server
70
+
71
+ To get a list of configured apps and its environment run:
72
+
73
+ #+BEGIN_SRC sh
74
+ $ debox apps
75
+ #+END_SRC
76
+
77
+ It will show a list of apps and configured envirments
78
+
79
+ ** Adding applications or environments
80
+
81
+ To create an application or add a new env to an existent application.
82
+
83
+ #+BEGIN_SRC sh
84
+ $ debox recipes:new application_name environment_name
85
+ #+END_SRC
86
+
87
+ This command will open your default text editor, defined in the environment variable $EDITOR, with a boostraped capistrano recipe.
88
+ After save and close this file, it will be automatically uploaded to the server and ready to use.
89
+
90
+ ** Edit environments
91
+
92
+ For change the capistrano recipe configured for any recipe run:
93
+ #+BEGIN_SRC sh
94
+ $ debox recipes:edit application_name environment_name
95
+ #+END_SRC
96
+
97
+ ** Show environments
98
+
99
+ To get the content for a recipe just run:
100
+
101
+ #+BEGIN_SRC sh
102
+ $ debox recipes:show
103
+ #+END_SRC
104
+
105
+ ** Run tasks
106
+
107
+ You can run any task defined in the capistrano recipe with the cap command:
108
+
109
+ #+BEGIN_SRC sh
110
+ $ debox cap deploy:setup app env
111
+ $ debox cap deploy app env
112
+ $ debox cap deploy:migrate app env
113
+ $ debox cap deploy:restart app env
114
+ #+END_SRC
115
+
116
+ It will stream the server output to the stdout
@@ -0,0 +1,26 @@
1
+ development:
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ reconnect: false
5
+ database: debox_development
6
+ pool: 5
7
+ username: root
8
+ password:
9
+
10
+ test:
11
+ adapter: mysql2
12
+ encoding: utf8
13
+ reconnect: false
14
+ database: debox_test
15
+ pool: 5
16
+ username: root
17
+ password:
18
+
19
+ production:
20
+ adapter: mysql2
21
+ encoding: utf8
22
+ reconnect: false
23
+ database: debox_production
24
+ pool: 5
25
+ username: root
26
+ password:
@@ -21,6 +21,11 @@ module Debox
21
21
  get '/v1/apps'
22
22
  end
23
23
 
24
+ # Server status
25
+ def self.status
26
+ get '/v1/status'
27
+ end
28
+
24
29
  # users
25
30
  #----------------------------------------------------------------------
26
31
 
@@ -90,10 +95,12 @@ module Debox
90
95
  #----------------------------------------------------------------------
91
96
 
92
97
  def self.live(opt, &block)
93
- path = "/v1/live/log/#{opt[:app]}"
94
- path += "/#{opt[:env]}" if opt[:env]
98
+ path = "/v1/live/log/job/#{opt[:job_id]}"
99
+ eventSource path, { }, block
100
+ end
95
101
 
96
- # stream path, nil, { }, block
102
+ def self.notifications(opt={ }, &block)
103
+ path = "/v1/live/notifications"
97
104
  eventSource path, { }, block
98
105
  end
99
106
 
@@ -106,7 +113,7 @@ module Debox
106
113
  def self.log(opt)
107
114
  path = "/v1/log/#{opt[:app]}"
108
115
  path += "/#{opt[:env]}" if opt[:env]
109
- path += "?index=#{opt[:index]}" if opt[:index]
116
+ path += "?job_id=#{opt[:job_id]}" if opt[:job_id]
110
117
  get_raw(path).body
111
118
  end
112
119
 
@@ -7,8 +7,8 @@ class Debox::Command::Cap < Debox::Command::Base
7
7
  deploy_params = { task: args[0], app: args[1] }
8
8
  deploy_params[:env] = args[2] if args.count == 3
9
9
  cap_request = Debox::API.cap(deploy_params)
10
- sleep 1
11
- Debox::API.live(deploy_params) do |chunk|
10
+ job_id = cap_request[:job_id]
11
+ Debox::API.live(job_id: job_id) do |chunk|
12
12
  puts chunk
13
13
  end
14
14
  end
@@ -2,8 +2,8 @@ require 'debox/command/base'
2
2
 
3
3
  class Debox::Command::Live < Debox::Command::Base
4
4
 
5
- help :index, params: ['application', 'enviroment'], text: 'Live log for application'
6
- def index
5
+ help :log, params: ['job_id'], text: 'Live log for job'
6
+ def log
7
7
  opt = { app: args[0] }
8
8
  opt[:env] = args[1] if args[1]
9
9
  Debox::API.live(opt) do |chunk|
@@ -11,4 +11,12 @@ class Debox::Command::Live < Debox::Command::Base
11
11
  end
12
12
  end
13
13
 
14
+
15
+ help :notifications, text: 'Live notifications'
16
+ def notifications
17
+ Debox::API.notifications do |chunk|
18
+ puts chunk
19
+ end
20
+ end
21
+
14
22
  end
@@ -3,13 +3,13 @@ require 'debox/command/base'
3
3
  class Debox::Command::Log < Debox::Command::Base
4
4
  include Debox::Utils
5
5
 
6
- help :index, params: ['application'],opt_params: ['environment', 'index'],
6
+ help :index, params: ['application'],opt_params: ['environment', 'job_id'],
7
7
  text: "Show log. Last by default"
8
8
 
9
9
  def index
10
10
  opt = { app: args[0] }
11
11
  opt[:env] = args[1] if args.length > 1
12
- opt[:index] = args[2] if args.length > 2
12
+ opt[:job_id] = args[2] if args.length > 2
13
13
 
14
14
  puts Debox::API.log opt
15
15
  end
@@ -16,11 +16,15 @@ class Debox::Command::Logs < Debox::Command::Base
16
16
  private
17
17
 
18
18
  def format_log_info(log)
19
+ status = log[:success] ? "SUCCESS" : "FAILED"
20
+ start_time = log[:start_time] ? DateTime.parse(log[:start_time]).to_s : ""
21
+ end_time = log[:end_time] ? DateTime.parse(log[:end_time]).to_s : ""
22
+
19
23
  l = []
20
- l << log[:job_id]
21
- l << log[:status]
24
+ l << log[:id]
25
+ l << status
22
26
  l << log[:task]
23
- l << DateTime.parse(log[:time]).to_s
27
+ l << start_time
24
28
  l << log[:error]
25
29
  l.join "\t"
26
30
  end
@@ -0,0 +1,11 @@
1
+ require 'debox/command/base'
2
+
3
+ class Debox::Command::Status < Debox::Command::Base
4
+
5
+ help :index, text: 'Show server status'
6
+ def index
7
+ status = Debox::API.status
8
+ puts status
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Debox
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -3,25 +3,25 @@ describe 'cap' do
3
3
 
4
4
  it 'should deal with invalid app' do
5
5
  configure_admin
6
- DeboxServer::Deployer.should_not_receive(:add_job_to_queue)
6
+ DeboxServer::jobs_queue.should_not_receive(:add)
7
7
  expect {
8
8
  Debox::API.cap(app: 'test')
9
- }.to raise_error Debox::DeboxServerException, '400: App not found'
9
+ }.to raise_error Debox::DeboxServerException, "400: Couldn't find App with name = test"
10
10
  end
11
11
 
12
12
  it 'should deal with invalid env' do
13
13
  configure_admin
14
14
  server.create_recipe('test', :production, 'invalid content')
15
- DeboxServer::Deployer.should_not_receive(:add_job_to_queue)
15
+ DeboxServer::jobs_queue.should_not_receive(:add)
16
16
  expect {
17
17
  Debox::API.cap(app: 'test', env: 'invalid')
18
- }.to raise_error Debox::DeboxServerException, '400: Environment not found.'
18
+ }.to raise_error Debox::DeboxServerException, "400: Couldn't find Recipe with name = invalid"
19
19
  end
20
20
 
21
21
  it 'should run a cap task gith a given app' do
22
22
  configure_admin
23
23
  server.create_recipe('test', :production, 'invalid content')
24
- DeboxServer::Deployer.should_receive(:add_job_to_queue)
24
+ DeboxServer::jobs_queue.should_receive(:add)
25
25
 
26
26
  job = Debox::API.cap app: 'test'
27
27
  job[:app].should eq 'test'
@@ -33,7 +33,7 @@ describe 'cap' do
33
33
  configure_admin
34
34
  server.create_recipe('test', :production, 'invalid content')
35
35
  server.create_recipe('test', :staging, 'invalid content')
36
- DeboxServer::Deployer.should_receive(:add_job_to_queue)
36
+ DeboxServer::jobs_queue.should_receive(:add)
37
37
 
38
38
  job = Debox::API.cap app: 'test', env: 'staging'
39
39
  job[:app].should eq 'test'
@@ -46,7 +46,7 @@ describe 'cap' do
46
46
  configure_admin
47
47
  server.create_recipe('test', :production, 'invalid content')
48
48
  server.create_recipe('test', :staging, 'invalid content')
49
- DeboxServer::Deployer.should_receive(:add_job_to_queue)
49
+ DeboxServer::jobs_queue.should_receive(:add)
50
50
 
51
51
  job = Debox::API.cap app: 'test', env: 'staging', task: 'node:setup'
52
52
  job[:app].should eq 'test'
@@ -2,38 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe 'logs' do
4
4
  it 'should return all the logs' do
5
- time = DateTime.now
6
- out = OpenStruct.new time: time, success: true, buffer: 'Some log content', error: 'Log result'
7
5
  server.create_recipe('test', 'production', 'content')
8
- job = stubbed_job 'test', 'production', 'deploy', out
9
- job.save_log
6
+ job = Job.new error: 'Log result'
7
+ Recipe.any_instance.should_receive(:jobs).and_return [job]
10
8
 
11
9
  configure_admin
12
10
 
13
11
  logs = Debox::API.logs app: 'test', env: 'production'
14
12
  logs.count.should eq 1
15
13
  saved = logs.first
16
- DateTime.parse(saved[:time]).to_s.should eq time.to_s
14
+
17
15
  saved[:error].should eq 'Log result'
18
- saved[:status].should eq 'success'
19
16
  end
20
17
 
21
18
  it 'should set default env if not set and only one available' do
22
- time = DateTime.now
23
- out = OpenStruct.new time: time, success: true, buffer: 'Some log content', error: 'Log result'
24
19
  server.create_recipe('test', 'production', 'content')
25
- job = stubbed_job 'test', 'production', 'deploy', out
26
- job.save_log
20
+ job = Job.new error: 'Log result'
21
+ Recipe.any_instance.should_receive(:jobs).and_return [job]
27
22
 
28
23
  configure_admin
29
24
 
30
- logs = Debox::API.logs app: 'test', env: 'production'
25
+ logs = Debox::API.logs app: 'test'
31
26
  logs.count.should eq 1
32
27
  saved = logs.first
33
28
 
34
- DateTime.parse(saved[:time]).to_s.should eq time.to_s
35
29
  saved[:error].should eq 'Log result'
36
- saved[:status].should eq 'success'
37
30
  end
38
31
 
39
32
  it 'should empty array withut logs' do
@@ -47,7 +40,7 @@ describe 'logs' do
47
40
  configure_admin
48
41
  expect {
49
42
  Debox::API.logs app: 'test', env: 'production'
50
- }.to raise_error Debox::DeboxServerException, '400: App not found'
43
+ }.to raise_error Debox::DeboxServerException, "400: Couldn't find App with name = test"
51
44
 
52
45
  end
53
46
 
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
2
  describe 'log' do
3
3
  it 'should return the log' do
4
- out = OpenStruct.new time: DateTime.now, success: true, buffer: 'Some log content', error: 'Log result'
5
4
  server.create_recipe('test', 'production', 'content')
6
- job = stubbed_job 'test', 'production', 'deploy', out
7
- job.save_log
5
+ job = Job.new error: 'Log result', log: 'Some log content'
6
+ jobs = double('jobs')
7
+ jobs.should_receive(:last).and_return job
8
+ Recipe.any_instance.should_receive(:jobs).and_return jobs
8
9
 
9
10
  configure_admin
10
11
 
@@ -13,10 +14,11 @@ describe 'log' do
13
14
  end
14
15
 
15
16
  it 'should return the log without env' do
16
- out = OpenStruct.new time: DateTime.now, success: true, buffer: 'Some log content', error: 'Log result'
17
17
  server.create_recipe('test', 'production', 'content')
18
- job = stubbed_job 'test', 'production', 'deploy', out
19
- job.save_log
18
+ job = Job.new error: 'Log result', log: 'Some log content'
19
+ jobs = double('jobs')
20
+ jobs.should_receive(:last).and_return job
21
+ Recipe.any_instance.should_receive(:jobs).and_return jobs
20
22
 
21
23
  configure_admin
22
24
 
@@ -5,10 +5,10 @@ describe 'recipes_delete' do
5
5
 
6
6
  it 'should destroy the recipe if exists' do
7
7
  configure_admin
8
- server.create_recipe('test', :staging, 'sample content')
9
- server.create_recipe('test', :production, 'sample content')
8
+ staging_recipe = server.create_recipe('test', :staging, 'sample content')
9
+ production_recipe = server.create_recipe('test', :production, 'sample content')
10
10
  response = Debox::API.recipes_destroy app: 'test', env: 'staging'
11
11
  response.code.should eq '200'
12
- server.recipes_list('test').should eq ['production']
12
+ Recipe.all.should eq [production_recipe]
13
13
  end
14
14
  end
@@ -1,11 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'recipes index' do
4
- it 'should return an empty array without recipes' do
4
+
5
+ it 'should return invalid if app does not exists' do
5
6
  configure_admin
6
- Debox::API.recipes(app: 'test').should eq []
7
- end
7
+ expect {
8
+ Debox::API.recipes(app: 'test')
9
+ }.to raise_error Debox::DeboxServerException, "400: Couldn't find App with name = test"
8
10
 
11
+ end
9
12
 
10
13
  it 'should return current recipes if any' do
11
14
  app = 'test'
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'recipes new' do
4
- it 'should create a new config file with the content of the template' do
4
+
5
+ xit 'should create a new config file with the content of the template' do
6
+
5
7
  configure_admin
6
8
  response = Debox::API.recipes_new app: 'test_app', env: 'production'
7
9
  response.should match 'test_app'
@@ -6,6 +6,6 @@ describe 'users_delete' do
6
6
  create_admin 'other@indeos.es'
7
7
  response = Debox::API.users_delete user: 'other@indeos.es'
8
8
  response.code.should eq '200'
9
- server.users_list.should eq [user.email]
9
+ User.all.collect(&:email).should eq [user.email]
10
10
  end
11
11
  end
@@ -5,6 +5,6 @@ describe 'users' do
5
5
  user = create_admin
6
6
  configure_admin user
7
7
  create_admin 'other@email.com'
8
- Debox::API.users.should eq ['other@email.com', user.email]
8
+ Debox::API.users.should eq [user.email, 'other@email.com']
9
9
  end
10
10
  end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe 'cap command' do
4
4
  it 'should call API::cap and API::live' do
5
- Debox::API.should_receive(:cap).with(app: 'test', env: 'prod', task: 'deploy').and_return '1'
6
- Debox::API.should_receive(:live).with(app: 'test', env: 'prod', task: 'deploy')
5
+ Debox::API.should_receive(:cap).with(app: 'test', env: 'prod', task: 'deploy').and_return job_id: 1
6
+ Debox::API.should_receive(:live).with(job_id: 1)
7
7
  run_command 'cap deploy test prod'
8
8
  end
9
9
 
10
10
  it 'env is optional' do
11
- Debox::API.should_receive(:cap).with(app: 'test', task: 'deploy').and_return '1'
12
- Debox::API.should_receive(:live).with(app: 'test', task: 'deploy')
11
+ Debox::API.should_receive(:cap).with(app: 'test', task: 'deploy').and_return job_id: 1
12
+ Debox::API.should_receive(:live).with(job_id: 1)
13
13
  run_command 'cap deploy test'
14
14
  end
15
15
 
@@ -1,11 +1,13 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
+ ENV['DEBOX_ROOT'] = File.join(File.dirname(__FILE__), '../')
2
3
 
3
4
  require 'rubygems'
4
5
  require 'bundler'
5
6
  require 'rack'
6
7
  require 'thin'
7
8
  require 'debox_server'
8
-
9
+ require 'debox_server/api'
10
+ require 'database_cleaner'
9
11
  Bundler.require
10
12
 
11
13
  require "debox/cli"
@@ -26,10 +28,13 @@ DEBOX_SERVER_PORT = 9393
26
28
  debox_server_start DEBOX_SERVER_PORT
27
29
 
28
30
  RSpec.configure do |config|
31
+ config.before(:suite) do
32
+ DatabaseCleaner.strategy = :truncation
33
+ DatabaseCleaner.clean
34
+ end
29
35
 
30
36
  # Cleanup database after each test
31
37
  config.after(:each) do
32
- DeboxServer::RedisDB.flush_test_db
38
+ DatabaseCleaner.clean
33
39
  end
34
-
35
40
  end
@@ -26,15 +26,6 @@ def configure
26
26
  Debox::Config.stub(:config).and_return host: 'localhost', port: DEBOX_SERVER_PORT
27
27
  end
28
28
 
29
- # Build a job with stdout and capistrano methos stubbed
30
- def stubbed_job(app, env, task='deploy', out=nil)
31
- out = OpenStruct.new time: DateTime.now, success: true unless out
32
- job = DeboxServer::Job.new(app, env, task)
33
- job.stub(:stdout) { out }
34
- job.stub(:capistrano) { { } }
35
- return job
36
- end
37
-
38
29
  def run_command(args_str, options={})
39
30
  args = args_str.split
40
31
  given_command = args.shift.strip
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-08 00:00:00.000000000 Z
12
+ date: 2013-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -103,9 +103,10 @@ files:
103
103
  - .rspec
104
104
  - Gemfile
105
105
  - LICENSE
106
- - README.md
106
+ - README.org
107
107
  - Rakefile
108
108
  - bin/debox
109
+ - config/database.yml.sample
109
110
  - debox.gemspec
110
111
  - lib/debox.rb
111
112
  - lib/debox/api.rb
@@ -122,6 +123,7 @@ files:
122
123
  - lib/debox/command/login.rb
123
124
  - lib/debox/command/logs.rb
124
125
  - lib/debox/command/recipes.rb
126
+ - lib/debox/command/status.rb
125
127
  - lib/debox/config.rb
126
128
  - lib/debox/utils.rb
127
129
  - lib/debox/version.rb
data/README.md DELETED
@@ -1,29 +0,0 @@
1
- # Debox
2
-
3
- Command line tool for Debox
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'debox'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install debox
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Added some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request