panoramix 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require "time"
2
+ require "panoramix/plugin/base"
3
+
4
+ module Panoramix
5
+ module Plugin
6
+ class S3 < Base
7
+
8
+ attr_reader :dst
9
+ attr_reader :src
10
+ attr_reader :flags
11
+
12
+ def initialize(dst, src, flags, host)
13
+ super host
14
+ @dst = dst
15
+ @src = src
16
+ @flags = flags
17
+ end
18
+
19
+ # Return current timestamp
20
+ def timestamp
21
+ return Time.at 0 unless created?
22
+ remote_time = shell("aws s3 ls --summarize #{@src} | head -n1 | awk 'END {print $1, $2}'", true)[:out]
23
+ while remote_time == " \n"
24
+ sleep 1
25
+ remote_time = shell("aws s3 ls --summarize #{@src} | head -n1 | awk 'END {print $1, $2}'", true)[:out]
26
+ end
27
+ remote_time = Time.parse(remote_time)
28
+ end
29
+
30
+ # When this instance needs to be executed
31
+ def needed? timestamps
32
+ return true if !created?
33
+ File.ctime(@dst) < timestamp
34
+ end
35
+
36
+ # Has this instance already been created
37
+ def created?
38
+ File.exists?(@dst)
39
+ end
40
+
41
+ # Action clean fot this task
42
+ def clean
43
+ shell "rm -f #{@dst}"
44
+ end
45
+
46
+ # Default action for this task
47
+ def run_default
48
+ shell "aws s3 cp #{@flags} #{@src} #{@dst}"
49
+ end
50
+
51
+ def validate
52
+ out = shell("aws s3 cp --dryrun #{@flags} #{@src} #{@dst}" , true)
53
+ if (! out[:exit_status].success?)
54
+ message = I18n.t('errors.s3.not_found', {:uri => @src})
55
+ raise(ValidationError, message)
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ def s3(args, prerequisites, block=nil)
65
+ # Task name
66
+ name = args.keys[0]
67
+ # Artifacts url
68
+ src = args.values[0][:s3]
69
+ # Provided flags
70
+ flags = args.values[0][:flags]
71
+
72
+ # S3 tasks always run as local
73
+ host = "local"
74
+
75
+ instance=Panoramix::Plugin::S3.new(name, src, flags, host)
76
+
77
+ descriptions = I18n.t('s3')
78
+ descriptions = Hash.new if descriptions.class != Hash
79
+
80
+ Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
81
+ end
@@ -0,0 +1,78 @@
1
+ require "time"
2
+ require "panoramix/plugin/base"
3
+
4
+ module Panoramix
5
+ module Plugin
6
+ class Wget < Base
7
+
8
+ attr_reader :dst
9
+ attr_reader :src
10
+ attr_reader :flags
11
+
12
+ def initialize(dst, src, flags, host)
13
+ super host
14
+ @dst = dst
15
+ @src = src
16
+ @flags = flags
17
+ end
18
+
19
+ # Return current timestamp
20
+ def timestamp
21
+ return Time.at 0 unless created?
22
+ remote_time = shell("wget #{@flags} --spider -S #{@src} 2>&1 | grep Last-Modified", true)[:out]
23
+ remote_time = remote_time.split("Last-Modified: ").last
24
+ remote_time = Time.parse(remote_time)
25
+ end
26
+
27
+ # When this instance needs to be executed
28
+ def needed? timestamps
29
+ return true if !created?
30
+ File.ctime(@dst) < timestamp
31
+ end
32
+
33
+ # Has this instance already been created
34
+ def created?
35
+ File.exists?(@dst)
36
+ end
37
+
38
+ # Action clean fot this task
39
+ def clean
40
+ shell "rm -f #{@dst}"
41
+ end
42
+
43
+ # Default action for this task
44
+ def run_default
45
+ shell "wget -nv #{@flags} #{@src} -O #{@dst}"
46
+ end
47
+
48
+ def validate
49
+ out = shell("wget #{@flags} --spider -S #{@src}", true)
50
+ if (! out[:exit_status].success?)
51
+ message = I18n.t('errors.wget.not_found', {:uri => @src})
52
+ raise(ValidationError, message)
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+
60
+
61
+ def wget(args, prerequisites, block=nil)
62
+ # Task name
63
+ name = args.keys[0]
64
+ # Artifacts url
65
+ src = args.values[0][:wget]
66
+ # Provided flags
67
+ flags = args.values[0][:flags]
68
+
69
+ # Wget tasks always run as local
70
+ host = "local"
71
+
72
+ instance=Panoramix::Plugin::Wget.new(name, src, flags, host)
73
+
74
+ descriptions = I18n.t('wget')
75
+ descriptions = Hash.new if descriptions.class != Hash
76
+
77
+ Panoramix.define_tasks(name, descriptions, instance, prerequisites, block)
78
+ end
@@ -0,0 +1,26 @@
1
+ module Panoramix
2
+ module Tasks
3
+
4
+ class Action
5
+ attr_reader :action_name
6
+ attr_reader :silent
7
+ attr_reader :order_class
8
+
9
+ def initialize(action_name, silent, order_class)
10
+ @action_name = action_name
11
+ @silent = silent
12
+ @order_class = order_class
13
+ end
14
+
15
+ end
16
+
17
+ Actions = Array.new
18
+ Actions.push(Action.new("validate", true, [Plugin::DockerUp, Plugin::Wget, Plugin::Git, Plugin::DockerBuild, Plugin::S3]))
19
+ Actions.push(Action.new("ps", false, [Plugin::Provision, Plugin::DockerImage, Plugin::DockerBuild, Plugin::DockerUp]))
20
+ Actions.push(Action.new("logs", false, [Plugin::DockerUp]))
21
+ Actions.push(Action.new("clobber", false, [Plugin::DockerUp, Plugin::DockerBuild, Plugin::DockerImage, Plugin::Provision]))
22
+ Actions.push(Action.new("clean", true, [Plugin::Wget, Plugin::Git, Plugin::S3]))
23
+ Actions.push(Action.new("stop", false, [Plugin::DockerUp]))
24
+ Actions.push(Action.new("start", false, [Plugin::DockerUp]))
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ module Panoramix
2
+ module Tasks
3
+ module CommonHostTasks
4
+ module_function
5
+
6
+ # puts_header writes a formatted name to stdout
7
+ def puts_header host
8
+ docker_host = "(#{ENV["DOCKER_HOST"]})" if ENV["DOCKER_HOST"] && host == "localhost"
9
+
10
+ puts ""
11
+ head = "- #{host} #{docker_host} -"
12
+ (head.length - 1).times {print "-"}
13
+ puts "-"
14
+ puts head
15
+ (head.length - 1).times {print "-"}
16
+ puts "-\n\n"
17
+ end
18
+
19
+ # define_task defines the main ps task
20
+ def define_common_task(action, description, silent=false)
21
+ # Task body
22
+
23
+ block = Proc.new do |t|
24
+
25
+ Panoramix::Hosts.hosts.each do |k, v|
26
+ puts_header k if((k != "localhost") && (!silent && (k != "localhost")))
27
+ Rake::Task["#{k}:#{action}"].invoke
28
+ end
29
+ end
30
+
31
+ # Define the ps task
32
+ Panoramix.define_task(action, [], description, block)
33
+ end
34
+
35
+ def define_tasks
36
+ descriptions = I18n.t('global')
37
+ Panoramix::Tasks::Actions.each do |act|
38
+ define_common_task(act.action_name, descriptions[act.action_name.to_sym], act.silent)
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,56 @@
1
+ module Panoramix
2
+ module Tasks
3
+
4
+ module MpiInfo
5
+ module_function
6
+
7
+ # This function defines the main task mpi_info
8
+ def define_tasks
9
+
10
+ block = Proc.new do |t|
11
+ puts "Base MPI".bold
12
+ Panoramix::MPI.print_mpi
13
+ puts "\nExecuted MPI".bold
14
+ Panoramix::MPI.print_final_mpi
15
+ puts "\nDiff".bold
16
+ Panoramix::MPI.diff_sh
17
+ end
18
+
19
+ # Define the mpi_info task
20
+ Panoramix.define_task("mpi:info", [], I18n.t('mpi.info'), block)
21
+
22
+ # Task body
23
+ block = Proc.new { |t| Panoramix::MPI.print_mpi }
24
+
25
+ # Define the mpi_info task
26
+ Panoramix.define_task("mpi:base", [], I18n.t('mpi.base'), block)
27
+
28
+ # Task body
29
+ block = Proc.new { |t| Panoramix::MPI.print_final_mpi }
30
+
31
+ # Define the mpi_info task
32
+ Panoramix.define_task("mpi:final", [], I18n.t('mpi.final'), block)
33
+
34
+ # Task body
35
+ block = Proc.new { |t| Panoramix::MPI.diff_sh }
36
+
37
+ # Define the mpi_info task
38
+ Panoramix.define_task("mpi:diff", [], I18n.t('mpi.diff'), block)
39
+ end
40
+ end
41
+
42
+ module MpiGen
43
+ module_function
44
+
45
+ # This function defines the main task mpi_gen
46
+ def define_task
47
+
48
+ # Task body
49
+ block = Proc.new { |t| Panoramix::MPI.generate }
50
+ # Define the mpi_gen task
51
+ Panoramix.define_task("mpi:gen", [], I18n.t('mpi.gen'), block)
52
+ end
53
+ end
54
+
55
+ end
56
+ end
data/lib/panoramix.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "panoramix/external"
2
+ require "panoramix/plugin/docker_image"
3
+ require "panoramix/plugin/docker_build"
4
+ require "panoramix/plugin/docker_up"
5
+ require "panoramix/plugin/provision"
6
+ require "panoramix/dsl"
7
+ require "panoramix/hosts"
8
+ require "panoramix/connections"
9
+ require "panoramix/panoramix_core"
10
+ require "panoramix/tasks/actions"
11
+ require "panoramix/tasks/common_host_tasks"
12
+ require "panoramix/tasks/task_mpi"
13
+ require "rake/clean"
14
+
15
+ Panoramix::MPI.initialize
16
+
17
+ Panoramix::Connections.initialize
18
+ Panoramix::Hosts.initialize
19
+ Panoramix::TIMESTAMP=Hash.new
20
+
21
+ class String
22
+ def black; "\033[30m#{self}\033[0m" end
23
+ def red; "\033[31m#{self}\033[0m" end
24
+ def green; "\033[32m#{self}\033[0m" end
25
+ def brown; "\033[33m#{self}\033[0m" end
26
+ def blue; "\033[34m#{self}\033[0m" end
27
+ def magenta; "\033[35m#{self}\033[0m" end
28
+ def cyan; "\033[36m#{self}\033[0m" end
29
+ def gray; "\033[37m#{self}\033[0m" end
30
+ def bg_black; "\033[40m#{self}\033[0m" end
31
+ def bg_red; "\033[41m#{self}\033[0m" end
32
+ def bg_green; "\033[42m#{self}\033[0m" end
33
+ def bg_brown; "\033[43m#{self}\033[0m" end
34
+ def bg_blue; "\033[44m#{self}\033[0m" end
35
+ def bg_magenta; "\033[45m#{self}\033[0m" end
36
+ def bg_cyan; "\033[46m#{self}\033[0m" end
37
+ def bg_gray; "\033[47m#{self}\033[0m" end
38
+ def bold; "\033[1m#{self}\033[22m" end
39
+ def reverse_color; "\033[7m#{self}\033[27m" end
40
+ end
41
+
42
+ Panoramix::Tasks::CommonHostTasks.define_tasks
43
+ Panoramix::Tasks::MpiInfo.define_tasks
44
+ Panoramix::Tasks::MpiGen.define_task
45
+ Panoramix::Link = Hash.new
46
+
47
+ Rake::Task.tasks.select{|t| t.name == "clobber"}.first.instance_variable_set(:@prerequisites,[])
48
+
49
+ at_exit { Panoramix::Connections.connections.each {|k,v| v.close_connection } }
data/locales/en.yml ADDED
@@ -0,0 +1,55 @@
1
+ en:
2
+ git:
3
+ wget:
4
+ s3:
5
+ docker_up:
6
+ main: Deploy new cluster
7
+ ps: Show deployment status
8
+ stop: Stop any project running container
9
+ start: Start any project stopped container
10
+ logs: Show containers logs
11
+ docker_image:
12
+ main: Pull given image
13
+ ps: Show image status
14
+ docker_build:
15
+ main: Build image
16
+ ps: Show built image status
17
+ provision:
18
+ main: Provision new host
19
+ ps: Show host status
20
+ host:
21
+ validate: Check host tasks definitions
22
+ ps: Print host system ps
23
+ logs: Print host system logs
24
+ clobber: Removes current system
25
+ clean: Remove local artifacts
26
+ stop: Stop all containers
27
+ start: Start all containers
28
+ global:
29
+ validate: Check tasks definitions
30
+ ps: Print system ps
31
+ logs: Print system logs
32
+ clobber: Removes current system
33
+ clean: Remove local artifacts
34
+ stop: Stop all containers
35
+ start: Start all containers
36
+ mpi:
37
+ gen: Generate project MPI
38
+ info: Show overriden dependencies
39
+ diff: Show dependencies diff
40
+ final: Show executed MPI
41
+ base: Show base dependencies
42
+ errors:
43
+ docker_up:
44
+ cluster_deployed: The cluster %{id} is already deployed. Delete it before creating it again.
45
+ docker_compose_not_found: The given docker-compose.yml %{path} has not found.
46
+ env_var_not_given: Undefined environment variables [%{env}].
47
+ no_compose_provided: Key compose has not been provided
48
+ docker_build:
49
+ no_dockerfile_provided: Key dockerfile has not been provided
50
+ wget:
51
+ not_found: Cannot download %{uri}.
52
+ s3:
53
+ not_found: Cannot download %{uri}.
54
+ git:
55
+ not_found: Tag %{tag} or branch %{branch} not found.
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: panoramix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sflyr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: net-ssh-gateway
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: highline
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: i18n
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Panoramix is a Rakefile like lib, capable of handling docker deployments
79
+ email: jig@safelayer.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/panoramix/dsl.rb
85
+ - lib/panoramix/tasks/common_host_tasks.rb
86
+ - lib/panoramix/tasks/task_mpi.rb
87
+ - lib/panoramix/tasks/actions.rb
88
+ - lib/panoramix/plugin/docker_image.rb
89
+ - lib/panoramix/plugin/base.rb
90
+ - lib/panoramix/plugin/docker_image_base.rb
91
+ - lib/panoramix/plugin/docker_up.rb
92
+ - lib/panoramix/plugin/docker_build.rb
93
+ - lib/panoramix/plugin/provision.rb
94
+ - lib/panoramix/plugin/s3.rb
95
+ - lib/panoramix/plugin/git.rb
96
+ - lib/panoramix/plugin/wget.rb
97
+ - lib/panoramix/hosts.rb
98
+ - lib/panoramix/connections.rb
99
+ - lib/panoramix/connections/local_connection.rb
100
+ - lib/panoramix/connections/base_connection.rb
101
+ - lib/panoramix/connections/docker_connection.rb
102
+ - lib/panoramix/locale.rb
103
+ - lib/panoramix/mpi.rb
104
+ - lib/panoramix/metal.rb
105
+ - lib/panoramix/external.rb
106
+ - lib/panoramix/instances/base.rb
107
+ - lib/panoramix/instances/local.rb
108
+ - lib/panoramix/instances/metal.rb
109
+ - lib/panoramix/instances/aws.rb
110
+ - lib/panoramix/aws.rb
111
+ - lib/panoramix/panoramix_core.rb
112
+ - lib/panoramix.rb
113
+ - locales/en.yml
114
+ homepage: https://github.com/sflyr
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project: panoramix
135
+ rubygems_version: 1.8.23
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Panoramix gem
139
+ test_files: []