mobilis 0.0.3 → 0.0.5

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
  SHA256:
3
- metadata.gz: 3cd47dc94e879a945b060720f6ee453228b266749ebab21264f8a03c1af833ef
4
- data.tar.gz: 22c7ce3af384fc3bda6b19790ea086919341466b8d37310d1c5b68fe5c169c6d
3
+ metadata.gz: b6f70c5988047af743d26f24694bdbf9894f7a6b5d05666987617aaf55fccd93
4
+ data.tar.gz: 185119c7a513b48f0d8ff991f2d79c40b43890b0fcf016624f786f8ba1383b45
5
5
  SHA512:
6
- metadata.gz: 8e9064d8564ee716bc4d4dcf0806638ca3ce16036b6e3225593bf07a470a2fca3bb42da8a7bc63996b2fcf7aefa502b9311f53fbbe5a4434216cfe700c218eaf
7
- data.tar.gz: a6f42ea29dd0b3605b3df3fe79bb768252bbc570cb5afdcb8a0c3245907af95bb8d7f5faefa687e057b4adf1feb686b60b66bfb7cfbc8f10f39649aed48598ba
6
+ metadata.gz: 6678e0445f6a8d777bc6f6c5280b7abacac3b61cb9b545cd51fc4a5ada43696a4815a2fa1fff553e8b3a2646b36550b12ec157437a78027225de87e63a20b650
7
+ data.tar.gz: ac072bd7e4bebca33480d3817aba9920869033d142d562f4908c6ca0c1a1a592f005ef834ffab4a025ea2b99e24741f534869e6daac49d2c3c461040bfc59c01
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.5] - 2022-12-09
4
+ - fixed a bug when loading a project that made the rails builder not update
5
+ - fixed permissions of wait-until, which means rails projects will wait until the database
6
+ is available to run migrations and start the server
7
+ - reworked a lot of the screens to be less cluttered and make more sense
8
+ - fixed unit tests to not hardcode my username in the test
9
+ - bumped redis version
10
+
11
+ ## [0.0.4] - 2022-09-11
12
+
13
+ - Added command line options load and build
14
+ - Added wait-until to rails w/postgresql or mysql to wait for the db to be ready before starting rails
15
+ - Fixed per-state display not working
16
+ - Use table_print to display some information such as linked projects
17
+
3
18
  ## [0.0.1] - 2022-06-26
4
19
 
5
20
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,9 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mobilis (0.1.0)
4
+ mobilis (0.0.4)
5
5
  awesome_print
6
+ optimist
7
+ pry
6
8
  state_machine
9
+ table_print
7
10
  tty-prompt
8
11
 
9
12
  GEM
@@ -41,6 +44,7 @@ GEM
41
44
  attr_extras (>= 6.2.4)
42
45
  diff-lcs
43
46
  patience_diff
47
+ table_print (1.5.7)
44
48
  tty-color (0.6.0)
45
49
  tty-cursor (0.7.1)
46
50
  tty-prompt (0.23.1)
data/README.md CHANGED
@@ -1,22 +1,44 @@
1
1
  # Mobilis
2
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.
3
+ Mobilis is a ruby app for generating linked sets of docker containers, for rapid
4
+ prototyping of arbitrary project architecture.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ It has some smarts built in to make common things simple, and will allow you to
7
+ further customize the output for more complex needs.
6
8
 
7
9
  ## Installation
8
10
 
9
- Install the gem and add to the application's Gemfile by executing:
11
+ $ gem install mobilis
10
12
 
11
- $ bundle add mobilis
13
+ ## Usage
12
14
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
15
+ $ mobilis
14
16
 
15
- $ gem install mobilis
17
+ This will start the console based user interface.
16
18
 
17
- ## Usage
19
+ Add projects of the various kinds. The input doesn't save you from mistakes
20
+ like entering spaces for service names, so don't do it.
21
+
22
+ If you need any containers to connect to other containers via the internal
23
+ names, you will want to add a link from the project that is connecting to the
24
+ project that is being connected to.
25
+
26
+ When configured to your liking, select the generate option to generate the
27
+ projects. This will *DESTROY* any data in an existing 'generate' directory.
18
28
 
19
- TODO: Write usage instructions here
29
+ ## Special Rails support
30
+ If a Ruby on Rails project is linked to a postgres or mysql instance, it will
31
+ be setup with a DATABASE_URL environment variable that has the connection
32
+ information.
33
+
34
+ In addition, the database instance will receive a environment variable with the
35
+ name of the default production database that is based on the rails project's name
36
+
37
+ ## Security
38
+ The generated projects are insecure, because of credential handling details.
39
+
40
+ If you want to deploy the projects into a production environment, you are
41
+ responsible for secrets management.
20
42
 
21
43
  ## Development
22
44
 
@@ -26,4 +48,13 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
48
 
27
49
  ## Contributing
28
50
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mobilis.
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Meleneth/mobilis.
52
+
53
+ ## Plans
54
+
55
+ Adding more project types + smart integrations
56
+ Instrumenting generated projects with New Relic
57
+ Smoothing out the flow of the UI
58
+ Be able to load a previous configured set of projects for further editing
59
+ ~~Make generated rails projects wait at startup until the database is usable~~
60
+ More details in TODO.md
data/TODO.md ADDED
@@ -0,0 +1,18 @@
1
+ make links look better ( table_print )
2
+ make link flow not redirect back to main menu
3
+ write down every time a flow feels bad
4
+ fix NR integration
5
+ ~~fix having to restart several times to go through db create, db migrate, start service loop~~
6
+ add flask app
7
+ rails: add interactive service designer (models / controllers)
8
+ add a rack service wrapper that deploys as a sidecar (*handwave*)
9
+ use graphviz to show a diagram for current metaproject
10
+ ~~give some documentation for expected usage / security concerns~~
11
+ rails: add multi-db-at-once support
12
+ add docker registry support (i.e. the docker container to host a docker registry)
13
+ no matter if you create a db or a rails project first, the flow should be easy and obvious to add the other, associated with whatever you made first
14
+ add ability to re-load old configuration
15
+ if generate/data exists already with data, have an option to keep or wipe the data
16
+ fix git integration so we have proper commit points between each step
17
+ add command line builder, so you can generate a tree based on an existing config
18
+ in a complex config, it feels bad when the config gets big
data/exe/mobilis CHANGED
@@ -5,9 +5,11 @@ require 'pry'
5
5
  require "mobilis/command_line"
6
6
  require "mobilis/interactive_designer"
7
7
 
8
- # options parsing is TODO
9
- #options = Mobilis::CommandLine.parse_args(ARGV)
8
+ options = Mobilis::CommandLine.parse_args(ARGV)
10
9
  program = Mobilis::InteractiveDesigner.new
10
+ if options[:subcommand] == :load
11
+ program.load_from_file options[:filename]
12
+ end
11
13
  program.go_main_menu
12
14
 
13
15
  loop do
@@ -5,37 +5,23 @@ module Mobilis
5
5
  def self.parse_args(args)
6
6
  options = {}
7
7
  Optimist.options(args) do
8
- banner "checklist code janitor"
9
- stop_on ["new", "check", "add"]
8
+ banner "multi-project codebase generation toolkit"
9
+ stop_on ["load", "build", "help"]
10
10
  end
11
- if args.length == 0
12
- options[:subcommand] = :help
11
+ if args == []
12
+ options[:subcommand] = :interactive
13
13
  return options
14
14
  end
15
15
  options[:subcommand] = args.shift.to_sym
16
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
17
+ when :load
18
+ options[:filename] = args.shift
19
+ when :build
20
+ options[:filename] = args.shift
21
+ when :help
22
+ puts "I think we'd all like a little help."
23
+ else
24
+ Optimist::die "unknown subcommand #{cmd.inspect}"
39
25
  end
40
26
  options
41
27
  end
@@ -73,10 +73,7 @@ def postgresql_service service
73
73
  {
74
74
  "image" => "postgres:14.1-alpine",
75
75
  "restart" => "always",
76
- "environment" => [
77
- "POSTGRES_USER=#{ service.name }",
78
- "POSTGRES_PASSWORD=#{ service.password }"
79
- ],
76
+ "environment" => service.env_vars,
80
77
  "ports" => ["#{ attributes[keyname] }:5432"],
81
78
  "volumes" => [
82
79
  "#{ service.data_dir }:/var/lib/postgresql/data"
@@ -102,7 +99,7 @@ def redis_service service
102
99
  attributes = @project.attributes
103
100
  port_key = "#{service.name}_internal_port_no".to_sym
104
101
  {
105
- "image" => "redis:6.2-alpine",
102
+ "image" => "redis:7.0.5-alpine",
106
103
  "restart" => "always",
107
104
  "command" => "redis-server --save 20 1 --loglevel warning --requirepass #{ service.password }",
108
105
  "environment" => [
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'state_machine'
4
- require 'tty-prompt'
5
3
  require 'awesome_print'
6
4
  require 'forwardable'
5
+ require 'state_machine'
6
+ require 'table_print'
7
+ require 'tty-prompt'
7
8
 
8
9
  require 'mobilis/logger'
9
10
  require 'mobilis/project'
@@ -16,7 +17,7 @@ extend Forwardable
16
17
  attr_accessor :project
17
18
  attr_reader :prompt
18
19
 
19
- def_delegators :@project, :projects, :display
20
+ def_delegators :@project, :projects, :load_from_file
20
21
 
21
22
  state_machine :state, initial: :intialize do
22
23
 
@@ -25,23 +26,37 @@ state_machine :state, initial: :intialize do
25
26
  end
26
27
 
27
28
  event :go_add_omakase_stack_rails_project do
28
- transition [:main_menu] => :add_omakase_stack_rails_project
29
+ transition [:add_project_menu] => :add_omakase_stack_rails_project
29
30
  end
30
31
 
31
32
  event :go_add_prime_stack_rails_project do
32
- transition [:main_menu] => :add_prime_stack_rails_project
33
+ transition [:add_project_menu] => :add_prime_stack_rails_project
33
34
  end
34
35
 
35
36
  event :go_add_postgresql_instance do
36
- transition [:main_menu] => :add_postgresql_instance
37
+ transition [:add_project_menu] => :add_postgresql_instance
38
+ end
39
+
40
+ event :go_add_project_menu do
41
+ transition [:main_menu] => :add_project_menu
42
+ end
43
+
44
+ event :go_edit_project_menu do
45
+ transition [:main_menu] => :edit_project_menu
37
46
  end
38
47
 
39
48
  event :go_add_mysql_instance do
40
- transition [:main_menu] => :add_mysql_instance
49
+ transition [:add_project_menu] => :add_mysql_instance
41
50
  end
42
51
 
43
52
  event :go_add_redis_instance do
44
- transition [:main_menu] => :add_redis_instance
53
+ transition [:add_project_menu] => :add_redis_instance
54
+ end
55
+
56
+ event :go_back do
57
+ transition [:edit_rails_project] => :edit_project_menu
58
+ transition [:edit_generic_project] => :main_menu
59
+ transition [:add_project_menu] => :main_menu
45
60
  end
46
61
 
47
62
  event :go_add_rack_project do
@@ -50,12 +65,7 @@ state_machine :state, initial: :intialize do
50
65
 
51
66
  event :go_edit_rails_project do
52
67
  transition [
53
- :add_omakase_stack_rails_project,
54
- :add_prime_stack_rails_project,
55
- :edit_rails_controller,
56
- :edit_rails_model,
57
- :toggle_rails_api_mode,
58
- :main_menu
68
+ :edit_project_menu, :add_omakase_stack_rails_project, :add_prime_stack_rails_project
59
69
  ] => :edit_rails_project
60
70
  end
61
71
 
@@ -93,6 +103,7 @@ state_machine :state, initial: :intialize do
93
103
 
94
104
  event :go_edit_links_select_project do
95
105
  transition [:main_menu] => :edit_links_select_project
106
+ transition [:edit_links] => :edit_links_select_project
96
107
  end
97
108
 
98
109
  event :go_edit_links do
@@ -107,13 +118,61 @@ state_machine :state, initial: :intialize do
107
118
 
108
119
  state :main_menu do
109
120
  def display
110
- project.display
121
+ puts
122
+ tp.set :max_width, 160
123
+ tp projects, 'name', 'type', 'options': lambda {|p| p.options.join ", "}
124
+ puts
111
125
  end
112
126
  def choices
113
- project_choices = projects.map do |project|
114
- { name: "Edit '#{ project.name }' project", value: -> { @selected_rails_project = project ; go_edit_rails_project } }
127
+ menu_items = [
128
+ { name: "reload all code", value: -> { reload! }},
129
+ { name: "[m] Add project", value: -> { go_add_project_menu }},
130
+ { name: "[m] Edit existing project", value: -> { go_edit_project_menu }}
131
+ ]
132
+ if projects.length > 1
133
+ menu_items.concat([
134
+ { name: "[m] edit links", value: -> { go_edit_links_select_project }}
135
+ ])
115
136
  end
137
+ if projects.length > 0
138
+ menu_items.concat([
139
+ { name: "Save mproj.json", value: -> { go_save_project }},
140
+ { name: "Generate", value: -> { go_generate }},
141
+ { name: "Build", value: -> { go_build }}
142
+ ])
143
+ end
144
+ menu_items
145
+ end
146
+ def action = false
147
+ end
148
+
149
+ state :edit_project_menu do
150
+ def display
151
+ puts
152
+ tp.set :max_width, 160
153
+ tp projects, 'name', 'type', 'options': lambda {|p| p.options.join ", "}
154
+ puts
155
+ end
156
+ def choices
116
157
  [
158
+ {name: "return to Main Menu", value: -> { go_main_menu }},
159
+ *(projects.map { |project| { name: "Edit '#{ project.name }' project", value: -> { @selected_rails_project = project ; go_edit_rails_project } } })
160
+ ]
161
+ end
162
+ def action = false
163
+ end
164
+
165
+ state :add_project_menu do
166
+ def display
167
+ puts
168
+ tp.set :max_width, 160
169
+ tp projects, 'name', 'type', 'options': lambda {|p| p.options.join ", "}
170
+ puts
171
+ end
172
+
173
+ def choices
174
+ [
175
+ {name: "return to Main Menu", value: -> { go_main_menu }},
117
176
  {name: "Add prime stack rails project", value: -> { go_add_prime_stack_rails_project }},
118
177
  {name: "Add omakase stack rails project", value: -> { go_add_omakase_stack_rails_project }},
119
178
  {name: "Add rack3 project", value: -> { go_add_rack_project }},
@@ -129,24 +188,25 @@ state_machine :state, initial: :intialize do
129
188
  #{ name: "Add couchdb instance", value: -> { go_add_couchdb_instance }},
130
189
  #{ name: "Add kafka instance", value: -> { go_add_kafka_instance }},
131
190
  #{ name: "Add graphql instance", value: -> { go_add_grapql_instance }},
132
- #{ name: "Add gitlab instance w/workers", value: -> { go_add_gitlab_instance }},
133
- *project_choices,
134
- { name: "edit links", value: -> { go_edit_links_select_project }},
135
- { name: "Save mproj.json", value: -> { go_save_project }},
136
- { name: "Generate", value: -> { go_generate }},
137
- { name: "Build", value: -> { go_build }}
191
+ #{ name: "Add gitlab instance w/workers", value: -> { go_add_gitlab_instance }}
138
192
  ]
139
193
  end
140
194
  def action = false
141
195
  end
142
196
 
143
197
  state :edit_links_select_project do
144
- def display = false
198
+ def display
199
+ puts
200
+ tp.set :max_width, 160
201
+ tp projects, 'name', 'type', 'links': lambda {|p| p.links.join ", "}
202
+ puts
203
+ end
145
204
  def choices
146
205
  [
147
206
  {name: "return to Main Menu", value: -> { go_main_menu }},
148
207
  *( projects.map do |project|
149
- { name: "Edit '#{ project.name }' links", value: -> { @selected_project = project ; go_edit_links } }
208
+ links_txt = project.links.join ", "
209
+ { name: "Edit '#{ project.name }' links (#{ links_txt })", value: -> { @selected_project = project ; go_edit_links } }
150
210
  end)
151
211
  ]
152
212
  end
@@ -164,7 +224,7 @@ state_machine :state, initial: :intialize do
164
224
  end
165
225
  end
166
226
  @selected_project.set_links selected
167
- go_main_menu
227
+ go_edit_links_select_project
168
228
  end
169
229
  end
170
230
 
@@ -202,7 +262,8 @@ state_machine :state, initial: :intialize do
202
262
 
203
263
  state :add_prime_stack_rails_project do
204
264
  def display
205
- spacer
265
+ puts "Creates a new rails project, using the prime stack"
266
+ puts "includes rspec haml factory_bot"
206
267
  end
207
268
  def choices = false
208
269
  def action
@@ -214,7 +275,7 @@ state_machine :state, initial: :intialize do
214
275
 
215
276
  state :add_rack_project do
216
277
  def display
217
- spacer
278
+ puts "Creates a new rack project, with a minimal script"
218
279
  end
219
280
  def choices = false
220
281
  def action
@@ -274,7 +335,7 @@ state_machine :state, initial: :intialize do
274
335
 
275
336
  state :toggle_rails_api_mode do
276
337
  def display
277
- Mobilis.logger.info "Toggled rails API mode for '#{@selected_rails_project.name}'"
338
+ Mobilis.logger.info "Toggled rails API mode for '#{ @selected_rails_project.name }'"
278
339
  end
279
340
  def choices = false
280
341
  def action
@@ -347,10 +408,10 @@ def initialize
347
408
  @project = Project.new
348
409
  end
349
410
 
350
-
411
+ ##
412
+ # display, choices, and action methods all change per-state
351
413
  def choose_destination
352
414
  Mobilis.logger.info "#choose_destination"
353
-
354
415
  blank_space
355
416
  spacer
356
417
  display
@@ -377,5 +438,19 @@ def blank_space
377
438
  puts ""
378
439
  end
379
440
 
441
+ def reload!(print = true)
442
+ puts 'Reloading ...' if print
443
+ # Main project directory.
444
+ root_dir = File.expand_path('../..', __dir__)
445
+ # Directories within the project that should be reloaded.
446
+ reload_dirs = %w{lib}
447
+ # Loop through and reload every file in all relevant project directories.
448
+ reload_dirs.each do |dir|
449
+ Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
450
+ end
451
+ # Return true when complete.
452
+ true
453
+ end
454
+
380
455
  end
381
456
  end
@@ -13,6 +13,17 @@ def child_env_vars
13
13
  [ ]
14
14
  end
15
15
 
16
+ def env_vars
17
+ vars = []
18
+ if linked_to_rails_project
19
+ vars << "POSTGRES_DB=#{ linked_to_rails_project.name }_production"
20
+ end
21
+ vars.concat [
22
+ "POSTGRES_USER=#{ name }",
23
+ "POSTGRES_PASSWORD=#{ password }"
24
+ ]
25
+ end
26
+
16
27
  def data_dir
17
28
  "./data/#{ name }"
18
29
  end
@@ -99,17 +99,15 @@ source "https://rubygems.org"
99
99
  # FIXME
100
100
  #git_source(:github) { |repo| "https://github.com/repo.git" }
101
101
 
102
- ruby "3.1.2"
103
-
104
- gem "rails", "~> 7.0.3", ">= 7.0.3.1"
105
- gem "sqlite3", "~> 1.4"
106
- gem "puma", "~> 5.0"
102
+ gem "rails"
103
+ gem "sqlite3"
104
+ gem "puma"
107
105
  gem "jbuilder"
108
- gem "redis", "~> 4.0"
106
+ gem "redis"
109
107
  gem "kredis"
110
- gem "bcrypt", "~> 3.1.7"
108
+ gem "bcrypt"
111
109
  gem "bootsnap", require: false
112
- gem "image_processing", "~> 1.2"
110
+ gem "image_processing"
113
111
  gem "rack-cors"
114
112
  gem "pg"
115
113
  gem "mysql2"
@@ -130,7 +128,7 @@ end
130
128
 
131
129
  def has_rails_project?
132
130
  projects.each do |p|
133
- return true if p.type == :rails
131
+ return true if p.type.to_sym == :rails
134
132
  end
135
133
  return false
136
134
  end
@@ -159,6 +157,11 @@ def build_rails_builder
159
157
  run_docker "build -t #{ rails_builder_image } ."
160
158
  end
161
159
 
160
+ def load_from_file filename
161
+ data = File.read filename
162
+ @data = JSON.parse data, {:symbolize_names => true}
163
+ end
164
+
162
165
  def save_project
163
166
  File.open("mproj.json", "w") do |f|
164
167
  f.write(JSON.pretty_generate(@data))
@@ -181,7 +184,7 @@ def projects
181
184
  redis: RedisInstance,
182
185
  rack: RackProject
183
186
  }
184
- @data[:projects].map {|p| mapping[p[:type]].new p, self}
187
+ @data[:projects].map {|p| mapping[p[:type].to_sym].new p, self}
185
188
  end
186
189
 
187
190
  def project_by_name name
@@ -21,7 +21,8 @@ def generate
21
21
  end
22
22
 
23
23
  def generate_config_ru
24
- set_file_contents "config.ru", '# config.ru
24
+ set_file_contents "config.ru", <<CONFIG_RU
25
+ # config.ru
25
26
  app = Proc.new {
26
27
  [
27
28
  200,
@@ -30,11 +31,12 @@ app = Proc.new {
30
31
  ]
31
32
  }
32
33
  run app
33
- '
34
+ CONFIG_RU
34
35
  end
35
36
 
36
37
  def generate_Gemfile
37
- set_file_contents "Gemfile", '# frozen_string_literal: true
38
+ set_file_contents "Gemfile", <<GEMFILE
39
+ # frozen_string_literal: true
38
40
 
39
41
  source "https://rubygems.org"
40
42
 
@@ -43,11 +45,12 @@ source "https://rubygems.org"
43
45
  gem "rack", "= 3.0.0.beta1"
44
46
 
45
47
  gem "rackup", "~> 0.2.2"
46
- '
48
+ GEMFILE
47
49
  end
48
50
 
49
51
  def generate_Gemfile_lock
50
- set_file_contents "Gemfile.lock", 'GEM
52
+ set_file_contents "Gemfile.lock", <<GEMFILE_LOCK
53
+ GEM
51
54
  remote: https://rubygems.org/
52
55
  specs:
53
56
  rack (3.0.0.beta1)
@@ -65,11 +68,11 @@ DEPENDENCIES
65
68
 
66
69
  BUNDLED WITH
67
70
  2.3.16
68
- '
71
+ GEMFILE_LOCK
69
72
  end
70
73
 
71
74
  def generate_Dockerfile
72
- set_file_contents "Dockerfile", '
75
+ set_file_contents "Dockerfile", <<DOCKER_END
73
76
  FROM ruby:latest
74
77
  RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
75
78
  WORKDIR /myapp
@@ -79,10 +82,9 @@ RUN bundle install
79
82
  COPY . /myapp
80
83
 
81
84
  # Add a script to be executed every time the container starts.
82
- ENTRYPOINT ["rackup"]
85
+ ENTRYPOINT ["rackup", "-o", "#{ name }"]
83
86
  EXPOSE 9292
84
-
85
- '
87
+ DOCKER_END
86
88
  end
87
89
 
88
90
  end
@@ -81,6 +81,7 @@ def generate
81
81
  install_rspec if options.include? :rspec
82
82
  install_factory_bot if options.include? :factory_bot
83
83
  git_commit_all "add Gems"
84
+ generate_wait_until
84
85
  generate_Dockerfile
85
86
  generate_entrypoint_sh
86
87
  generate_build_sh
@@ -96,10 +97,36 @@ def rails_master_key
96
97
  @data[:attributes][:rails_master_key]
97
98
  end
98
99
 
100
+ def generate_wait_until
101
+ set_file_contents 'wait-until', <<WAITUNTIL
102
+ #!/usr/bin/env bash
103
+ # https://github.com/nickjj/wait-until under MIT license
104
+
105
+ command="${1}"
106
+ timeout="${2:-30}"
107
+
108
+ i=1
109
+ until eval "${command}"
110
+ do
111
+ ((i++))
112
+
113
+ if [ "${i}" -gt "${timeout}" ]; then
114
+ echo "command was never successful, aborting due to ${timeout}s timeout!"
115
+ exit 1
116
+ fi
117
+
118
+ sleep 1
119
+ done
120
+ WAITUNTIL
121
+ end
122
+
123
+
99
124
  def generate_Dockerfile
100
- set_file_contents "Dockerfile", 'FROM ruby:latest
101
- RUN apt-get update -qq && apt-get install -y nodejs postgresql-client dos2unix
125
+ set_file_contents "Dockerfile", <<DOCKER_END
126
+ FROM ruby:latest
127
+ RUN apt-get update -qq && apt-get install -y nodejs postgresql-client default-mysql-client dos2unix
102
128
  WORKDIR /myapp
129
+ COPY --chmod=0755 wait-until /myapp/wait-until
103
130
  COPY Gemfile /myapp/Gemfile
104
131
  COPY Gemfile.lock /myapp/Gemfile.lock
105
132
  RUN bundle install
@@ -113,11 +140,12 @@ RUN dos2unix /myapp/entrypoint.sh
113
140
 
114
141
  # Configure the main process to run when running the image
115
142
  CMD ["rails", "server", "-b", "0.0.0.0"]
116
- '
143
+ DOCKER_END
117
144
  end
118
145
 
119
146
  def generate_entrypoint_sh
120
- set_file_contents "entrypoint.sh", "#!/bin/sh
147
+ set_file_contents "entrypoint.sh", <<ENTRYPOINT_SH
148
+ #!/bin/sh
121
149
 
122
150
  # https://stackoverflow.com/a/38732187/1935918
123
151
  set -e
@@ -125,11 +153,25 @@ set -e
125
153
  if [ -f /app/tmp/pids/server.pid ]; then
126
154
  rm /app/tmp/pids/server.pid
127
155
  fi
128
-
156
+ #{ wait_until_line }
129
157
  bundle exec rake db:migrate 2>/dev/null || bundle exec rake db:setup
130
158
 
131
- exec bundle exec \"$@\"
132
- "
159
+ exec bundle exec "$@"
160
+ ENTRYPOINT_SH
161
+ end
162
+
163
+ def wait_until_line
164
+ if database.instance_of? Mobilis::PostgresqlInstance
165
+ return <<POSTGRES_LINE
166
+ /myapp/wait-until "psql postgres://#{ database.username }:#{ database.password }@#{ database.name }/#{ name }_production -c 'select 1'"
167
+ POSTGRES_LINE
168
+ end
169
+ # instance_of? is a code smell - maybe this should be database.wait_until_line ?
170
+ if database.instance_of? Mobilis::MysqlInstance
171
+ return <<MYSQL_LINE
172
+ /myapp/wait-until "mysql -D #{ name }_production -h #{ database.name } -u #{ database.username } -p#{ database.password } -e 'select 1'"
173
+ MYSQL_LINE
174
+ end
133
175
  end
134
176
 
135
177
  def install_rspec
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mobilis
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
data/lib/mobilis.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "mobilis/version"
4
+ require_relative "mobilis/command_line"
4
5
  require_relative "mobilis/project"
5
6
  require_relative "mobilis/docker_compose_projector"
6
7
 
data/mobilis.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mobilis/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mobilis"
7
+ spec.version = Mobilis::VERSION
8
+ spec.authors = ["Meleneth"]
9
+ spec.email = ["meleneth@gmail.com"]
10
+
11
+ spec.summary = "Generate and scaffold multiple projects and a docker compose file"
12
+ spec.homepage = "https://github.com/meleneth/mobilis"
13
+ spec.required_ruby_version = ">= 2.6.0"
14
+ spec.licenses = ['MIT']
15
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/meleneth/mobilis"
19
+ spec.metadata["changelog_uri"] = "https://github.com/meleneth/mobilis/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+ spec.executables << 'mobilis'
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ spec.add_dependency "awesome_print"
35
+ spec.add_dependency "optimist"
36
+ spec.add_dependency "pry"
37
+ spec.add_dependency "state_machine"
38
+ spec.add_dependency "table_print"
39
+ spec.add_dependency "tty-prompt"
40
+
41
+ spec.add_development_dependency "super_diff"
42
+
43
+ # spec.add_dependency "example-gem", "~> 1.0"
44
+
45
+ # For more information and examples about making a new gem, check out our
46
+ # guide at: https://bundler.io/guides/creating_gem.html
47
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobilis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meleneth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-20 00:00:00.000000000 Z
11
+ date: 2022-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: state_machine
28
+ name: optimist
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: tty-prompt
42
+ name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: state_machine
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: optimist
70
+ name: table_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tty-prompt
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -109,6 +123,7 @@ files:
109
123
  - Gemfile.lock
110
124
  - README.md
111
125
  - Rakefile
126
+ - TODO.md
112
127
  - exe/mobilis
113
128
  - lib/mobilis.rb
114
129
  - lib/mobilis/actions_projects_take.rb
@@ -126,6 +141,7 @@ files:
126
141
  - lib/mobilis/rails_project.rb
127
142
  - lib/mobilis/redis_instance.rb
128
143
  - lib/mobilis/version.rb
144
+ - mobilis.gemspec
129
145
  - sig/mobilis.rbs
130
146
  homepage: https://github.com/meleneth/mobilis
131
147
  licenses: