dockerize_rails 1.0.3.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4e165e07e5a148fb3147133467337f4c87592c3
4
+ data.tar.gz: da828631c4c0c935303e7972438366525a12b84a
5
+ SHA512:
6
+ metadata.gz: ab565063675c08e2594dd4ffdb89a32bd86631942ebd27593ba148e4a7b2a3ddce48aa7f7250038c149587f809b2cffeea88f15108861974f3bd6bc228ceb476
7
+ data.tar.gz: 3d4b13b165ed3fac19d4db9a43dca05f862a515a6a7a4f8be84ff1d27b0f858fbf48285887e1e603f622d0998b1f5dc77bea002638b4f9273d39b7f8f30026e6
data/.codeclimate.yml ADDED
@@ -0,0 +1,19 @@
1
+ engines:
2
+ duplication:
3
+ enabled: true
4
+ config:
5
+ languages:
6
+ - ruby
7
+ fixme:
8
+ enabled: true
9
+ rubocop:
10
+ enabled: true
11
+ checks:
12
+ Rubocop/Style/PercentLiteralDelimiters:
13
+ enabled: false
14
+ ratings:
15
+ paths:
16
+ - "**.rb"
17
+ exclude_paths:
18
+ - spec/**/*
19
+ - "**/vendor/**/*"
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /doc/
5
+ /Gemfile.lock
6
+ /coverage/
7
+ /pkg/
8
+ /spec/reports/
9
+ .rspec_status
10
+ /tmp/
11
+ .idea/
12
+ .ruby-version
13
+ *.gem
14
+ /vendor/ruby
15
+ !*/.gitkeep
16
+ /docker-compose.yml
17
+ /.dockerize.yml
18
+ /.dockerized
19
+ /dockerw
20
+ .dockerignore
data/.reek ADDED
@@ -0,0 +1,24 @@
1
+ exclude_paths:
2
+ - vendor
3
+ - spec
4
+ - bin
5
+ - doc
6
+ - pkg
7
+
8
+ TooManyConstants:
9
+ enabled: false
10
+
11
+ TooManyStatements:
12
+ max_statements: 15
13
+
14
+ IrresponsibleModule:
15
+ enabled: false
16
+
17
+ TooManyInstanceVariables:
18
+ enabled: false
19
+
20
+ DuplicateMethodCall:
21
+ enabled: false
22
+
23
+ InstanceVariableAssumption:
24
+ enabled: false
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,41 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'spec/**/*'
5
+ - 'vendor/**/*'
6
+
7
+ Lint/SafeNavigationChain:
8
+ Enabled: false
9
+
10
+ Metrics/LineLength:
11
+ Max: 120
12
+
13
+ Metrics/ClassLength:
14
+ Max: 150
15
+
16
+ Metrics/ModuleLength:
17
+ Max: 150
18
+
19
+ Metrics/MethodLength:
20
+ Max: 15
21
+
22
+ Metrics/AbcSize:
23
+ Max: 20
24
+
25
+ Style/BlockComments:
26
+ Enabled: false
27
+
28
+ Style/Documentation:
29
+ Enabled: false
30
+
31
+ Style/ExtraSpacing:
32
+ AllowForAlignment: true
33
+
34
+ Style/FrozenStringLiteralComment:
35
+ Enabled: false
36
+
37
+ Style/NumericLiterals:
38
+ Enabled: false
39
+
40
+ Style/Next:
41
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.0
7
+ - 2.3.0
8
+ - 2.4.0
9
+ - 2.4.1
10
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at eendroroy@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1 @@
1
+ * **indrajit** ([eendroroy](https://github.com/eendroroy)) - *Owner*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dockerize_rails.gemspec
4
+ gemspec
5
+
6
+ gem 'reek'
7
+ gem 'rubocop'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 indrajit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # DockerizeRails
2
+
3
+ [![GitHub tag](https://img.shields.io/github/tag/eendroroy/dockerize_rails.svg)](https://github.com/eendroroy/dockerize_rails)
4
+ [![Gem Version](https://badge.fury.io/rb/dockerize_rails.svg)](https://rubygems.org/gems/dockerize_rails)
5
+ [![Downloads](https://img.shields.io/gem/dt/dockerize_rails.svg)](https://rubygems.org/gems/dockerize_rails)
6
+ [![Build Status](https://travis-ci.org/eendroroy/dockerize_rails.svg?branch=master)](https://travis-ci.org/eendroroy/dockerize_rails)
7
+ [![Code Climate](https://codeclimate.com/github/eendroroy/dockerize_rails/badges/gpa.svg)](https://codeclimate.com/github/eendroroy/dockerize_rails)
8
+ [![Contributors](https://img.shields.io/github/contributors/eendroroy/dockerize_rails.svg)](CONTRIBUTORS.md)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your rails application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'dockerize_rails'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ $ bundle exec dock help
27
+ $ bundle exec dock configure
28
+ $ bundle exec dock dockerize
29
+ $ bundle exec dock undockerize
30
+ $ bundle exec dock docker_info
31
+ ```
32
+
33
+ ## Demo
34
+
35
+ [![asciicast](https://asciinema.org/a/121552.png)](https://asciinema.org/a/121552)
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eendroroy/dockerize_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'dockerize_rails'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ default: &default
2
+ adapter: mysql2
3
+ host: localhost
4
+ encoding: utf8
5
+
6
+ development:
7
+ <<: *default
8
+ username: root
9
+ password: root
10
+ database: dockerize_rails_development
11
+
12
+ test:
13
+ <<: *default
14
+ username: root
15
+ password: root
16
+ database: dockerize_rails_test
17
+
18
+ staging:
19
+ <<: *default
20
+ username: root
21
+ password: root
22
+ database: dockerize_rails_staging
23
+
24
+ production:
25
+ <<: *default
26
+ username: root
27
+ password: root
28
+ database: dockerize_rails_production
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'dockerize_rails/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'dockerize_rails'
10
+ spec.version = DockerizeRails::VERSION
11
+
12
+ spec.authors = ['indrajit']
13
+ spec.email = ['eendroroy@gmail.com']
14
+
15
+ spec.summary = 'A docker util for rails application'
16
+ spec.description = 'A docker util for rails application'
17
+ spec.homepage = 'https://github.com/eendroroy/dockerize_rails'
18
+ spec.license = 'MIT'
19
+
20
+ spec.required_ruby_version = '>= 2.0.0'
21
+
22
+ unless spec.respond_to?(:metadata)
23
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
24
+ end
25
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'docker-api'
33
+ spec.add_dependency 'colorize'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.14'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ spec.add_development_dependency 'yard'
39
+ end
data/exe/dock ADDED
@@ -0,0 +1,3 @@
1
+ require 'dockerize_rails'
2
+
3
+ DockerizeRailsCLI.run
@@ -0,0 +1,7 @@
1
+ module DockerizeRails
2
+ module CommandLine
3
+ def run
4
+ exit(CommandLineMethods.invoke(Helpers.parse_opts))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ module DockerizeRails
2
+ module CommandLineMethods
3
+ require 'colorize'
4
+
5
+ # -rubocop:disable Metrics/MethodLength
6
+ def self.invoke(options)
7
+ commands = Helpers.processed_commands
8
+ case options[0]
9
+ when *(commands[:configure])
10
+ return configure options[1][:args]
11
+ when *(commands[:dockerize])
12
+ return dockerize
13
+ when *(commands[:undockerize])
14
+ return undockerize options[1][:args]
15
+ when *(commands[:docker_info])
16
+ return docker_info
17
+ when *(commands[:help])
18
+ return help
19
+ else
20
+ return help 1
21
+ end
22
+ end
23
+ # -rubocop:enable Metrics/MethodLength
24
+
25
+ def self.dockerize
26
+ Helpers.ensure_rails_root
27
+ DRNameSpace.load
28
+ ConfigGenerator.dockerize
29
+ end
30
+
31
+ def self.undockerize(args)
32
+ Helpers.ensure_rails_root
33
+ ConfigGenerator.undockerize args
34
+ end
35
+
36
+ def self.configure(args)
37
+ Helpers.ensure_rails_root
38
+ ConfigGenerator.configure args
39
+ end
40
+
41
+ def self.help(status = 0)
42
+ puts "\nCommand not found".red if status != 0
43
+ puts Helpers.help.white
44
+ status
45
+ end
46
+
47
+ def self.docker_info
48
+ docker_version = DockerHelper.version
49
+
50
+ puts
51
+ Helpers.print_formatted_info 'Docker Version', "#{docker_version['Version']}\n"
52
+ Helpers.print_formatted_info 'API', "#{docker_version['ApiVersion']} : #{docker_version['MinAPIVersion']}\n"
53
+ Helpers.print_formatted_info 'Git Commit', "#{docker_version['GitCommit']}\n"
54
+ Helpers.print_formatted_info 'Go Version', "#{docker_version['GoVersion']}\n"
55
+ # Helpers.print_formatted_info 'OS', "#{v['Os']}_#{v['Arch']}_#{v['KernelVersion']}\n"
56
+ Helpers.print_formatted_info 'Experimental', "#{docker_version['Experimental']}\n"
57
+ Helpers.print_formatted_info 'Build Time',
58
+ "#{DateTime.parse(docker_version['BuildTime']).strftime('%b %d, %Y %I:%M %p')}\n"
59
+ puts
60
+ 0
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,135 @@
1
+ module DockerizeRails
2
+ module ConfigGenerator
3
+ def self.configure(args)
4
+ puts "\nGenerating DockerizeRails config file ...\n".yellow
5
+ puts " ==> #{Constants::DOCKERIZE_RAILS_CONFIG_FILE_NAME}".blue
6
+ file = File.open(File.join(PATHS.current, Constants::DOCKERIZE_RAILS_CONFIG_FILE_NAME), 'w+')
7
+ if args.include?('--skip-desc')
8
+ file.write(DRConfig.to_yaml)
9
+ else
10
+ file.write(DRConfig.to_yaml_str)
11
+ end
12
+ file.close
13
+ puts
14
+ 0
15
+ end
16
+
17
+ def self.dockerize
18
+ status = 0
19
+ puts "\nGenerating config files ...\n".yellow
20
+ status += create_config_directories
21
+ status += create_config_files
22
+ puts "\nDon't forget to update "\
23
+ "\"#{Constants::CONFIG_DIRECTORY_NAME}/#{Constants::RAILS_DIRECTORY_NAME}/secrtes.yml\"".yellow.underline
24
+ puts
25
+ set_executables
26
+ status
27
+ end
28
+
29
+ def self.undockerize(args)
30
+ status = 0
31
+ puts "\nRemoving docker config files ...\n".yellow
32
+ status += remove_config_directories
33
+ dir_op(Constants::DOCKERIZE_RAILS_CONFIG_FILE_NAME, 'rm_rf') if args.include?('--purge')
34
+ status
35
+ end
36
+
37
+ def self.dir_op(dir, method)
38
+ FileUtils.send(method, File.join(PATHS.current, dir))
39
+ end
40
+
41
+ def self.remove_config_directories
42
+ dir_op(Constants::CONFIG_DIRECTORY_NAME, 'rm_rf')
43
+ Templates::ROOT_TEMPLATES.each { |conf| dir_op(conf, 'rm_rf') }
44
+ 0
45
+ end
46
+
47
+ def self.create_config_directories
48
+ db_values = DRConfig.databases.values
49
+ dirs = Templates::ROOT_DIRECTORIES + Templates::RAILS_DIRECTORIES
50
+ if DRConfig.linked_database?
51
+ dirs += Templates::MYSQL_DIRECTORIES if db_values.include? 'mysql'
52
+ dirs += Templates::PG_DIRECTORIES if db_values.include? 'postgresql'
53
+ end
54
+ dirs.each { |dir| dir_op(dir, 'mkdir_p') }
55
+ 0
56
+ end
57
+
58
+ def self.create_custom_database_config
59
+ puts " ==> #{PATHS.relative_from_current(File.join(PATHS.rails_directory, 'database.yml'))}".blue
60
+ file = File.open(File.join(PATHS.config_directory, Constants::RAILS_DIRECTORY_NAME, 'database.yml'), 'w+')
61
+ file.write(ConfigLoader.app_config.to_yaml)
62
+ file.close
63
+ 0
64
+ end
65
+
66
+ def self.create_rails_configs
67
+ status = 0
68
+ status += write_config PATHS.rails_directory, Templates::RAILS_TEMPLATES, 'rails'
69
+ status += create_custom_database_config
70
+ status
71
+ end
72
+
73
+ def self.create_mysql_configs
74
+ write_config PATHS.mysql_directory, Templates::MYSQL_TEMPLATES, 'mysql'
75
+ end
76
+
77
+ def self.create_postgresql_configs
78
+ write_config PATHS.postgresql_directory, Templates::POSTGRES_TEMPLATES, 'postgresql'
79
+ end
80
+
81
+ def self.create_root_configs
82
+ write_config PATHS.current, Templates::ROOT_TEMPLATES
83
+ end
84
+
85
+ def self.create_config_files
86
+ db_values = DRConfig.databases.values
87
+ status = 0
88
+ status += create_rails_configs
89
+ if DRConfig.linked_database?
90
+ status += create_mysql_configs if db_values.include? 'mysql'
91
+ status += create_postgresql_configs if db_values.include? 'postgresql'
92
+ end
93
+ status += create_root_configs
94
+ status
95
+ end
96
+
97
+ def self.write_config(dir, config_names, resource_name = '')
98
+ config_names.each do |conf|
99
+ conf_path = File.join(dir, conf)
100
+ puts " ==> #{PATHS.relative_from_current(conf_path)}".blue
101
+ file = File.open(conf_path, 'w+')
102
+ file.write(
103
+ StringIO.new(
104
+ ERB.new(File.read(File.join(
105
+ PATHS.resources(resource_name),
106
+ "#{conf}.erb"
107
+ ))).result(DRNameSpace.eval_i)
108
+ ).read.gsub!(/\s*\n+/, "\n")
109
+ )
110
+ file.close
111
+ end
112
+ 0
113
+ end
114
+
115
+ def self.set_executables
116
+ Templates::EXECUTABLES.each do |exe|
117
+ File.chmod(0o775, File.join(PATHS.current, exe))
118
+ end
119
+ end
120
+
121
+ class << self
122
+ private :dir_op
123
+ private :remove_config_directories
124
+ private :create_config_directories
125
+ private :create_custom_database_config
126
+ private :create_rails_configs
127
+ private :create_mysql_configs
128
+ private :create_postgresql_configs
129
+ private :create_root_configs
130
+ private :create_config_files
131
+ private :write_config
132
+ private :set_executables
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,32 @@
1
+ module DockerizeRails
2
+ module ConfigLoader
3
+ require 'yaml'
4
+
5
+ @app_config = false
6
+
7
+ def self.app_config
8
+ unless @app_config
9
+ @app_config = YAML.load_file(File.join(PATHS.current, 'config/database.yml'))
10
+ process_app_config
11
+ end
12
+ @app_config
13
+ end
14
+
15
+ def self.process_app_config
16
+ @app_config.delete 'default'
17
+ @app_config.keys.each do |section|
18
+ current_section = @app_config[section]
19
+ current_section['username'] = DRConfig.database_user_name
20
+ current_section['password'] = DRConfig.database_user_pass
21
+ current_section['database'] = "#{DRConfig.application_name}_#{section}" \
22
+ if DRConfig.database_host_type == Constants::DATABASE_HOST_LINKED
23
+ current_section['host'] = DRConfig.database_host_name
24
+ @app_config[section] = current_section
25
+ end
26
+ end
27
+
28
+ class << self
29
+ private :process_app_config
30
+ end
31
+ end
32
+ end