caracara 0.0.0.alpha

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73d2514d4beb7b3e72836421a49f74d86609d536
4
+ data.tar.gz: 1d53094514ab617caa62cbad1e4b87c484a1c98e
5
+ SHA512:
6
+ metadata.gz: d6398fc70be01d80e5447c901f6341f1bcdb1c720fc29c230de3c9d3f3b6e4636c5405c9190746d1694aeac33ee7709f18ea17f3fcafdc279ce13d235459ca2b
7
+ data.tar.gz: f4d348856521c22e484c5ff44d68facc86f60f57c63f971528cbe30fed0ac63f73cd120a147878943d6bbefdeded841735f2b5ff3845c2bac65d749a179d80a4
data/Dockerfile ADDED
@@ -0,0 +1,17 @@
1
+ # Ruby Image
2
+ FROM ruby:2.2.0
3
+
4
+ # Install Bundler
5
+ RUN gem install bundler --no-ri --no-rdoc
6
+
7
+ # Make the app folder
8
+ RUN mkdir caracara/
9
+
10
+ # Set workdir
11
+ WORKDIR caracara/
12
+
13
+ # Add the rest of the source
14
+ ADD . .
15
+
16
+ # Bundle install it
17
+ RUN bundle install
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ caracara (0.0.0.pre.alpha)
5
+ mustache (~> 1.0)
6
+ rake
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.2.5)
12
+ mustache (1.0.2)
13
+ rake (10.4.2)
14
+ rspec (3.0.0)
15
+ rspec-core (~> 3.0.0)
16
+ rspec-expectations (~> 3.0.0)
17
+ rspec-mocks (~> 3.0.0)
18
+ rspec-core (3.0.4)
19
+ rspec-support (~> 3.0.0)
20
+ rspec-expectations (3.0.4)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.0.0)
23
+ rspec-mocks (3.0.4)
24
+ rspec-support (~> 3.0.0)
25
+ rspec-support (3.0.4)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ caracara!
32
+ rspec (~> 3.0.0)
33
+
34
+ BUNDLED WITH
35
+ 1.10.6
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Caracara
2
+ Task runner based on [Envoy](http://laravel.com/docs/5.1/envoy) and [Mina](http://mina-deploy.github.io/mina/)
3
+
4
+ # Concepts
5
+ **Task**: Everything is based on this entity, it has steps that are the commands that will be performed somewhere. ~~Ex: git-clone~~
6
+ **Group**: Group of tasks that represents an business operation. ~~Ex: deploy~~
7
+
8
+ # Usage
9
+ How to use this crazy gem.
10
+
11
+ **Define a task**
12
+ ```ruby
13
+ class GitCloneTask < Caracara::Task
14
+ # Clone the repository
15
+ step 'git clone {{repository}} {{dest}} --recursive'
16
+
17
+ # Run commands inside the repo folder
18
+ dir '{{dest}}' do
19
+ # Checkout to the lastest tag
20
+ step 'git checkout {{version}}'
21
+
22
+ # Remove .git/ folder
23
+ step ''
24
+ end
25
+ end
26
+ ```
27
+
28
+ # Development
29
+ * **Generating docker image**
30
+ * `docker build -t caracara .`
31
+ * **Running the RSpec (for shell fish)**
32
+ * `docker run -v (pwd):/caracara --rm caracara bundle exec rspec`
data/caracara.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ require './lib/caracara/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'caracara'
5
+ s.version = Caracara.version
6
+ s.summary = ''
7
+ s.description = ''
8
+ s.author = 'Gabriel Corado'
9
+ s.email = 'gabrielcorado@mail.com'
10
+ s.homepage = 'http://github.com/gabrielcorado/caracara'
11
+
12
+ s.files = `git ls-files`.strip.split("\n")
13
+ s.executables = Dir["bin/*"].map { |f| File.basename(f) }
14
+
15
+ s.add_dependency 'rake'
16
+ s.add_dependency 'mustache', '~> 1.0'
17
+
18
+ s.add_development_dependency 'rspec', '~> 3.0.0'
19
+ # s.add_dependency 'open4', '~> 1.3.4'
20
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ module Caracara
3
+ # Group
4
+ class Group
5
+ # Tasks
6
+ attr_reader :tasks
7
+
8
+ # Initialize
9
+ def initialize(tasks = [])
10
+ @tasks = tasks
11
+ end
12
+
13
+ # Tasks access
14
+ def tasks
15
+ # Map the tasks
16
+ @tasks.map do |task|
17
+ task
18
+ end
19
+ end
20
+
21
+ # Compile the tasks
22
+ def compile(args = {})
23
+ # Each the steps
24
+ @tasks.map do |task|
25
+ # Compile the task
26
+ task.compile args
27
+ end
28
+ end
29
+
30
+ # Generate the SSH command
31
+ def command(args = {}, escape = true)
32
+ # Each tasks
33
+ tasks = @tasks.map do |task|
34
+ task.command args, false
35
+ end
36
+
37
+ # Generate the full command
38
+ SSH.command tasks, escape
39
+ end
40
+
41
+ # Static methods
42
+ class << self
43
+ # Tasks
44
+ attr_reader :tasks
45
+
46
+ # Set a new task to the group
47
+ def task(command)
48
+ # Check the type of the command
49
+ if command.is_a? String
50
+ task = Task.new [command]
51
+ else
52
+ task = command.init
53
+ end
54
+
55
+ # Init the tasks
56
+ @tasks = [] if @tasks.nil?
57
+
58
+ # Push it to the tasks
59
+ @tasks.push task
60
+ end
61
+
62
+ # Init
63
+ def init
64
+ new @tasks
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,69 @@
1
+ # Include shellwords
2
+ require 'shellwords'
3
+
4
+ #
5
+ module Caracara
6
+ # SSH class
7
+ class SSH
8
+ # Static methods
9
+ class << self
10
+ # Login command
11
+ def login(user, host, options = {})
12
+ # Basic command
13
+ command = "ssh #{user}@#{host}"
14
+
15
+ # Identity file
16
+ command << " -i #{options[:key]}" unless options[:key].nil?
17
+
18
+ # Port
19
+ command << " -p #{options[:port]}" unless options[:port].nil?
20
+
21
+ # Forward agent
22
+ command << ' -A' if options[:forward_agent]
23
+
24
+ # Check strict host key
25
+ command << ' -o StrictHostKeyChecking=no'
26
+
27
+ # Disable pseudo terminal
28
+ command << ' -T'
29
+ end
30
+
31
+ # Escape the command
32
+ def escape(cmd)
33
+ Shellwords.escape cmd
34
+ end
35
+
36
+ # Generate a command
37
+ def command(cmd, escape = true)
38
+ # Joing commands
39
+ cmd = cmd.join("\n") if cmd.is_a? Array
40
+
41
+ # Escape the command
42
+ cmd = escape(cmd) if escape
43
+
44
+ # Return the command
45
+ cmd
46
+ end
47
+
48
+ # Generate the SSH command
49
+ def generate(user, host, cmd, ssh_options = {})
50
+ "#{login(user, host, ssh_options)} -- #{command(cmd)}"
51
+ end
52
+
53
+ # Exec the SSH command
54
+ def exec(cmd)
55
+ # System the command
56
+ result = `#{cmd}`
57
+
58
+ # Return the status
59
+ status = $?.to_i
60
+
61
+ # Return the status `true` for success and `false` for error
62
+ {
63
+ result: result,
64
+ status: !(status.is_a?(Fixnum) && status > 0)
65
+ }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ module Caracara
3
+ # Task class
4
+ class Task
5
+ # Task steps
6
+ @steps = []
7
+
8
+ # Initialize
9
+ def initialize(steps)
10
+ @steps = steps
11
+ end
12
+
13
+ # Steps
14
+ def steps
15
+ @steps
16
+ end
17
+
18
+ # Compile the tasks
19
+ def compile(args = {})
20
+ # Each the steps
21
+ @steps.map do |step|
22
+ # Compile the mustache template
23
+ Mustache.render step, args
24
+ end
25
+ end
26
+
27
+ # Generate the SSH command
28
+ def command(args = {}, escape = true)
29
+ SSH.command compile(args), escape
30
+ end
31
+
32
+ # Static methods
33
+ class << self
34
+ # Task steps
35
+ attr_reader :steps
36
+
37
+ # Run commands inside a dir
38
+ # @TODO
39
+ def dir(name)
40
+ end
41
+
42
+ # Add a step
43
+ def step(cmd)
44
+ # Define the step
45
+ @steps = [] if @steps.nil?
46
+
47
+ # Add a new step
48
+ @steps.push cmd
49
+ end
50
+
51
+ def init
52
+ # Create a new instance
53
+ new @steps
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module Caracara
2
+ def self.version
3
+ '0.0.0.alpha'
4
+ end
5
+ end
data/lib/caracara.rb ADDED
@@ -0,0 +1,11 @@
1
+ # Define the module
2
+ module Caracara
3
+ end
4
+
5
+ # Mustache
6
+ require 'mustache'
7
+
8
+ # Include the sources
9
+ require 'caracara/ssh'
10
+ require 'caracara/task'
11
+ require 'caracara/group'
@@ -0,0 +1,50 @@
1
+ # Include the helper
2
+ require 'spec_helper'
3
+
4
+ # Define a simple task
5
+ class FolderTask < Caracara::Task
6
+ step 'mkdir {{folder}}/'
7
+ step 'chmod -R 775 {{folder}}/'
8
+ end
9
+
10
+ # Define a new group
11
+ class GroupSpec < Caracara::Group
12
+ # Define a task from a class
13
+ task FolderTask
14
+
15
+ # Simple task
16
+ task 'mv anotherFolder/file.txt {{folder}}/movedFile.txt'
17
+ end
18
+
19
+ # Kickstart with the tests
20
+ describe 'Groups' do
21
+ # Initialize the group
22
+ let(:group) { GroupSpec.init }
23
+
24
+ it 'should return the right tasks from GroupSpec' do
25
+ # Get the tasks
26
+ tasks = group.tasks
27
+
28
+ # Assertions
29
+ expect(tasks[0]).to be_an_instance_of(FolderTask)
30
+ expect(tasks[1]).to be_an_instance_of(Caracara::Task)
31
+ end
32
+
33
+ it 'should return the compiled tasks' do
34
+ # Get the compile tasks
35
+ tasks = group.compile folder: 'niceFolder'
36
+
37
+ # Assertions
38
+ expect(tasks[0][0]).to eq('mkdir niceFolder/')
39
+ expect(tasks[0][1]).to eq('chmod -R 775 niceFolder/')
40
+ expect(tasks[1][0]).to eq('mv anotherFolder/file.txt niceFolder/movedFile.txt')
41
+ end
42
+
43
+ it 'should return the group command' do
44
+ # Get the command
45
+ command = group.command folder: 'niceFolder'
46
+
47
+ # Assertions
48
+ expect(command).to eq("mkdir\\ niceFolder/'\n'chmod\\ -R\\ 775\\ niceFolder/'\n'mv\\ anotherFolder/file.txt\\ niceFolder/movedFile.txt")
49
+ end
50
+ end
@@ -0,0 +1,65 @@
1
+ # Include the helper
2
+ require 'spec_helper'
3
+
4
+ # Tests
5
+ describe 'SSH' do
6
+ context 'login' do
7
+ it 'should be generated without all the params' do
8
+ # Generate the SSH command
9
+ command = Caracara::SSH.login 'user', 'localhost'
10
+
11
+ # Assertions
12
+ expect(command).to eq('ssh user@localhost -o StrictHostKeyChecking=no -T')
13
+ end
14
+
15
+ it 'should be generated with all the param' do
16
+ # Generate the SSH command
17
+ command = Caracara::SSH.login 'user', 'localhost', key: '~/my-key', port: 22, forward_agent: true
18
+
19
+ # Assertions
20
+ expect(command).to eq('ssh user@localhost -i ~/my-key -p 22 -A -o StrictHostKeyChecking=no -T')
21
+ end
22
+ end
23
+
24
+ context 'string command' do
25
+ it 'should be generated with a string command' do
26
+ # Generate command
27
+ command = Caracara::SSH.command %{ls -la}
28
+
29
+ # Assertions
30
+ expect(command).to eq('ls\\ -la')
31
+ end
32
+
33
+
34
+ it 'should be generated with an array of commands' do
35
+ # Generate commands
36
+ commands = Caracara::SSH.command([
37
+ 'ls -la',
38
+ 'pwd'
39
+ ])
40
+
41
+ # Assertions
42
+ expect(commands).to eq("ls\\ -la'\n'pwd")
43
+ end
44
+ end
45
+
46
+ it 'should generate the SSH command' do
47
+ # Generate command
48
+ command = Caracara::SSH.generate 'user', 'localhost', %{ls -la}
49
+
50
+ # Assertions
51
+ expect(command).to eq('ssh user@localhost -o StrictHostKeyChecking=no -T -- ls\\ -la')
52
+ end
53
+
54
+ it 'should execute the SSH command' do
55
+ # Generate command
56
+ command = Caracara::SSH.generate 'ubuntu', 'localhost', %{ls -la}
57
+
58
+ # Run the command
59
+ result = Caracara::SSH.exec command
60
+
61
+ # Assertions
62
+ # it should return false because ssh localhost it not enable
63
+ expect(result[:status]).to eq(false)
64
+ end
65
+ end
@@ -0,0 +1,49 @@
1
+ # Include the helper
2
+ require 'spec_helper'
3
+
4
+ # Class definitions
5
+ class TaskSpec < Caracara::Task
6
+ step 'mkdir {{folder.name}}/'
7
+ step 'chown -R {{user}} {{folder.name}}'
8
+ step 'chmod -R {{folder.permission}} {{folder.name}}/'
9
+ end
10
+
11
+ class TaskTwoSpec < Caracara::Task
12
+ step 'mkdir {{folder.name}}/'
13
+ step 'chown -R {{user}} {{folder.name}}'
14
+ step 'chmod -R {{folder.permission}} {{folder.name}}/'
15
+ end
16
+
17
+ # Tests
18
+ describe 'Task' do
19
+ # Initialize the task
20
+ let(:task) { TaskSpec.init }
21
+
22
+ it 'should return the steps' do
23
+ # Get the steps
24
+ steps = task.steps
25
+
26
+ # Assertions
27
+ expect(steps[0]).to eq('mkdir {{folder.name}}/')
28
+ expect(steps[1]).to eq('chown -R {{user}} {{folder.name}}')
29
+ expect(steps[2]).to eq('chmod -R {{folder.permission}} {{folder.name}}/')
30
+ end
31
+
32
+ it 'should compile the steps' do
33
+ # Get the steps
34
+ steps = task.compile user: 'ubuntu', folder: { name: 'niceFolder', permission: 755 }
35
+
36
+ # Assertions
37
+ expect(steps[0]).to eq('mkdir niceFolder/')
38
+ expect(steps[1]).to eq('chown -R ubuntu niceFolder')
39
+ expect(steps[2]).to eq('chmod -R 755 niceFolder/')
40
+ end
41
+
42
+ it 'should generate the SSH command' do
43
+ # Command
44
+ command = task.command user: 'ubuntu', folder: { name: 'niceFolder', permission: 755 }
45
+
46
+ # Assertions
47
+ expect(command).to eq("mkdir\\ niceFolder/'\n'chown\\ -R\\ ubuntu\\ niceFolder'\n'chmod\\ -R\\ 755\\ niceFolder/")
48
+ end
49
+ end
@@ -0,0 +1,8 @@
1
+ # Include Caracara
2
+ require 'caracara'
3
+
4
+ # Rspec conf
5
+ RSpec.configure do |config|
6
+ config.order = 'random'
7
+ config.seed = '12345'
8
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caracara
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Corado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-02 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: mustache
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ description: ''
56
+ email: gabrielcorado@mail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - Dockerfile
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.md
65
+ - caracara.gemspec
66
+ - lib/caracara.rb
67
+ - lib/caracara/group.rb
68
+ - lib/caracara/ssh.rb
69
+ - lib/caracara/task.rb
70
+ - lib/caracara/version.rb
71
+ - spec/caracara/group_spec.rb
72
+ - spec/caracara/ssh_spec.rb
73
+ - spec/caracara/task_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/gabrielcorado/caracara
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>'
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.1
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.14
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: ''
98
+ test_files: []