elders 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/README.md +31 -0
- data/lib/elders/task.rb +6 -3
- data/lib/elders/version.rb +1 -1
- data/spec/elders/task_spec.rb +17 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c8d40944aca21095bb21978fed816a25056a41
|
4
|
+
data.tar.gz: 388f3d4a1fab62015ca59babdc9d58ed8a6a70d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f02428106de1ac55c6e69818389431ef3c2ec0317d27f937cc7bac112a58c2a3e86fe2e764e2adc84dae5d6fb13159bd4420f59c85a35144b1abd96dbff521b6
|
7
|
+
data.tar.gz: cb10892d9558fd9dfc45776ae63e49c4b34426f835ba429617534d563ae3f76646b1597807a06a416121c4aff9891ec1cdb741bed6adead0636c9f4b93c768b5
|
data/.gitignore
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
# Elders [![Build Status](https://travis-ci.org/gabrielcorado/elders.svg?branch=master)](https://travis-ci.org/gabrielcorado/elders)
|
2
|
+
Enable you to run your command line tasks in containers.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
### Task
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
# Create a new task
|
10
|
+
# Params are `name`, `image` and `command`
|
11
|
+
task = Elder::Task.new 'sample', 'ruby', 'ruby'
|
12
|
+
|
13
|
+
# Start the task passing params to the command and ENV variables
|
14
|
+
task.start '-v'
|
15
|
+
|
16
|
+
# Wait until the task is finished
|
17
|
+
sleep 1
|
18
|
+
|
19
|
+
# Return it results
|
20
|
+
task.logs
|
21
|
+
|
22
|
+
# Remove the docker container used in this operation
|
23
|
+
task.clean
|
24
|
+
```
|
25
|
+
|
26
|
+
## TODO
|
27
|
+
* Enable more options to the task (like `links`, `volumes`, `network`).
|
28
|
+
* Create a method `:wait` for the `Elders::Task`, this will block
|
29
|
+
the main thread until the task is completed.
|
30
|
+
* Doc the `Elders::Stack` usage.
|
31
|
+
|
1
32
|
## Development
|
2
33
|
* Running tests:
|
3
34
|
1. Build the Docker image: `docker build -t elders .`
|
data/lib/elders/task.rb
CHANGED
@@ -31,7 +31,10 @@ class Elders::Task
|
|
31
31
|
command = "#{command} #{params}" unless params.nil?
|
32
32
|
|
33
33
|
# Create the container
|
34
|
-
@container = Docker::Container.create 'Image' => @image_name,
|
34
|
+
@container = Docker::Container.create 'Image' => @image_name,
|
35
|
+
'Cmd' => Shellwords.split(command),
|
36
|
+
'Env' => env,
|
37
|
+
'Tty' => true
|
35
38
|
|
36
39
|
# Start it
|
37
40
|
@container.start
|
@@ -47,7 +50,7 @@ class Elders::Task
|
|
47
50
|
|
48
51
|
# Task logs
|
49
52
|
def logs
|
50
|
-
container.logs stdout: true
|
53
|
+
container.logs stdout: true, stderr: true
|
51
54
|
end
|
52
55
|
|
53
56
|
# Delete the container
|
@@ -91,7 +94,7 @@ class Elders::Task
|
|
91
94
|
return nil unless completed?
|
92
95
|
|
93
96
|
# Check the task status code
|
94
|
-
@promise.value['StatusCode']
|
97
|
+
@promise.value['StatusCode'] != 0
|
95
98
|
end
|
96
99
|
|
97
100
|
# Completed the task?
|
data/lib/elders/version.rb
CHANGED
data/spec/elders/task_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
# Tests
|
5
5
|
describe 'Task' do
|
6
6
|
# Time to complete the task
|
7
|
-
let(:time) {
|
7
|
+
let(:time) { 1 }
|
8
8
|
|
9
9
|
# Create the task before the tests
|
10
10
|
before(:all) do
|
@@ -38,6 +38,22 @@ describe 'Task' do
|
|
38
38
|
expect(@task.logs).to match(/APP_ENV/)
|
39
39
|
end
|
40
40
|
|
41
|
+
it 'should get the errors from a task' do
|
42
|
+
# Create a task with error
|
43
|
+
task = Elders::Task.new 'with-error', 'busybox', 'some-non-sense command'
|
44
|
+
|
45
|
+
# Start the task
|
46
|
+
task.start
|
47
|
+
|
48
|
+
# Wait for it run
|
49
|
+
sleep time
|
50
|
+
|
51
|
+
# Assertions
|
52
|
+
expect(task.error?).to eq(true)
|
53
|
+
expect(task.completed?).to eq(true)
|
54
|
+
expect(task.logs.size).to be > 1
|
55
|
+
end
|
56
|
+
|
41
57
|
it 'should be deleted' do
|
42
58
|
# Start the task
|
43
59
|
@task.start
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elders
|
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
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -72,6 +72,7 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- ".gitignore"
|
75
76
|
- ".travis.yml"
|
76
77
|
- Dockerfile
|
77
78
|
- Gemfile
|