roro 0.3.5 → 0.3.12

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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -2
  3. data/Guardfile +4 -10
  4. data/lib/roro.rb +0 -1
  5. data/lib/roro/cli.rb +75 -5
  6. data/lib/roro/cli/base/base.rb +2 -1
  7. data/lib/roro/cli/base/base_files.rb +1 -7
  8. data/lib/roro/cli/base/check_dependencies.rb +98 -0
  9. data/lib/roro/cli/base/insert_gems.rb +15 -7
  10. data/lib/roro/cli/base/insertions.rb +3 -1
  11. data/lib/roro/cli/cli.rb +99 -0
  12. data/lib/roro/cli/configuration.rb +69 -0
  13. data/lib/roro/cli/expose.rb +8 -7
  14. data/lib/roro/cli/generate/config.rb +13 -0
  15. data/lib/roro/cli/generate/config/rails.rb +17 -0
  16. data/lib/roro/cli/generate/generate.rb +1 -0
  17. data/lib/roro/cli/generate/generate_keys.rb +47 -0
  18. data/lib/roro/cli/greenfield.rb +20 -31
  19. data/lib/roro/cli/obfuscate.rb +10 -11
  20. data/lib/roro/cli/rollon.rb +67 -21
  21. data/lib/roro/cli/rollon/stories.rb +2 -3
  22. data/{.keep → lib/roro/cli/rollon/stories/database.rb} +0 -0
  23. data/lib/roro/cli/rollon/stories/rails.rb +1 -0
  24. data/lib/roro/cli/{templates/base/roro → rollon/stories/rails}/.keep +0 -0
  25. data/lib/roro/cli/rollon/stories/rails/database.rb +33 -0
  26. data/lib/roro/cli/rollon/stories/rails/database/with_mysql.rb +22 -0
  27. data/lib/roro/cli/rollon/stories/rails/database/with_postgresql.rb +21 -0
  28. data/lib/roro/cli/rollon/stories/ruby_gem.rb +77 -0
  29. data/lib/roro/cli/rollon/stories/ruby_gem/with_ci_cd.rb +81 -0
  30. data/lib/roro/cli/rollon/stories/stories.rb +3 -0
  31. data/lib/roro/cli/roro_configurator.yml +157 -0
  32. data/lib/roro/cli/ruby_gem.rb +60 -47
  33. data/lib/roro/cli/templates/base/.roro_config.yml +15 -0
  34. data/lib/roro/cli/templates/base/Dockerfile.tt +82 -0
  35. data/lib/roro/cli/templates/base/config/database.mysql.yml +19 -0
  36. data/lib/roro/cli/templates/base/config/{database.yml.pg.tt → database.pg.yml} +0 -0
  37. data/lib/roro/cli/templates/greenfield/Dockerfile.tt +29 -7
  38. data/lib/roro/cli/templates/{base/livereload → livereload}/hosts.example +0 -0
  39. data/lib/roro/cli/templates/{base/roro/containers → roro}/.keep +0 -0
  40. data/lib/roro/cli/templates/{greenfield → roro}/docker-compose.yml.tt +18 -13
  41. data/lib/roro/cli/templates/{base/roro/containers/app → roro/roro}/.keep +0 -0
  42. data/lib/roro/cli/templates/{base/roro/containers/frontend → roro/roro/containers}/.keep +0 -0
  43. data/lib/roro/cli/templates/{dockerize/.env → roro/roro/containers/app}/.keep +0 -0
  44. data/lib/roro/cli/templates/{dockerize/.env/development → roro/roro/containers/frontend}/.keep +0 -0
  45. data/lib/roro/cli/templates/{quickstart/entrypoint.sh → roro/roro/docker-entrypoint.sh.tt} +1 -1
  46. data/lib/roro/cli/templates/ruby_gem/.circleci/config.yml +17 -0
  47. data/lib/roro/cli/templates/ruby_gem/docker-compose.yml +6 -4
  48. data/lib/roro/cli/templates/ruby_gem/roro/ci.env.tt +1 -0
  49. data/lib/roro/cli/templates/{dockerize → ruby_gem/roro/containers}/.keep +0 -0
  50. data/lib/roro/cli/templates/ruby_gem/roro/containers/ruby_image/Dockerfile.tt +16 -0
  51. data/lib/roro/cli/templates/ruby_gem/{docker/env_files → roro/keys}/.keep +0 -0
  52. data/lib/roro/cli/templates/{ruby_gem/docker/keys → stories}/.keep +0 -0
  53. data/lib/roro/cli/templates/stories/with_mysql/_service.yml +10 -0
  54. data/lib/roro/cli/templates/stories/with_postgresql/.keep +0 -0
  55. data/lib/roro/cli/templates/stories/with_postgresql/_service.yml +7 -0
  56. data/lib/roro/version.rb +1 -1
  57. data/roro.gemspec +3 -4
  58. data/sandbox/.keep +0 -0
  59. data/vendor/cache/concurrent-ruby-1.1.7.gem +0 -0
  60. data/vendor/cache/gem-release-2.1.1.gem +0 -0
  61. metadata +69 -66
  62. data/lib/roro/cli/base/configuration.rb +0 -118
  63. data/lib/roro/cli/generate_keys.rb +0 -79
  64. data/lib/roro/cli/rollon/rollon_as_dockerize.rb +0 -42
  65. data/lib/roro/cli/rollon/rollon_as_quickstart.rb +0 -17
  66. data/lib/roro/cli/rollon/rollon_as_roro.rb +0 -30
  67. data/lib/roro/cli/templates/base/circleci/config.yml.tt +0 -70
  68. data/lib/roro/cli/templates/base/docker-compose.yml.tt +0 -53
  69. data/lib/roro/cli/templates/base/pg/config/database.yml.pg.tt +0 -20
  70. data/lib/roro/cli/templates/base/pg/database.yml.pg.tt +0 -20
  71. data/lib/roro/cli/templates/base/roro/containers/app/Dockerfile.tt +0 -32
  72. data/lib/roro/cli/templates/base/roro/containers/app/development.env.tt +0 -1
  73. data/lib/roro/cli/templates/base/roro/containers/app/docker-entrypoint.sh +0 -8
  74. data/lib/roro/cli/templates/base/roro/containers/app/test.env.tt +0 -1
  75. data/lib/roro/cli/templates/base/roro/containers/database/development.env.tt +0 -4
  76. data/lib/roro/cli/templates/base/roro/containers/database/test.env.tt +0 -4
  77. data/lib/roro/cli/templates/dockerize/.env/development/database +0 -3
  78. data/lib/roro/cli/templates/dockerize/.env/development/web +0 -1
  79. data/lib/roro/cli/templates/dockerize/Dockerfile.tt +0 -23
  80. data/lib/roro/cli/templates/dockerize/docker-compose.yml.tt +0 -60
  81. data/lib/roro/cli/templates/dockerize/docker-entrypoint.sh +0 -9
  82. data/lib/roro/cli/templates/quickstart/Dockerfile.tt +0 -20
  83. data/lib/roro/cli/templates/quickstart/database.yml +0 -85
  84. data/lib/roro/cli/templates/quickstart/docker-compose.yml +0 -17
  85. data/lib/roro/cli/templates/ruby_gem/.gitignore +0 -8
  86. data/lib/roro/cli/templates/ruby_gem/config.yml +0 -122
  87. data/lib/roro/cli/templates/ruby_gem/docker/containers/app/Dockerfile.tt +0 -10
  88. data/roro-0.3.4.gem +0 -0
  89. data/vendor/cache/concurrent-ruby-1.1.6.gem +0 -0
@@ -1,13 +1,14 @@
1
1
  module Roro
2
2
  class CLI < Thor
3
+
4
+ no_commands do
3
5
 
4
- desc "expose", "Expose encrypted files"
5
-
6
- def expose(*args)
7
- environments = args.first ? [args.first] : gather_environments
8
- environments.each do |environment|
9
- HandsomeFencer::Crypto.expose(environment, 'docker')
6
+ def expose(*args)
7
+ environments = args.first ? [args.first] : gather_environments
8
+ environments.each do |environment|
9
+ HandsomeFencer::Crypto.expose(environment, 'roro')
10
+ end
10
11
  end
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Roro
2
+ class CLI < Thor
3
+ include Thor::Actions
4
+
5
+ # desc "generate::config::roro", "Generate a config file at .roro_config.yml"
6
+ # map "generate::config::roro" => "generate_roro_config"
7
+
8
+
9
+ # def generate_roro_config
10
+ # create_file ".roro_config.yml", @config.app.to_yaml
11
+ # end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # module Roro
2
+ # class CLI < Thor
3
+ # include Thor::Actions
4
+
5
+ # desc "generate::config::rails", "Generates a config file to use roro with
6
+ # a rails app at .roro.yml"
7
+ # map "generate::config::rails" => "generate_config_rails"
8
+
9
+ # def generate_config_rails
10
+ # master_config = YAML.load_file(ENV['PWD'] + "/lib/roro/cli/roro_configurator.yml")
11
+ # template 'base/.roro_config.yml', '.roro_config.yml'
12
+ # end
13
+
14
+ # no_commands do
15
+ # end
16
+ # end
17
+ # end
@@ -0,0 +1 @@
1
+ require_relative 'config/rails'
@@ -0,0 +1,47 @@
1
+ module Roro
2
+
3
+ class CLI < Thor
4
+
5
+ no_commands do
6
+
7
+ def generate_key_or_keys(*args)
8
+ environments = args.first ? [args.first] : gather_environments
9
+ environments.each do |environment|
10
+
11
+ confirm_files_decrypted?(environment)
12
+ create_file "roro/keys/#{environment}.key", encoded_key
13
+ end
14
+ end
15
+
16
+ def encoded_key
17
+ @cipher = OpenSSL::Cipher.new 'AES-128-CBC'
18
+ @salt = '8 octets'
19
+ @new_key = @cipher.random_key
20
+ Base64.encode64(@new_key)
21
+ end
22
+
23
+ def gather_environments
24
+ environments = []
25
+ ['.env', '.env.enc'].each do |extension|
26
+ HandsomeFencer::Crypto.source_files('roro', extension).each do |env_file|
27
+ environments << env_file.split('/').last.split(extension).last
28
+ end
29
+ end
30
+ environments.uniq
31
+ end
32
+
33
+ def confirm_files_decrypted?(environment)
34
+ orphan_encrypted = []
35
+ HandsomeFencer::Crypto.source_files('.', '.env.enc').each do |file|
36
+ unless File.exist? file.split('.enc').first
37
+ orphan_encrypted << file
38
+ end
39
+ end
40
+ if !orphan_encrypted.empty?
41
+ raise Roro::Error.new("You have an encrypted files (.env.enc) #{orphan_encrypted} that do not have corresponding decrypted files (.env). Please decrypt or remove these encrypted files before generating a new key for #{environment}.")
42
+ end
43
+ true
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,42 +1,31 @@
1
- require 'os'
2
-
3
1
  module Roro
4
2
 
5
3
  class CLI < Thor
6
-
7
- include Thor::Actions
8
-
9
- desc "greenfield", "Greenfield a brand new rails app using Docker's instructions"
10
-
11
- method_option :env_vars, type: :hash, default: {}, desc: "Pass a list of environment variables like so: env:var", banner: "key1:value1 key2:value2"
12
- method_option :interactive, desc: "Set up your environment variables as you go."
13
- method_option :force, desc: "force over-write of existing files"
14
-
15
-
16
- def greenfield
17
- confirm_dependencies
18
- confirm_dependency({
19
- system_query: "ls -A",
20
- warning: "this is not an empty directory. Roro will not greenfield a new Rails app unless either a) the current directory is empty or b) you run greenfield with the --force flag",
21
- suggestion: "$ roro greenfield --force",
22
- conditional: "Dir.glob('*').empty?" })
23
- get_configuration_variables
24
- copy_greenfield_files
25
- copy_greenfield_to_host
26
- @env_hash[:use_force] = { force: true }
27
- rollon
28
- end
29
-
4
+
30
5
  no_commands do
31
-
32
- def copy_greenfield_files
33
- template 'greenfield/Dockerfile.tt', 'Dockerfile', @env_hash
34
- template 'greenfield/docker-compose.yml.tt', 'docker-compose.yml', @env_hash
6
+
7
+ def greenfield
8
+ confirm_directory_empty
9
+ confirm_dependencies
10
+ remove_roro_artifacts
11
+ configure_for_greenfielding
12
+ copy_greenfield_files
13
+ run_greenfield_commands
35
14
  end
36
15
 
37
- def copy_greenfield_to_host
16
+ def configure_for_greenfielding
17
+ @config ||= Roro::Configuration.new(options)
18
+ end
19
+
20
+ def run_greenfield_commands
38
21
  system "DOCKER_BUILDKIT=1 docker build --file Dockerfile --output . ."
22
+ rollon
39
23
  end
24
+
25
+ def copy_greenfield_files
26
+ template 'greenfield/Dockerfile.tt', 'Dockerfile', @config.app
27
+ template 'roro/docker-compose.yml.tt', 'docker-compose.yml', @config.app
28
+ end
40
29
  end
41
30
  end
42
31
  end
@@ -3,17 +3,16 @@ require 'handsome_fencer/crypto'
3
3
  module Roro
4
4
 
5
5
  class CLI < Thor
6
-
7
- include Thor::Actions
8
- include HandsomeFencer::Crypto
9
-
10
- desc "obfuscate", "obfuscates any files matching the pattern ./docker/**/*.env"
11
-
12
- def obfuscate(*args)
13
- default_environments = %w[circleci development staging production]
14
- environments = args.first ? [args.first] : default_environments
15
- environments.each do |environment|
16
- HandsomeFencer::Crypto.obfuscate(environment, 'docker')
6
+
7
+ no_commands do
8
+ include Thor::Actions
9
+ include HandsomeFencer::Crypto
10
+
11
+ def obfuscate(*args)
12
+ environments = args.first ? [args.first] : gather_environments
13
+ environments.each do |environment|
14
+ HandsomeFencer::Crypto.obfuscate(environment, 'roro')
15
+ end
17
16
  end
18
17
  end
19
18
  end
@@ -1,38 +1,84 @@
1
- require_relative 'rollon/stories'
1
+ require 'roro/cli/rollon/stories'
2
2
 
3
3
  module Roro
4
4
 
5
5
  class CLI < Thor
6
6
 
7
- desc "rollon", "Generates files and makes changes to your rails app
8
- necessary to run it using Docker containers."
7
+ desc "rollon", "Generates files for and makes changes to your app
8
+ so it can run using Docker containers."
9
9
  method_option :interactive, desc: "Set up your environment variables as
10
10
  you go."
11
11
 
12
12
  def rollon
13
+ confirm_directory_not_empty
13
14
  confirm_dependencies
14
- confirm_dependency({
15
- system_query: "ls -A",
16
- warning: "This is an empty directory. You can generate a new and fully
17
- dockerized Rails app using the 'greenfield' command here here but if
18
- you want to containerize an existing app -- which is what the 'rollon'
19
- command is for -- you'll need to navigate to a directory with an app we
20
- can roll onto.",
21
- suggestion: "$ roro greenfield",
22
- conditional: "!Dir.glob('*').empty?" })
23
- @env_hash || get_configuration_variables
24
- # case ask("Configure using the Quickstart, Curated, or HandsomeFencer way?\n\n(1) Quikstart\n\n(2) Curated\n\n(3) HandsomeFencer\n\n", { default: '2', limited_to: %w(1 2 3) })
25
- # when '1'
26
- # rollon_as_quickstart
27
- # when '2'
28
- # rollon_as_dockerized
29
- # when '3'
30
- # end
31
- rollon_as_dockerize
15
+ remove_roro_artifacts
16
+
17
+ configure_for_rollon
18
+
19
+ copy_roro_files
20
+ generate_config
21
+ startup_commands
32
22
  end
33
23
 
34
24
  no_commands do
25
+
26
+ def configure_for_rollon
27
+ @config ||= Roro::Configuration.new(options)
28
+ end
29
+
30
+ def yaml_from_template(file)
31
+ File.read(File.dirname(__FILE__) + "/templates/#{file}")
32
+ end
33
+
34
+ def copy_roro_files
35
+ configure_database
36
+ directory 'roro', './', @config.app
37
+ template 'base/Dockerfile.tt', 'roro/containers/app/Dockerfile', @config.app
38
+ take_thor_actions
39
+ end
40
+
41
+ def take_thor_actions
42
+ @config.thor_actions.each {|k, v| eval(k) if v.eql?('y') }
43
+ end
44
+
45
+ def startup_commands
46
+ system 'docker-compose build'
47
+ system 'docker-compose run web bundle'
48
+ system 'docker-compose run web bin/rails webpacker:install'
49
+ system 'docker-compose run web bin/rails yarn:install'
50
+ system 'docker-compose run web bin/rails db:create'
51
+ system 'docker-compose run web bin/rails db:migrate'
52
+ system 'docker-compose up'
53
+ end
54
+
55
+ def confirm_directory_empty
56
+ confirm = confirm_dependency({
57
+ system_query: "ls -A",
58
+ warning: "this is not an empty directory. Roro will not greenfield a new Rails app unless either a) the current directory is empty or b) you run greenfield with the --force flag",
59
+ suggestion: "$ roro greenfield --force",
60
+ conditional: "Dir.glob('*').empty?" })
61
+ confirm || true
62
+ end
63
+
35
64
 
65
+ def confirm_dependency(options)
66
+ msg = []
67
+ msg << ""
68
+ msg << delineator
69
+ msg << "It looks like #{options[:warning]}. The following bash command returns false:"
70
+ msg << "\t$ #{options[:system_query]}"
71
+ msg << "Please try these instructions:"
72
+ msg << ("\t" + options[:suggestion])
73
+ msg << delineator
74
+ conditional = options[:conditional] ? eval(options[:conditional]) : system(options[:system_query])
75
+ if conditional == false
76
+ raise(Roro::Error.new(msg.join("\n\n")))
77
+ else
78
+ true
79
+ end
80
+ end
81
+
36
82
  end
37
83
  end
38
84
  end
@@ -1,3 +1,2 @@
1
- require_relative 'rollon_as_quickstart.rb'
2
- require_relative 'rollon_as_dockerize.rb'
3
- require_relative 'rollon_as_roro.rb'
1
+ require 'roro/cli/rollon/stories/ruby_gem'
2
+ require 'roro/cli/rollon/stories/rails'
@@ -0,0 +1 @@
1
+ require 'roro/cli/rollon/stories/rails/database'
@@ -0,0 +1,33 @@
1
+ require 'roro/cli/rollon/stories/rails/database/with_mysql'
2
+ require 'roro/cli/rollon/stories/rails/database/with_postgresql'
3
+ module Roro
4
+
5
+ class CLI < Thor
6
+
7
+ no_commands do
8
+
9
+ def configure_database
10
+ database = @config.thor_actions['configure_database']
11
+ vendor = @config.master['services']['database']['vendors']
12
+ case database
13
+ when 'p'
14
+ @config.app['database_vendor'] = 'postgresql'
15
+ @config.app['postgresql_env_vars'] = vendor['postgresql']['env_vars']
16
+ configure_for_pg
17
+ when 'm'
18
+ @config.app['database_vendor'] = 'mysql'
19
+ @config.app['mysql_env_vars'] = vendor['mysql']['env_vars']
20
+ configure_for_mysql
21
+ end
22
+
23
+ %w(development production test staging ci).each do |environment|
24
+ template(
25
+ 'base/.env/web.env.tt',
26
+ "roro/containers/app/#{environment}.env", @config.app
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,22 @@
1
+ module Roro
2
+
3
+ class CLI < Thor
4
+
5
+ no_commands do
6
+
7
+ def configure_for_mysql
8
+ insert_db_gem('mysql2')
9
+ copy_file 'base/config/database.mysql.yml', 'config/database.yml', force: true
10
+ config = @config.app.clone
11
+
12
+ %w(development production test staging ci).each do |environment|
13
+ config['rails_env'] = environment
14
+
15
+ source = 'base/.env/database.mysql.env.tt'
16
+ target = "roro/containers/database/#{environment}.env"
17
+ template( source, target, config )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module Roro
2
+
3
+ class CLI < Thor
4
+
5
+ no_commands do
6
+
7
+ def configure_for_pg
8
+ insert_db_gem('pg')
9
+ copy_file 'base/config/database.pg.yml', 'config/database.yml', force: true
10
+ config = @config.app.clone
11
+ %w(development production test staging ci).each do |environment|
12
+ config['rails_env'] = environment
13
+
14
+ source = 'base/.env/database.pg.env.tt'
15
+ target = "roro/containers/database/#{environment}.env"
16
+ template( source, target, config )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,77 @@
1
+ require 'roro/cli/rollon/stories/ruby_gem/with_ci_cd.rb'
2
+ # class RubyGem
3
+ # attr_reader :getsome
4
+
5
+ # def initialize
6
+ # @getsome = 'getsome'
7
+ # end
8
+ # end
9
+
10
+ # include Stories::RubyGem
11
+ # module Rollon
12
+ # module Story
13
+
14
+ # end
15
+ # end
16
+ # class Rollon::Story::RubyGem < Roro::CLI
17
+ # attr_reader :getsome
18
+ # def initialize
19
+ # @getsome = 'getsome'
20
+ # end
21
+ # end
22
+
23
+ # # module Roro
24
+
25
+ # # class CLI < Thor
26
+
27
+
28
+ # # no_commands do
29
+
30
+ # # def ruby_gem(*args)
31
+
32
+
33
+ # # end
34
+ # # def copy_ruby_gem_files
35
+ # # copy_file 'ruby_gem/config.yml', '.circleci/config.yml'
36
+ # # end
37
+ # # end
38
+
39
+ # # def ruby_gem
40
+ # # rubies = options["rubies"] || ["2.5.3", "2.6.0"]
41
+ # # copy_file 'ruby_gem/docker-compose.yml', 'docker-compose.yml'
42
+ # # copy_file 'ruby_gem/config.yml', '.circleci/config.yml'
43
+ # # copy_file 'ruby_gem/setup-gem-credentials.sh', '.circleci/setup-gem-credentials.sh'
44
+ # # directory 'ruby_gem/docker', 'docker', { ruby_version: "2.5"}
45
+
46
+ # # rubies.each do |ruby|
47
+ # # rubydash = ruby.gsub('.', '-')
48
+ # # rubyunderscore = ruby.gsub('.', '_')
49
+ # # doc_loc = "docker/containers/#{rubyunderscore}/Dockerfile"
50
+ # # content = <<-EOM
51
+
52
+ # # app-#{rubydash}:
53
+ # # build:
54
+ # # context: .
55
+ # # dockerfile: #{doc_loc}
56
+ # # command: rake test
57
+ # # EOM
58
+ # # append_to_file 'docker-compose.yml', content
59
+ # # template 'ruby_gem/docker/containers/app/Dockerfile.tt', doc_loc, {ruby_version: ruby}
60
+ # # # append_to_file 'docker-compose.yml', "\n app-#{ruby}:\n build:\n\s\s\s\s\s\scontext:"
61
+ # # end
62
+
63
+ # # # end
64
+ # # # <<EOF
65
+ # # # This is the first way of creating
66
+ # # # here document ie. multiple line string.
67
+ # # # EOF
68
+ # # # %w[app web].each do |container|
69
+ # # # options = {
70
+ # # # email: @env_hash['DOCKERHUB_EMAIL'],
71
+ # # # app_name: @env_hash['APP_NAME'] }
72
+ # # #
73
+ # # # template("docker/containers/#{container}/Dockerfile.tt", "docker/containers/#{container}/Dockerfile", options)
74
+ # # # end
75
+ # # end
76
+ # # end
77
+ # # end