ikaros 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/ikaros +7 -0
- data/ikaros.gemspec +24 -0
- data/lib/ikaros/cli.rb +33 -0
- data/lib/ikaros/command.rb +35 -0
- data/lib/ikaros/config.rb +27 -0
- data/lib/ikaros/container.rb +40 -0
- data/lib/ikaros/docker.rb +56 -0
- data/lib/ikaros/error.rb +13 -0
- data/lib/ikaros/logger.rb +27 -0
- data/lib/ikaros/runner.rb +70 -0
- data/lib/ikaros/scripts/ruby.sh +21 -0
- data/lib/ikaros/version.rb +3 -0
- data/lib/ikaros.rb +16 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88b6e6934d3e77f2ff758aa72d9f05353eb76378
|
4
|
+
data.tar.gz: c8a7016b0176b471941f219d0108c73819d216bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa4729f0849597dbf8f5c3a85a9fe32ab2a4f8852f62f950d059432b65a7bf3ed9d6d425677a1d116aa2f7d9200b66f0666356e10dd765ee6334c44d0e62f5c8
|
7
|
+
data.tar.gz: 8094054e2a45ab29f12d3430ede3ad9c40872c2a2e9107abd314392ad27ccdf49d9c7d59e940c61a5fbe71bb34bd1918566ffca5acbad37a8fdc6b67c5705635
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Võ Anh Duy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Ikaros
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ikaros'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ikaros
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/ikaros/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/ikaros
ADDED
data/ikaros.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ikaros/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ikaros"
|
8
|
+
spec.version = Ikaros::VERSION
|
9
|
+
spec.authors = ["Võ Anh Duy"]
|
10
|
+
spec.email = ["voanhduy1512@live.com"]
|
11
|
+
spec.summary = "update later"
|
12
|
+
spec.description = "update later"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = ['ikaros']
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_runtime_dependency 'thor'
|
24
|
+
end
|
data/lib/ikaros/cli.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative './config'
|
3
|
+
require_relative './runner'
|
4
|
+
|
5
|
+
module Ikaros
|
6
|
+
class CLI < Thor
|
7
|
+
desc 'start', 'start test in docker'
|
8
|
+
method_options :debug => :boolean, :aliases => "-d"
|
9
|
+
def start
|
10
|
+
if options.debug?
|
11
|
+
Logger.log_level = ::Logger::DEBUG
|
12
|
+
end
|
13
|
+
check_requirement
|
14
|
+
|
15
|
+
config_file = Config.new '.ikaros.yml'
|
16
|
+
Runner.new(config_file).run
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def check_requirement
|
21
|
+
raise Error::ConfigMissing.new unless have_config_file?
|
22
|
+
raise Error::CacheBundleMissing.new unless have_bundle_cache?
|
23
|
+
end
|
24
|
+
|
25
|
+
def have_config_file?
|
26
|
+
::File.exist?('.ikaros.yml')
|
27
|
+
end
|
28
|
+
|
29
|
+
def have_bundle_cache?
|
30
|
+
ENV['CACHE_BUNDLE_PATH']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Ikaros
|
4
|
+
class Command
|
5
|
+
def initialize(command, options={})
|
6
|
+
@command = command
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
logger.debug @command
|
12
|
+
result = ''
|
13
|
+
Open3.popen3(@command) do |stdin, stdout, stderr, wait_thr|
|
14
|
+
while line = stdout.gets
|
15
|
+
result = "#{result}#{line}"
|
16
|
+
logger.debug line
|
17
|
+
logger.info line if output?
|
18
|
+
end
|
19
|
+
unless wait_thr.value.success?
|
20
|
+
raise Error::CommandError.new stderr.gets(nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
result.chomp
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def output?
|
28
|
+
@options[:output]
|
29
|
+
end
|
30
|
+
|
31
|
+
def logger
|
32
|
+
@logger ||= Ikaros.logger
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module Ikaros
|
3
|
+
class Config
|
4
|
+
def initialize(path)
|
5
|
+
@path = path
|
6
|
+
@config = YAML.load_file @path
|
7
|
+
@dir_path = ::File.dirname ::File.realpath(@path)
|
8
|
+
@dir_name = @dir_path.match(/\w+$/).to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def services
|
12
|
+
@config['services']
|
13
|
+
end
|
14
|
+
|
15
|
+
def app_type
|
16
|
+
@config['language']
|
17
|
+
end
|
18
|
+
|
19
|
+
def project_path
|
20
|
+
@dir_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def project_name
|
24
|
+
@dir_name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative './docker'
|
2
|
+
|
3
|
+
module Ikaros
|
4
|
+
class Container
|
5
|
+
attr_accessor :basename, :image, :id
|
6
|
+
|
7
|
+
def initialize(basename, options = {})
|
8
|
+
self.basename = basename
|
9
|
+
self.image = basename
|
10
|
+
@service = options.delete(:service) || Docker
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def image= value
|
15
|
+
@image = case value
|
16
|
+
when 'ruby'
|
17
|
+
'voanhduy1512/ruby'
|
18
|
+
when 'postgres'
|
19
|
+
'sss_postgresql'
|
20
|
+
when 'elasticsearch'
|
21
|
+
'dockerfile/elasticsearch'
|
22
|
+
else
|
23
|
+
value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
@service.get_name id
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
@id = @service.run image, @options
|
33
|
+
end
|
34
|
+
|
35
|
+
def stop
|
36
|
+
@service.stop id
|
37
|
+
@service.rm id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative './command'
|
2
|
+
|
3
|
+
|
4
|
+
module Ikaros
|
5
|
+
class Docker
|
6
|
+
class << self
|
7
|
+
def run(image, options)
|
8
|
+
command = 'docker run '
|
9
|
+
|
10
|
+
options[:link] && options[:link].each do |key, value|
|
11
|
+
command = "#{command} --link #{value}:#{key}"
|
12
|
+
end
|
13
|
+
|
14
|
+
if options[:env]
|
15
|
+
options[:env].each do |key, value|
|
16
|
+
command = "#{command} -e #{key}=#{value}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if options[:mount]
|
21
|
+
options[:mount].each do |key, value|
|
22
|
+
command = "#{command} -v #{value}:#{key}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if options[:daemon]
|
27
|
+
command = "#{command} -d"
|
28
|
+
end
|
29
|
+
|
30
|
+
command = "#{command} #{image}"
|
31
|
+
command = "#{command} /scripts/ruby.sh" unless options[:daemon]
|
32
|
+
|
33
|
+
exec command
|
34
|
+
end
|
35
|
+
|
36
|
+
def stop(id)
|
37
|
+
command = "docker stop #{id}"
|
38
|
+
exec command
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_name(id)
|
42
|
+
command = "docker inspect -f '{{ .Name }}' #{id} | cut -d / -f2"
|
43
|
+
exec command
|
44
|
+
end
|
45
|
+
|
46
|
+
def rm(id)
|
47
|
+
command = "docker rm #{id}"
|
48
|
+
exec command
|
49
|
+
end
|
50
|
+
|
51
|
+
def exec(command, options={})
|
52
|
+
Command.new(command, options).run
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ikaros/error.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Ikaros
|
4
|
+
class Logger < ::Logger
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :log_level
|
8
|
+
|
9
|
+
def log_level
|
10
|
+
@log_level ||= self::INFO
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
super
|
16
|
+
self.level = self.class.log_level
|
17
|
+
@formatter = SimpleFormatter.new
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class SimpleFormatter < ::Logger::Formatter
|
23
|
+
def call(severity, timestamp, progname, msg)
|
24
|
+
"#{String === msg ? msg : msg.inspect}\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative './container'
|
2
|
+
|
3
|
+
module Ikaros
|
4
|
+
class Runner
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
@containers = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
start_services
|
12
|
+
run_test
|
13
|
+
stop_services
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def start_services
|
18
|
+
@config.services.each do |service|
|
19
|
+
container = Container.new(service, daemon: true)
|
20
|
+
container.start
|
21
|
+
@containers << container
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_test
|
26
|
+
app = Container.new(@config.app_type, options_for_main_container)
|
27
|
+
app.start
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop_services
|
31
|
+
@containers.each do |container|
|
32
|
+
container.stop
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def options_for_main_container
|
38
|
+
env = {}
|
39
|
+
link = {}
|
40
|
+
@containers.each do |container|
|
41
|
+
case container.basename
|
42
|
+
when 'redis'
|
43
|
+
env['REDISTOGO_URL'] = 'redis://redis'
|
44
|
+
env['REDIS_URL'] = 'redis://redis'
|
45
|
+
when 'elasticsearch'
|
46
|
+
env['ELASTICSEARCH_URL'] = 'http://elasticsearch:9200'
|
47
|
+
end
|
48
|
+
|
49
|
+
link[container.basename] = container.name
|
50
|
+
end
|
51
|
+
|
52
|
+
mount = {
|
53
|
+
'/code' => @config.project_path,
|
54
|
+
'/scripts' => File.expand_path("../scripts", __FILE__),
|
55
|
+
'/bundle' => bundle_path
|
56
|
+
}
|
57
|
+
|
58
|
+
{
|
59
|
+
link: link,
|
60
|
+
env: env,
|
61
|
+
mount: mount,
|
62
|
+
output: true
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def bundle_path
|
67
|
+
ENV['CACHE_BUNDLE_PATH']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# enable rvm
|
4
|
+
source /etc/profile.d/rvm.sh
|
5
|
+
|
6
|
+
# install and switch ruby
|
7
|
+
#rvm install 2.0
|
8
|
+
#rvm use 2.0
|
9
|
+
|
10
|
+
# clone code
|
11
|
+
mkdir /app
|
12
|
+
cp -R /code/* /app/
|
13
|
+
cd /app
|
14
|
+
|
15
|
+
# remove duplication RAILS_ENV=test in other command
|
16
|
+
export RAILS_ENV=test
|
17
|
+
|
18
|
+
bundle install --without production development --path=/bundle
|
19
|
+
bundle exec rake db:create
|
20
|
+
bundle exec rake db:migrate
|
21
|
+
bundle exec rspec
|
data/lib/ikaros.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ikaros
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Võ Anh Duy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: update later
|
56
|
+
email:
|
57
|
+
- voanhduy1512@live.com
|
58
|
+
executables:
|
59
|
+
- ikaros
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/ikaros
|
69
|
+
- ikaros.gemspec
|
70
|
+
- lib/ikaros.rb
|
71
|
+
- lib/ikaros/cli.rb
|
72
|
+
- lib/ikaros/command.rb
|
73
|
+
- lib/ikaros/config.rb
|
74
|
+
- lib/ikaros/container.rb
|
75
|
+
- lib/ikaros/docker.rb
|
76
|
+
- lib/ikaros/error.rb
|
77
|
+
- lib/ikaros/logger.rb
|
78
|
+
- lib/ikaros/runner.rb
|
79
|
+
- lib/ikaros/scripts/ruby.sh
|
80
|
+
- lib/ikaros/version.rb
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: update later
|
105
|
+
test_files: []
|