docora 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1269e0bb8da4a4be3e0dbc27a30c8e29f3899021
4
+ data.tar.gz: 0b1bbbdfee2036a546e8f33eb4f7093c2566c052
5
+ SHA512:
6
+ metadata.gz: ec13312a2e01f2ee2986d32ce593703164cbc2cb9545278f4fd404e1b8024f9c43ff5fd6385457760319e2f513f5b14edf80f5308f0ed1ddfcd3b161e65cae2b
7
+ data.tar.gz: cc4d281c795c34e56ae9e364a17bbe44eea2c907d9f49a4c1a800d2c33c92fa98dd19e0aee01bd0fa4b05846bcf16be13e7a5bcacd1a56d1b2611d673c2ac56b
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
12
+ .bundle
13
+ Gemfile.lock
14
+ pkg/*
15
+ sandbox
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docora.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dakota Lightning
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,41 @@
1
+ # Docora
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/docora`. 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
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'docora'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install docora
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/docora.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/docora ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Abort beautifully with ctrl+c.
4
+ Signal.trap(:INT) { abort "\nAborting." }
5
+
6
+ # Load the main lib and invoke CLI.
7
+ require 'docora'
8
+ Docora::Cli.start
data/docora.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docora/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "docora"
8
+ spec.version = Docora::VERSION
9
+ spec.authors = ["Dakota Lightning"]
10
+ spec.email = ["im@koda.io"]
11
+
12
+ spec.summary = %q{Run your rails app in docker using docker compose}
13
+ spec.description = %q{The intention is use this to dockerify your rails project for use anywhere in development.}
14
+ spec.homepage = "http://github.com/dakotalightning/docora"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = '>= 2.0.0'
23
+
24
+ spec.add_runtime_dependency 'thor', '~> 0.19'
25
+ spec.add_runtime_dependency 'rainbow', '~> 2.0'
26
+ spec.add_runtime_dependency 'highline', '~> 1.7'
27
+ spec.add_development_dependency 'rake', '~> 10.5'
28
+ spec.add_development_dependency 'rspec', '~> 5.8'
29
+ end
data/lib/docora/cli.rb ADDED
@@ -0,0 +1,238 @@
1
+ require 'open3'
2
+ require 'ostruct'
3
+ require 'highline'
4
+ require 'json'
5
+
6
+ module Docora
7
+ class Cli < Thor
8
+ include Thor::Actions
9
+
10
+ desc 'setup', 'dockerify your project'
11
+ def setup(project = 'docker')
12
+ do_setup(project)
13
+ end
14
+
15
+ desc 'up', 'start docker compose'
16
+ def up(project = 'docker')
17
+ do_up(project)
18
+ end
19
+
20
+ desc 'clean', 'clean you docker images and volumes'
21
+ def clean(project = 'docker')
22
+ do_clean(project)
23
+ end
24
+
25
+ desc 'version', 'Show version'
26
+ def version
27
+ puts Gem.loaded_specs['docora'].version.to_s
28
+ end
29
+
30
+ no_tasks do
31
+ include Docora::Utility
32
+
33
+ def self.source_root
34
+ File.expand_path('../../',__FILE__)
35
+ end
36
+
37
+ def do_up(project)
38
+ @ui = HighLine.new
39
+ @project = project
40
+
41
+ answer = ask("Do you want to clean? (y/n) ", ["y","n"])
42
+ if answer == "y"
43
+ do_clean(project)
44
+ end
45
+
46
+ docker_running?
47
+ abort_with "run docora create" unless File.exists?('docker-compose.yml')
48
+
49
+ say @ui.color("Starting containers", :green, :bold)
50
+ run("docker-compose up -d", verbose: false)
51
+
52
+ say @ui.color("--> booting containers ...", :green, :bold)
53
+
54
+ say @ui.color("done", :green, :bold)
55
+ run("docker-compose ps", verbose: false)
56
+ end
57
+
58
+ def do_clean(project)
59
+ @ui = HighLine.new
60
+ @project = project
61
+
62
+ docker_running?
63
+
64
+ images = run('docker images -qf dangling=true', capture: true, verbose: false)
65
+ volumes = run('docker volume ls -qf dangling=true', capture: true, verbose: false)
66
+
67
+ if images.empty?
68
+ say @ui.color("no images", :green, :bold)
69
+ else
70
+ say "cleaning images"
71
+ say @ui.color("--> cleaning images", :blue, :bold)
72
+ run(`docker rmi -f #{images}`, verbose: false)
73
+ end
74
+
75
+ if volumes.empty?
76
+ say @ui.color("no volumes", :green, :bold)
77
+ else
78
+ say @ui.color("--> cleaning volumes", :blue, :bold)
79
+ run(`docker volume rm #{volumes}`, verbose: false)
80
+ end
81
+
82
+ say @ui.color("Done", :green, :bold)
83
+ end
84
+
85
+ def do_setup(project)
86
+ @ui = HighLine.new
87
+ @project = project
88
+
89
+ docker_running?
90
+
91
+ allowed_ruby_versions = [
92
+ "2",
93
+ "2.0.0",
94
+ "2.1",
95
+ "2.1.10",
96
+ "2.1.6",
97
+ "2.1.8",
98
+ "2.2.6",
99
+ "2.3",
100
+ "2.3.0",
101
+ "2.3.1",
102
+ "2.3.2",
103
+ "2.3.3",
104
+ "2.3.4",
105
+ "2.4",
106
+ "2.4.1"
107
+ ]
108
+
109
+ if File.exists?('.ruby-version')
110
+ ruby_version = File.read('.ruby-version').strip
111
+ elsif File.exists?('Gemfile')
112
+ ruby_version = File.read('Gemfile').split("\n").first.gsub("ruby", "").strip.gsub("'", "")
113
+ # else
114
+ # ruby_version = ask_menu("What ruby version?", ["2.0.0", "2.1.6", "2.2.6", "2.3.3", "2.4.0"])
115
+ end
116
+
117
+ abort_with "Unsupported Ruby version, allowed ruby versions: #{allowed_ruby_versions.join(", ")}" unless allowed_ruby_versions.include?(ruby_version)
118
+
119
+ if File.exists?('.env')
120
+ append_to_file ".env", "JOB_WORKER_URL=redis://redis:6379/0"
121
+ else
122
+ create_file ".env", "JOB_WORKER_URL=redis://redis:6379/0"
123
+ end
124
+
125
+ dockerfile = "FROM ruby:#{ruby_version}\n"
126
+ dockerfile += "RUN apt-get update && apt-get install -qq -y --no-install-recommends build-essential nodejs libpq-dev libqt4-dev libqtwebkit-dev\n"
127
+ dockerfile += "ENV INSTALL_PATH /var/rails_app\n"
128
+ dockerfile += "RUN mkdir -p $INSTALL_PATH\n"
129
+ dockerfile += "WORKDIR $INSTALL_PATH\n"
130
+ dockerfile += "COPY Gemfile Gemfile.lock ./\n"
131
+ dockerfile += "RUN bundle install\n"
132
+
133
+ dockerignore = ".git\n"
134
+ dockerignore += ".dockerignore\n"
135
+ dockerignore += ".byebug_history\n"
136
+ dockerignore += "/log/*\n"
137
+ dockerignore += "/tmp/*\n"
138
+ dockerignore += "#{project}/\n"
139
+ dockerignore += "/#{project}/*\n"
140
+
141
+ create_file "Dockerfile", dockerfile
142
+ create_file ".dockerignore", dockerignore
143
+ create_file "docker-compose.yml", YAML.dump(docker_compose)
144
+
145
+ answer = ask("Want to run rake db:setup? (y/n) ", ["y","n"])
146
+ if answer == "y"
147
+ do_up(project)
148
+ run("docker-compose exec web rake db:setup", verbose: false)
149
+ end
150
+ end
151
+
152
+ def docker_compose
153
+ compose = {}
154
+ compose["version"] = '2'
155
+ services = {}
156
+ db = ask_menu("What database?", ["postgres", "mysql"])
157
+ if db == "mysql"
158
+ services["mysql"] = {
159
+ image: 'mysql:5.7.17',
160
+ ports: ["13306:3306"],
161
+ environment: {
162
+ MYSQL_ROOT_PASSWORD: 'root',
163
+ MYSQL_DATABASE: 'root'
164
+ },
165
+ volumes: ["./#{@project}/data/mysql:/var/lib/mysql"]
166
+ }
167
+ elsif db == "postgres"
168
+ services["postgres"] = {
169
+ image: 'postgres:9.5',
170
+ ports: ["5432:5432"],
171
+ environment: {
172
+ POSTGRES_USER: 'root',
173
+ POSTGRES_PASSWORD: 'root'
174
+ },
175
+ volumes: ["./#{@project}/data/postgres:/var/lib/postgresql/data"]
176
+ }
177
+ end
178
+
179
+ redis = ask("Are you using redis? (y/n) ", ["y","n"])
180
+ if redis == "y"
181
+ services["redis"] = {
182
+ image: 'redis:3.0.7-alpine',
183
+ ports: ["6379:6379"],
184
+ volumes: ["./#{@project}/data/redis:/data"]
185
+ }
186
+ end
187
+
188
+ depends_on = []
189
+ if redis == "y"
190
+ depends_on.push('redis')
191
+ end
192
+ depends_on.push(db)
193
+
194
+ sidekiq = ask("Are you using sidekiq? (y/n) ", ["y","n"])
195
+ if sidekiq == "y"
196
+ services["sidekiq"] = {
197
+ build: '.',
198
+ command: 'bash -c "bundle exec sidekiq -C config/sidekiq.yml"',
199
+ env_file: ['.env'],
200
+ volumes: ['.:/var/rails_app'],
201
+ depends_on: depends_on
202
+ }
203
+ end
204
+
205
+ services["web"] = {
206
+ build: '.',
207
+ ports: ['3000:3000'],
208
+ command: 'bash -c "bundle exec rails s -b 0.0.0.0"',
209
+ env_file: ['.env'],
210
+ volumes: ['.:/var/rails_app'],
211
+ depends_on: depends_on
212
+ }
213
+
214
+ compose["services"] = services
215
+ JSON.parse(compose.to_json)
216
+ end
217
+
218
+ def docker_running?
219
+ version = run('docker version', capture: true, verbose: false)
220
+ docker_version = YAML.load(version)
221
+ abort_with "Please make sure docker is running" unless docker_version["Client"]
222
+ end
223
+
224
+ def ask(question, answer_type, &details)
225
+ @ui.ask(@ui.color(question, :green, :bold), answer_type, &details)
226
+ end
227
+
228
+ def ask_menu(question, choices)
229
+ @ui.choose do |menu|
230
+ menu.prompt = "#{@ui.color(question, :green, :bold)} "
231
+ choices.each { |n| menu.choice(n) }
232
+ end
233
+ end
234
+
235
+ end
236
+
237
+ end
238
+ end
@@ -0,0 +1,17 @@
1
+ module Docora
2
+ module Logger
3
+ class << self
4
+ def info(text)
5
+ puts text.bright
6
+ end
7
+
8
+ def success(text)
9
+ puts text.color(:green).bright
10
+ end
11
+
12
+ def error(text)
13
+ puts text.color(:red).bright
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Docora
2
+ module Utility
3
+ def abort_with(text)
4
+ Logger.error text
5
+ abort
6
+ end
7
+
8
+ def exit_with(text)
9
+ Logger.success text
10
+ exit
11
+ end
12
+
13
+ def say(text)
14
+ Logger.info text
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Docora
2
+ VERSION = "0.1.0"
3
+ end
data/lib/docora.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+ require 'rainbow'
3
+ require 'yaml'
4
+ require 'highline'
5
+
6
+ require "docora/version"
7
+
8
+ # Starting 2.0.0, Rainbow no longer patches string with the color method by default.
9
+ require 'rainbow/version'
10
+ require 'rainbow/ext/string' unless Rainbow::VERSION < '2.0.0'
11
+
12
+ module Docora
13
+ autoload :Cli, 'docora/cli'
14
+ autoload :Logger, 'docora/logger'
15
+ autoload :Utility, 'docora/utility'
16
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docora
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dakota Lightning
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.8'
83
+ description: The intention is use this to dockerify your rails project for use anywhere
84
+ in development.
85
+ email:
86
+ - im@koda.io
87
+ executables:
88
+ - docora
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/docora
99
+ - docora.gemspec
100
+ - lib/docora.rb
101
+ - lib/docora/cli.rb
102
+ - lib/docora/logger.rb
103
+ - lib/docora/utility.rb
104
+ - lib/docora/version.rb
105
+ homepage: http://github.com/dakotalightning/docora
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.0.0
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Run your rails app in docker using docker compose
129
+ test_files: []