caracara 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22d2f961067ed99bd7e85d8c20a16393acbe22b7
4
- data.tar.gz: 9f06a43d93e8d4898b4a605b785b99d1c9762daa
3
+ metadata.gz: d50c26f77f84e931ddaebccefcf04be5719db1d2
4
+ data.tar.gz: a47824aa31549922404bbf7e8db756d1a5863d0b
5
5
  SHA512:
6
- metadata.gz: 43907c32b6f1dc51c42eb41172ea48276187c8706c8246998aa47d9099fbf1df79238c5ac0c6406e98440c090a6a46c4e985e220e06b5bf036071cd7abf5d37a
7
- data.tar.gz: 4cd556a08df8ddd5d86a2b201569be30faf25bb2a17ad4a66f0af98031d69c403902ea8538119b4cea8574cf15b2cfc64892d514d69f12788d992cfccf1c6c20
6
+ metadata.gz: 99d8b2ca1a4dbf51238c9afab8bac90975cf56acb54be4c8c2de8d8c8a8b7207ec16b47f14352a73443cf0482a32b377e797e1badba2f7c273f8c884519d252c
7
+ data.tar.gz: becec1267fed45c615b97e4c0f65b213d96bee7d89ee415d84063bf11b3d39e7a4b2bfccb5f1e39ee75b078cbf2b4834ee9ad037c74fd653d24edf9013abc247
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ env:
5
+ - "travis=true"
6
+ script:
7
+ - bundle exec rspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Caracara
1
+ # Caracara [![Build Status](https://travis-ci.org/gabrielcorado/caracara.svg)](https://travis-ci.org/gabrielcorado/caracara)
2
2
  Task runner based on [Envoy](http://laravel.com/docs/5.1/envoy) and [Mina](http://mina-deploy.github.io/mina/)
3
3
 
4
4
  # Concepts
@@ -44,21 +44,15 @@ end
44
44
  ```ruby
45
45
  class DeployGroup < Caracara::Group
46
46
  # Clone it
47
- task GitCloneTask
47
+ task :clone, GitCloneTask
48
48
 
49
49
  # Dockernize it
50
- task DockerTask
50
+ task :docker, DockerTask
51
51
  end
52
52
  ```
53
53
 
54
54
  **Intialize the group**
55
55
  ```ruby
56
- # Initialize the group
57
- deploy = DeployGroup.init
58
- ```
59
-
60
- **Generate the command**
61
- ```ruby
62
56
  # Set the options
63
57
  options = {
64
58
  repository: 'git@github.com:gabrielcorado/caracara.git',
@@ -68,13 +62,19 @@ options = {
68
62
  container: 'caracara_app'
69
63
  }
70
64
 
71
- # Generate the SSH command
72
- command = deploy.command options
65
+ # Initialize the group
66
+ deploy = DeployGroup.init options
67
+ ```
68
+
69
+ **Generate the commands**
70
+ ```ruby
71
+ # Compile the group commands
72
+ commands = deploy.compile_all
73
73
  ```
74
74
 
75
75
  **Run the command in your server**
76
76
  ```ruby
77
- Caracara::SSH.exec 'user', 'localhost', command
77
+ Caracara::SSH.exec 'user', 'localhost', commands
78
78
  ```
79
79
 
80
80
  # Development
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.files = `git ls-files`.strip.split("\n")
13
13
  s.executables = Dir["bin/*"].map { |f| File.basename(f) }
14
14
 
15
- s.add_dependency 'rake'
16
15
  s.add_dependency 'mustache', '~> 1.0'
17
16
 
18
17
  s.add_development_dependency 'rspec', '~> 3.0.0'
@@ -6,32 +6,53 @@ module Caracara
6
6
  attr_reader :tasks
7
7
 
8
8
  # Initialize
9
- def initialize(tasks = [])
9
+ def initialize(tasks = [], options = {})
10
10
  @tasks = tasks
11
+ @options = options
11
12
  end
12
13
 
13
- # Tasks access
14
- def tasks
15
- # Map the tasks
16
- @tasks.map do |task|
17
- task
18
- end
14
+ # Compile the tasks
15
+ def compile(name, options = {})
16
+ # Set options
17
+ options = @options.merge options
18
+
19
+ # Get the tasks
20
+ task = @tasks[name]
21
+
22
+ # Compile the task
23
+ task.compile options
19
24
  end
20
25
 
21
- # Compile the tasks
22
- def compile(args = {})
23
- # Each the steps
24
- @tasks.map do |task|
26
+ # Compile all the tasks
27
+ def compile_all(options = {})
28
+ # Each tasks
29
+ @tasks.keys.map do |name|
25
30
  # Compile the task
26
- task.compile args
31
+ compile name, options
27
32
  end
28
33
  end
29
34
 
30
35
  # Generate the SSH command
31
- def command(args = {}, escape = true)
36
+ def command(name, options = {}, ssh_command = true, escape = true)
37
+ # Set options
38
+ options = @options.merge options
39
+
40
+ # Generate task command
41
+ task = @tasks[name].command options, false
42
+
43
+ # Do not return the SSH command
44
+ return task unless ssh_command
45
+
46
+ # Generate the full command
47
+ SSH.command task, escape
48
+ end
49
+
50
+ # Generate all tasks commands
51
+ def command_all(options = {}, escape = true)
32
52
  # Each tasks
33
- tasks = @tasks.map do |task|
34
- task.command args, false
53
+ tasks = @tasks.keys.map do |name|
54
+ # Compile the task
55
+ command name, options, false
35
56
  end
36
57
 
37
58
  # Generate the full command
@@ -44,7 +65,9 @@ module Caracara
44
65
  attr_reader :tasks
45
66
 
46
67
  # Set a new task to the group
47
- def task(command)
68
+ # @param {Symbol} name The task name
69
+ # @param {Caracara::Task/String} task The task itself
70
+ def task(name, command)
48
71
  # Check the type of the command
49
72
  if command.is_a? String
50
73
  task = Task.new [command]
@@ -53,15 +76,15 @@ module Caracara
53
76
  end
54
77
 
55
78
  # Init the tasks
56
- @tasks = [] if @tasks.nil?
79
+ @tasks = {} if @tasks.nil?
57
80
 
58
- # Push it to the tasks
59
- @tasks.push task
81
+ # Set the task
82
+ @tasks[name] = task
60
83
  end
61
84
 
62
85
  # Init
63
- def init
64
- new @tasks
86
+ def init(options = {})
87
+ new @tasks, options
65
88
  end
66
89
 
67
90
  end
@@ -6,8 +6,9 @@ module Caracara
6
6
  @steps = []
7
7
 
8
8
  # Initialize
9
- def initialize(steps)
9
+ def initialize(steps, args = {})
10
10
  @steps = steps
11
+ @options = args
11
12
  end
12
13
 
13
14
  # Steps
@@ -17,10 +18,13 @@ module Caracara
17
18
 
18
19
  # Compile the tasks
19
20
  def compile(args = {})
21
+ # Merge args with defult options
22
+ options = @options.merge args
23
+
20
24
  # Each the steps
21
25
  @steps.map do |step|
22
26
  # Compile the mustache template
23
- Mustache.render step, args
27
+ Mustache.render step, options
24
28
  end
25
29
  end
26
30
 
@@ -58,9 +62,10 @@ module Caracara
58
62
  @steps.push cmd
59
63
  end
60
64
 
61
- def init
65
+ # Initialize a task
66
+ def init(args = {})
62
67
  # Create a new instance
63
- new @steps
68
+ new @steps, args
64
69
  end
65
70
  end
66
71
  end
@@ -1,5 +1,5 @@
1
1
  module Caracara
2
2
  def self.version
3
- '0.1.0'
3
+ '0.2.0'
4
4
  end
5
5
  end
@@ -10,29 +10,31 @@ end
10
10
  # Define a new group
11
11
  class GroupSpec < Caracara::Group
12
12
  # Define a task from a class
13
- task FolderTask
13
+ task :folder, FolderTask
14
14
 
15
15
  # Simple task
16
- task 'mv anotherFolder/file.txt {{folder}}/movedFile.txt'
16
+ task :move, 'mv anotherFolder/file.txt {{folder}}/movedFile.txt'
17
17
  end
18
18
 
19
19
  # Kickstart with the tests
20
20
  describe 'Groups' do
21
21
  # Initialize the group
22
- let(:group) { GroupSpec.init }
22
+ let(:group) {
23
+ GroupSpec.init folder: 'niceFolder'
24
+ }
23
25
 
24
26
  it 'should return the right tasks from GroupSpec' do
25
27
  # Get the tasks
26
28
  tasks = group.tasks
27
29
 
28
30
  # Assertions
29
- expect(tasks[0]).to be_an_instance_of(FolderTask)
30
- expect(tasks[1]).to be_an_instance_of(Caracara::Task)
31
+ expect(tasks[:folder]).to be_an_instance_of(FolderTask)
32
+ expect(tasks[:move]).to be_an_instance_of(Caracara::Task)
31
33
  end
32
34
 
33
- it 'should return the compiled tasks' do
35
+ it 'should compile all the tasks' do
34
36
  # Get the compile tasks
35
- tasks = group.compile folder: 'niceFolder'
37
+ tasks = group.compile_all
36
38
 
37
39
  # Assertions
38
40
  expect(tasks[0][0]).to eq('mkdir niceFolder/')
@@ -40,11 +42,45 @@ describe 'Groups' do
40
42
  expect(tasks[1][0]).to eq('mv anotherFolder/file.txt niceFolder/movedFile.txt')
41
43
  end
42
44
 
43
- it 'should return the group command' do
45
+ it 'should compile just one task' do
46
+ # Compile it
47
+ task = group.compile :move
48
+
49
+ # Assertions
50
+ expect(task[0]).to eq('mv anotherFolder/file.txt niceFolder/movedFile.txt')
51
+ end
52
+
53
+ it 'should compile all the tasks using the defined args' do
54
+ # Get the compiled tasks
55
+ tasks = group.compile_all folder: 'argsFolder'
56
+
57
+ # Assertions
58
+ expect(tasks[0][0]).to eq('mkdir argsFolder/')
59
+ expect(tasks[0][1]).to eq('chmod -R 775 argsFolder/')
60
+ expect(tasks[1][0]).to eq('mv anotherFolder/file.txt argsFolder/movedFile.txt')
61
+ end
62
+
63
+ it 'should compile one task using the defined args' do
64
+ # Get the compiled tasks
65
+ task = group.compile :move, folder: 'argsFolder'
66
+
67
+ # Assertions
68
+ expect(task[0]).to eq('mv anotherFolder/file.txt argsFolder/movedFile.txt')
69
+ end
70
+
71
+ it 'should generate the group command' do
44
72
  # Get the command
45
- command = group.command folder: 'niceFolder'
73
+ command = group.command_all
46
74
 
47
75
  # Assertions
48
76
  expect(command).to eq("mkdir\\ niceFolder/'\n'chmod\\ -R\\ 775\\ niceFolder/'\n'mv\\ anotherFolder/file.txt\\ niceFolder/movedFile.txt")
49
77
  end
78
+
79
+ it 'should generate one task command' do
80
+ # Get the command
81
+ command = group.command :move
82
+
83
+ # Assertions
84
+ expect(command).to eq("mv\\ anotherFolder/file.txt\\ niceFolder/movedFile.txt")
85
+ end
50
86
  end
@@ -55,11 +55,13 @@ describe 'SSH' do
55
55
  # Generate command
56
56
  command = Caracara::SSH.generate 'ubuntu', 'localhost', %{ls -la}
57
57
 
58
- # Run the command
59
- result = Caracara::SSH.exec command
58
+ # Check if travis is not running this
59
+ if ENV['travis'] != 'true'
60
+ # Run the command
61
+ result = Caracara::SSH.exec command
60
62
 
61
- # Assertions
62
- # it should return false because ssh localhost it not enable
63
- expect(result[:status]).to eq(false)
63
+ # it should return false because ssh localhost it not enable
64
+ expect(result[:status]).to eq(false)
65
+ end
64
66
  end
65
67
  end
@@ -21,18 +21,13 @@ end
21
21
  # Tests
22
22
  describe 'Task' do
23
23
  # Initialize the task
24
- let(:task) { TaskSpec.init }
25
-
26
- # Define the task options
27
- let(:options) {
28
- {
29
- user: 'ubuntu',
30
- folder: {
31
- name: 'niceFolder',
32
- permission: 755
33
- },
34
- text: 'Some nice text!'
35
- }
24
+ let(:task) {
25
+ TaskSpec.init user: 'ubuntu',
26
+ folder: {
27
+ name: 'niceFolder',
28
+ permission: 755
29
+ },
30
+ text: 'Some nice text!'
36
31
  }
37
32
 
38
33
  it 'should return the steps' do
@@ -48,7 +43,7 @@ describe 'Task' do
48
43
 
49
44
  it 'should compile the steps' do
50
45
  # Get the steps
51
- steps = task.compile options
46
+ steps = task.compile
52
47
 
53
48
  # Assertions
54
49
  expect(steps[0]).to eq('mkdir niceFolder/')
@@ -57,9 +52,24 @@ describe 'Task' do
57
52
  expect(steps[3]).to eq('(cd niceFolder && (echo "Some nice text!" > file.txt))')
58
53
  end
59
54
 
55
+ it 'should compile the steps using specific args' do
56
+ # Get the steps
57
+ steps = task.compile user: 'root',
58
+ folder: {
59
+ name: 'argsFolder',
60
+ permission: 655
61
+ }
62
+
63
+ # Assertions
64
+ expect(steps[0]).to eq('mkdir argsFolder/')
65
+ expect(steps[1]).to eq('chown -R root argsFolder')
66
+ expect(steps[2]).to eq('chmod -R 655 argsFolder/')
67
+ expect(steps[3]).to eq('(cd argsFolder && (echo "Some nice text!" > file.txt))')
68
+ end
69
+
60
70
  it 'should generate the SSH command' do
61
71
  # Command
62
- command = task.command options
72
+ command = task.command
63
73
 
64
74
  # Assertions
65
75
  expect(command).to eq("mkdir\\ niceFolder/'\n'chown\\ -R\\ ubuntu\\ niceFolder'\n'chmod\\ -R\\ 755\\ niceFolder/'\n'\\(cd\\ niceFolder\\ \\&\\&\\ \\(echo\\ \\\"Some\\ nice\\ text\\!\\\"\\ \\>\\ file.txt\\)\\)")
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caracara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Corado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: mustache
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +45,7 @@ extensions: []
59
45
  extra_rdoc_files: []
60
46
  files:
61
47
  - .gitignore
48
+ - .travis.yml
62
49
  - Dockerfile
63
50
  - Gemfile
64
51
  - Gemfile.lock