caracara 0.0.0.alpha → 0.1.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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +58 -6
- data/lib/caracara/task.rb +13 -3
- data/lib/caracara/version.rb +1 -1
- data/spec/caracara/task_spec.rb +21 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d2f961067ed99bd7e85d8c20a16393acbe22b7
|
4
|
+
data.tar.gz: 9f06a43d93e8d4898b4a605b785b99d1c9762daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43907c32b6f1dc51c42eb41172ea48276187c8706c8246998aa47d9099fbf1df79238c5ac0c6406e98440c090a6a46c4e985e220e06b5bf036071cd7abf5d37a
|
7
|
+
data.tar.gz: 4cd556a08df8ddd5d86a2b201569be30faf25bb2a17ad4a66f0af98031d69c403902ea8538119b4cea8574cf15b2cfc64892d514d69f12788d992cfccf1c6c20
|
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,29 +2,81 @@
|
|
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
|
5
|
-
**Task**: Everything is based on this entity, it has steps that are the commands that will be performed somewhere.
|
6
|
-
|
5
|
+
**Task**: Everything is based on this entity, it has steps that are the commands that will be performed somewhere. *Ex: git clone*
|
6
|
+
|
7
|
+
**Group**: Group of tasks that represents an business operation. *Ex: deploy*
|
7
8
|
|
8
9
|
# Usage
|
9
10
|
How to use this crazy gem.
|
10
11
|
|
11
|
-
**Define
|
12
|
+
**Define some tasks**
|
12
13
|
```ruby
|
13
14
|
class GitCloneTask < Caracara::Task
|
14
15
|
# Clone the repository
|
15
|
-
step 'git clone {{repository}} {{dest}} --recursive'
|
16
|
+
step 'git clone {{repository}} {{dest}}/scm/{{version}} --recursive'
|
16
17
|
|
17
18
|
# Run commands inside the repo folder
|
18
|
-
dir '{{dest}}' do
|
19
|
+
dir '{{dest}}/scm/{{version}}' do
|
19
20
|
# Checkout to the lastest tag
|
20
21
|
step 'git checkout {{version}}'
|
21
22
|
|
22
23
|
# Remove .git/ folder
|
23
|
-
step ''
|
24
|
+
step 'rm -rf .git/'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class DockerTask < Caracara::Task
|
29
|
+
# Access new app folder
|
30
|
+
dir '{{dest}}/scm/{{version}}' do
|
31
|
+
# Build the image
|
32
|
+
step 'docker build -t {{image}} .'
|
33
|
+
|
34
|
+
# Remove the current container
|
35
|
+
step 'docker rm -f {{container}}'
|
36
|
+
|
37
|
+
# Start it again
|
38
|
+
step 'docker run -d --name {{container}} {{image}}'
|
24
39
|
end
|
25
40
|
end
|
26
41
|
```
|
27
42
|
|
43
|
+
**Group these tasks**
|
44
|
+
```ruby
|
45
|
+
class DeployGroup < Caracara::Group
|
46
|
+
# Clone it
|
47
|
+
task GitCloneTask
|
48
|
+
|
49
|
+
# Dockernize it
|
50
|
+
task DockerTask
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
**Intialize the group**
|
55
|
+
```ruby
|
56
|
+
# Initialize the group
|
57
|
+
deploy = DeployGroup.init
|
58
|
+
```
|
59
|
+
|
60
|
+
**Generate the command**
|
61
|
+
```ruby
|
62
|
+
# Set the options
|
63
|
+
options = {
|
64
|
+
repository: 'git@github.com:gabrielcorado/caracara.git',
|
65
|
+
dest: '/home/user/apps',
|
66
|
+
version: '0.0.0.alpha',
|
67
|
+
image: 'caracara',
|
68
|
+
container: 'caracara_app'
|
69
|
+
}
|
70
|
+
|
71
|
+
# Generate the SSH command
|
72
|
+
command = deploy.command options
|
73
|
+
```
|
74
|
+
|
75
|
+
**Run the command in your server**
|
76
|
+
```ruby
|
77
|
+
Caracara::SSH.exec 'user', 'localhost', command
|
78
|
+
```
|
79
|
+
|
28
80
|
# Development
|
29
81
|
* **Generating docker image**
|
30
82
|
* `docker build -t caracara .`
|
data/lib/caracara/task.rb
CHANGED
@@ -34,9 +34,19 @@ module Caracara
|
|
34
34
|
# Task steps
|
35
35
|
attr_reader :steps
|
36
36
|
|
37
|
-
# Run
|
38
|
-
|
39
|
-
|
37
|
+
# Run steps inside a dir
|
38
|
+
def dir(name, &blk)
|
39
|
+
# Store the current steps and set a blank steps
|
40
|
+
old, @steps = @steps, nil
|
41
|
+
|
42
|
+
# Generate the block steps
|
43
|
+
result = yield
|
44
|
+
|
45
|
+
# Restore the old steps
|
46
|
+
@steps = old
|
47
|
+
|
48
|
+
# Put dir commands in the steps
|
49
|
+
@steps.push "(cd #{name} && (#{result.join('\n')}))"
|
40
50
|
end
|
41
51
|
|
42
52
|
# Add a step
|
data/lib/caracara/version.rb
CHANGED
data/spec/caracara/task_spec.rb
CHANGED
@@ -6,6 +6,10 @@ class TaskSpec < Caracara::Task
|
|
6
6
|
step 'mkdir {{folder.name}}/'
|
7
7
|
step 'chown -R {{user}} {{folder.name}}'
|
8
8
|
step 'chmod -R {{folder.permission}} {{folder.name}}/'
|
9
|
+
|
10
|
+
dir '{{folder.name}}' do
|
11
|
+
step 'echo "{{text}}" > file.txt'
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
class TaskTwoSpec < Caracara::Task
|
@@ -19,6 +23,18 @@ describe 'Task' do
|
|
19
23
|
# Initialize the task
|
20
24
|
let(:task) { TaskSpec.init }
|
21
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
|
+
}
|
36
|
+
}
|
37
|
+
|
22
38
|
it 'should return the steps' do
|
23
39
|
# Get the steps
|
24
40
|
steps = task.steps
|
@@ -27,23 +43,25 @@ describe 'Task' do
|
|
27
43
|
expect(steps[0]).to eq('mkdir {{folder.name}}/')
|
28
44
|
expect(steps[1]).to eq('chown -R {{user}} {{folder.name}}')
|
29
45
|
expect(steps[2]).to eq('chmod -R {{folder.permission}} {{folder.name}}/')
|
46
|
+
expect(steps[3]).to eq('(cd {{folder.name}} && (echo "{{text}}" > file.txt))')
|
30
47
|
end
|
31
48
|
|
32
49
|
it 'should compile the steps' do
|
33
50
|
# Get the steps
|
34
|
-
steps = task.compile
|
51
|
+
steps = task.compile options
|
35
52
|
|
36
53
|
# Assertions
|
37
54
|
expect(steps[0]).to eq('mkdir niceFolder/')
|
38
55
|
expect(steps[1]).to eq('chown -R ubuntu niceFolder')
|
39
56
|
expect(steps[2]).to eq('chmod -R 755 niceFolder/')
|
57
|
+
expect(steps[3]).to eq('(cd niceFolder && (echo "Some nice text!" > file.txt))')
|
40
58
|
end
|
41
59
|
|
42
60
|
it 'should generate the SSH command' do
|
43
61
|
# Command
|
44
|
-
command = task.command
|
62
|
+
command = task.command options
|
45
63
|
|
46
64
|
# Assertions
|
47
|
-
expect(command).to eq("mkdir\\ niceFolder/'\n'chown\\ -R\\ ubuntu\\ niceFolder'\n'chmod\\ -R\\ 755\\ niceFolder/")
|
65
|
+
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\\)\\)")
|
48
66
|
end
|
49
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caracara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Corado
|
@@ -58,6 +58,7 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- .gitignore
|
61
62
|
- Dockerfile
|
62
63
|
- Gemfile
|
63
64
|
- Gemfile.lock
|
@@ -86,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
87
|
version: '0'
|
87
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
89
|
requirements:
|
89
|
-
- - '
|
90
|
+
- - '>='
|
90
91
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
92
|
+
version: '0'
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
95
|
rubygems_version: 2.0.14
|