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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d5f64b6b4e554a5e73d5262466b503430a03c4f
4
- data.tar.gz: b81f05d2015f8afd189c216fcea139d7492f4b51
3
+ metadata.gz: 15c8d40944aca21095bb21978fed816a25056a41
4
+ data.tar.gz: 388f3d4a1fab62015ca59babdc9d58ed8a6a70d8
5
5
  SHA512:
6
- metadata.gz: 05ad36e734a945b2c8c5eab2136cc926f0ce1886ec67fbdf3e3c899bdddac3ea5d025070922ef2a5238e02fdb38037d5d682712f3d9eecefbb7039a8ee70e24f
7
- data.tar.gz: 67694110b341ffc277eb04afce37ba38406e4410a8f64a53fdcd330cbde443609823decc90091b367ec9f5219f1913221fc8f681feea7d6a1c7734585c0569cf
6
+ metadata.gz: f02428106de1ac55c6e69818389431ef3c2ec0317d27f937cc7bac112a58c2a3e86fe2e764e2adc84dae5d6fb13159bd4420f59c85a35144b1abd96dbff521b6
7
+ data.tar.gz: cb10892d9558fd9dfc45776ae63e49c4b34426f835ba429617534d563ae3f76646b1597807a06a416121c4aff9891ec1cdb741bed6adead0636c9f4b93c768b5
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/.travis.yml CHANGED
@@ -7,5 +7,8 @@ rvm:
7
7
  services:
8
8
  - docker
9
9
 
10
+ before_script:
11
+ - docker pull busybox
12
+
10
13
  script:
11
14
  - bundle exec rspec
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, 'Cmd' => Shellwords.split(command), 'Env' => env
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'] > 0
97
+ @promise.value['StatusCode'] != 0
95
98
  end
96
99
 
97
100
  # Completed the task?
@@ -2,6 +2,6 @@
2
2
  module Elders
3
3
  # Gem Version
4
4
  def self.version
5
- '0.0.0'.freeze
5
+ '0.1.0'.freeze
6
6
  end
7
7
  end
@@ -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) { 0.1 }
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.0.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-09 00:00:00.000000000 Z
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