mobilis 0.0.1
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +68 -0
- data/README.md +29 -0
- data/Rakefile +13 -0
- data/lib/mobilis/actions_projects_take.rb +62 -0
- data/lib/mobilis/command_line.rb +43 -0
- data/lib/mobilis/docker_compose_projector.rb +132 -0
- data/lib/mobilis/generic_project.rb +101 -0
- data/lib/mobilis/interactive_designer.rb +381 -0
- data/lib/mobilis/logger.rb +14 -0
- data/lib/mobilis/mysql_instance.rb +49 -0
- data/lib/mobilis/new_relic.rb +18 -0
- data/lib/mobilis/os.rb +26 -0
- data/lib/mobilis/postgresql_instance.rb +38 -0
- data/lib/mobilis/project.rb +261 -0
- data/lib/mobilis/rack_project.rb +89 -0
- data/lib/mobilis/rails_project.rb +179 -0
- data/lib/mobilis/redis_instance.rb +37 -0
- data/lib/mobilis/version.rb +5 -0
- data/lib/mobilis.rb +9 -0
- data/sig/mobilis.rbs +4 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9272e45feab19a739c39a972908e0d5f1ef1edc05cccc1cabf1ff5211a2f0990
|
4
|
+
data.tar.gz: 2ea3d6a87fdf6d8c60eab53523a86e77ba7cdd1c65819db34f76cc1389107351
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b572cfacd0fa1a2e11f706a50246af9d418062107fa776c2a8dd605bc8e777a803e288b5c2c14d7e0933145eb5ee7f84797d4bcf33590feabeeefe6a621956ed
|
7
|
+
data.tar.gz: 037b620a1846fa7f9ebe54435b8aabcb9143c9428816f6db802b6bd79b358fe1dd15ce45c883be043484c2864d0d29407e705eb322b1fb13be353b57e96ee360
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mobilis (0.1.0)
|
5
|
+
awesome_print
|
6
|
+
state_machine
|
7
|
+
tty-prompt
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
attr_extras (6.2.5)
|
13
|
+
awesome_print (1.9.2)
|
14
|
+
coderay (1.1.3)
|
15
|
+
diff-lcs (1.5.0)
|
16
|
+
method_source (1.0.0)
|
17
|
+
optimist (3.0.1)
|
18
|
+
pastel (0.8.0)
|
19
|
+
tty-color (~> 0.5)
|
20
|
+
patience_diff (1.2.0)
|
21
|
+
optimist (~> 3.0)
|
22
|
+
pry (0.14.1)
|
23
|
+
coderay (~> 1.1)
|
24
|
+
method_source (~> 1.0)
|
25
|
+
rake (13.0.6)
|
26
|
+
rspec (3.11.0)
|
27
|
+
rspec-core (~> 3.11.0)
|
28
|
+
rspec-expectations (~> 3.11.0)
|
29
|
+
rspec-mocks (~> 3.11.0)
|
30
|
+
rspec-core (3.11.0)
|
31
|
+
rspec-support (~> 3.11.0)
|
32
|
+
rspec-expectations (3.11.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.11.0)
|
35
|
+
rspec-mocks (3.11.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.11.0)
|
38
|
+
rspec-support (3.11.0)
|
39
|
+
state_machine (1.2.0)
|
40
|
+
super_diff (0.9.0)
|
41
|
+
attr_extras (>= 6.2.4)
|
42
|
+
diff-lcs
|
43
|
+
patience_diff
|
44
|
+
tty-color (0.6.0)
|
45
|
+
tty-cursor (0.7.1)
|
46
|
+
tty-prompt (0.23.1)
|
47
|
+
pastel (~> 0.8)
|
48
|
+
tty-reader (~> 0.8)
|
49
|
+
tty-reader (0.9.0)
|
50
|
+
tty-cursor (~> 0.7)
|
51
|
+
tty-screen (~> 0.8)
|
52
|
+
wisper (~> 2.0)
|
53
|
+
tty-screen (0.8.1)
|
54
|
+
wisper (2.0.1)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
x64-mingw-ucrt
|
58
|
+
x86_64-linux
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
mobilis!
|
62
|
+
pry (~> 0.14.1)
|
63
|
+
rake (~> 13.0)
|
64
|
+
rspec (~> 3.0)
|
65
|
+
super_diff
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.3.16
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Mobilis
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mobilis`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add mobilis
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install mobilis
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
|
+
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mobilis.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
#require "rubocop/rake_task"
|
9
|
+
#
|
10
|
+
#RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
#task default: %i[spec rubocop]
|
13
|
+
task default: %i[spec]
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mobilis
|
4
|
+
module ActionsProjectsTake
|
5
|
+
|
6
|
+
|
7
|
+
def append_line filename, line
|
8
|
+
lines = IO.readlines filename
|
9
|
+
lines << line
|
10
|
+
write_file filename do |f|
|
11
|
+
f.write(lines.join("\n"))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_command command
|
16
|
+
# fixme
|
17
|
+
#Mobilis.logger.info "$ #{command.join " "}"
|
18
|
+
puts "-> Running --> #{command}"
|
19
|
+
system command
|
20
|
+
if $? then
|
21
|
+
puts "-> Error running command!"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def oblivious_run_command command
|
27
|
+
# fixme
|
28
|
+
#Mobilis.logger.info "$ #{command.join " "}"
|
29
|
+
puts "-> Running --> #{command}"
|
30
|
+
system command
|
31
|
+
end
|
32
|
+
|
33
|
+
def run_docker cmd
|
34
|
+
oblivious_run_command "docker #{cmd}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_second_line filename, line
|
38
|
+
lines = IO.readlines filename
|
39
|
+
lines.reverse!
|
40
|
+
first_line = lines.pop
|
41
|
+
lines << line
|
42
|
+
lines << first_line
|
43
|
+
lines.reverse!
|
44
|
+
write_file filename do |f|
|
45
|
+
f.write(lines.join("\n"))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_file_contents filename, contents
|
50
|
+
write_file filename do |f|
|
51
|
+
f.write contents
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_file filename, &block
|
56
|
+
puts " -> Writing --> #{ filename }"
|
57
|
+
File.open(filename, "wb", &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "optimist"
|
2
|
+
|
3
|
+
module Mobilis
|
4
|
+
class CommandLine
|
5
|
+
def self.parse_args(args)
|
6
|
+
options = {}
|
7
|
+
Optimist.options(args) do
|
8
|
+
banner "checklist code janitor"
|
9
|
+
stop_on ["new", "check", "add"]
|
10
|
+
end
|
11
|
+
if args.length == 0
|
12
|
+
options[:subcommand] = :help
|
13
|
+
return options
|
14
|
+
end
|
15
|
+
options[:subcommand] = args.shift.to_sym
|
16
|
+
case options[:subcommand]
|
17
|
+
when :new
|
18
|
+
Optimist.options(args) do
|
19
|
+
stop_on ["gem", "railsapp", "railsapi"]
|
20
|
+
end
|
21
|
+
options[:new_type] = args.shift.to_sym
|
22
|
+
options[:name] = case options[:new_type]
|
23
|
+
when :gem
|
24
|
+
args.shift
|
25
|
+
when :railsapp
|
26
|
+
args.shift
|
27
|
+
when :railsapi
|
28
|
+
args.shift
|
29
|
+
end
|
30
|
+
when :add
|
31
|
+
Optimist.options(args) do
|
32
|
+
stop_on ["gem", "docker"]
|
33
|
+
end
|
34
|
+
options[:add_type] = args.shift.to_sym
|
35
|
+
case options[:add_type]
|
36
|
+
when :gem
|
37
|
+
options[:name] = args.shift
|
38
|
+
end
|
39
|
+
end
|
40
|
+
options
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Mobilis
|
4
|
+
class DockerComposeProjector
|
5
|
+
|
6
|
+
def self.port_skip
|
7
|
+
return 10
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.project project
|
11
|
+
projector = DockerComposeProjector.new project
|
12
|
+
|
13
|
+
services = {}
|
14
|
+
project.projects.each_with_index do |service, index|
|
15
|
+
services[service.name] = projector.send "#{service.type}_service", service
|
16
|
+
if service.links.count > 0 then
|
17
|
+
services[service.name]["links"] = service.links.map(&:to_s)
|
18
|
+
services[service.name]["depends_on"] = service.links.map(&:to_s)
|
19
|
+
service.links.each do |link|
|
20
|
+
linked_service = project.project_by_name link
|
21
|
+
linked_service.child_env_vars.each do |var|
|
22
|
+
services[service.name]["environment"] << var
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
{"version" => "3.8", "services" => services}
|
28
|
+
end
|
29
|
+
|
30
|
+
def rails_service service
|
31
|
+
attributes = @project.attributes
|
32
|
+
keyname = "#{ service.name }_internal_port_no".to_sym
|
33
|
+
vars = []
|
34
|
+
vars << "RAILS_ENV=production"
|
35
|
+
vars << "RAILS_MASTER_KEY=#{ service.rails_master_key }"
|
36
|
+
vars << "RAILS_MIN_THREADS=5"
|
37
|
+
vars << "RAILS_MAX_THREADS=5"
|
38
|
+
|
39
|
+
database = service.database
|
40
|
+
if database then
|
41
|
+
vars << "DATABASE_URL=#{ database.url }"
|
42
|
+
end
|
43
|
+
|
44
|
+
#vars << "NEW_RELIC_APP_NAME=#{ service.name }"
|
45
|
+
#vars << "NEW_RELIC_LICENSE_KEY=#{ attributes[:new_relic_license_key] }"
|
46
|
+
#vars << "NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true"
|
47
|
+
{
|
48
|
+
"image" => service.docker_image_name,
|
49
|
+
"ports" => ["#{ attributes[keyname] }:3000"],
|
50
|
+
"environment" => vars,
|
51
|
+
"build" => {
|
52
|
+
"context" => "./#{ service.name }"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def rack_service service
|
58
|
+
attributes = @project.attributes
|
59
|
+
keyname = "#{ service.name }_internal_port_no".to_sym
|
60
|
+
{
|
61
|
+
"image" => service.docker_image_name,
|
62
|
+
"ports" => ["#{ attributes[keyname] }:9292"],
|
63
|
+
"environment" => [],
|
64
|
+
"build" => {
|
65
|
+
"context" => "./#{ service.name }"
|
66
|
+
}
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def postgresql_service service
|
71
|
+
attributes = @project.attributes
|
72
|
+
keyname = "#{service.name}_internal_port_no".to_sym
|
73
|
+
{
|
74
|
+
"image" => "postgres:14.1-alpine",
|
75
|
+
"restart" => "always",
|
76
|
+
"environment" => [
|
77
|
+
"POSTGRES_USER=#{ service.name }",
|
78
|
+
"POSTGRES_PASSWORD=#{ service.password }"
|
79
|
+
],
|
80
|
+
"ports" => ["#{ attributes[keyname] }:5432"],
|
81
|
+
"volumes" => [
|
82
|
+
"#{ service.data_dir }:/var/lib/postgresql/data"
|
83
|
+
],
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def mysql_service service
|
88
|
+
attributes = @project.attributes
|
89
|
+
keyname = "#{service.name}_internal_port_no".to_sym
|
90
|
+
{
|
91
|
+
"image" => "mysql:debian",
|
92
|
+
"restart" => "always",
|
93
|
+
"environment" => service.env_vars,
|
94
|
+
"ports" => ["#{ attributes[keyname] }:3306"],
|
95
|
+
"volumes" => [
|
96
|
+
"#{ service.data_dir }:/var/lib/mysql"
|
97
|
+
],
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
def redis_service service
|
102
|
+
attributes = @project.attributes
|
103
|
+
port_key = "#{service.name}_internal_port_no".to_sym
|
104
|
+
{
|
105
|
+
"image" => "redis:6.2-alpine",
|
106
|
+
"restart" => "always",
|
107
|
+
"command" => "redis-server --save 20 1 --loglevel warning --requirepass #{ service.password }",
|
108
|
+
"environment" => [
|
109
|
+
],
|
110
|
+
"ports" => [ "#{ attributes[port_key] }:6379" ],
|
111
|
+
"volumes" => [
|
112
|
+
"#{ service.data_dir }:/data"
|
113
|
+
],
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_cwd_path
|
118
|
+
f = Dir.getwd
|
119
|
+
if f[1] == ':' then
|
120
|
+
f[1] = f[0].downcase
|
121
|
+
f[0] = '/'
|
122
|
+
end
|
123
|
+
f
|
124
|
+
end
|
125
|
+
|
126
|
+
def initialize project
|
127
|
+
@project = project
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'forwardable'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'mobilis/actions_projects_take'
|
6
|
+
|
7
|
+
module Mobilis
|
8
|
+
|
9
|
+
##
|
10
|
+
# base class for projects.
|
11
|
+
# Child classes should override
|
12
|
+
# generate
|
13
|
+
# and as needed
|
14
|
+
# child_env_vars
|
15
|
+
class GenericProject
|
16
|
+
include ActionsProjectsTake
|
17
|
+
extend Forwardable
|
18
|
+
|
19
|
+
def_delegators :@metaproject, :starting_port, :port_gap, :username, :getwd
|
20
|
+
|
21
|
+
def initialize data, metaproject
|
22
|
+
@data = data
|
23
|
+
data[:attributes] = {} unless data[:attributes]
|
24
|
+
data[:options] = [] unless data[:options]
|
25
|
+
data[:links] = [] unless data[:links]
|
26
|
+
@metaproject = metaproject
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# environment env vars added to linked child services
|
31
|
+
def child_env_vars
|
32
|
+
[]
|
33
|
+
end
|
34
|
+
|
35
|
+
def env_vars
|
36
|
+
[]
|
37
|
+
end
|
38
|
+
|
39
|
+
def children
|
40
|
+
links.map {|name| @metaproject.project_by_name name }
|
41
|
+
end
|
42
|
+
|
43
|
+
def parents
|
44
|
+
@metaproject.projects.filter {|l| l.links.include? name}
|
45
|
+
end
|
46
|
+
|
47
|
+
def linked_to_rails_project
|
48
|
+
parents.find {|l| l.instance_of? Mobilis::RailsProject}
|
49
|
+
end
|
50
|
+
|
51
|
+
def display
|
52
|
+
ap @data
|
53
|
+
end
|
54
|
+
|
55
|
+
def name
|
56
|
+
@data[:name]
|
57
|
+
end
|
58
|
+
|
59
|
+
def options
|
60
|
+
@data[:options]
|
61
|
+
end
|
62
|
+
|
63
|
+
def type
|
64
|
+
@data[:type]
|
65
|
+
end
|
66
|
+
|
67
|
+
def links
|
68
|
+
@data[:links]
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_links new_links
|
72
|
+
@data[:links] = new_links
|
73
|
+
end
|
74
|
+
|
75
|
+
def docker_image_name
|
76
|
+
return "#{ @metaproject.username }/#{ name }"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
def generate_build_sh
|
82
|
+
write_file "build.sh" do |f|
|
83
|
+
f.write "docker build -t #{ docker_image_name } ."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def git_commit_all message
|
89
|
+
# FIXME
|
90
|
+
#run_command ["git", "add", "."]
|
91
|
+
#run_command ["git", "commit", "-m", message]
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# generate the local file structure to support the project
|
96
|
+
def generate
|
97
|
+
FileUtils.mkdir_p name
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|