dockrails 1.0.1 → 1.0.2

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
  SHA1:
3
- metadata.gz: 2af14517691bd7a4bb6d4cb322caa32b4ed44dc9
4
- data.tar.gz: 72a9899888365436771a9955e553dd75d891d3d1
3
+ metadata.gz: adbe324970fc15fb50b9b9ad644592992c9f1241
4
+ data.tar.gz: 0776a2436119808d5471b06910d3535c16889847
5
5
  SHA512:
6
- metadata.gz: f44e3310ba8fe63da42015b91262b29f6ce36aa89e1e66b9b9110af6199949ae5a76097e2e068dc73f20c5e5e176bef51459cfd3b0566d6a1c2ebfe2229bbb5f
7
- data.tar.gz: 1f0d80977feb513ca7fd5c4d54915fc46ea0f27b238f2c490bc6bd1323ffd6ad207125409aabe2aeb082b7fdf10f16521b340f0fdfa4c3e61b9815d60f1341a4
6
+ metadata.gz: da05bbe63ab3882df34d3b5663268e4c72a907c16c2ecd82bffa4c06167ccb50410bcb420dc7b4a1410291cfae11b178243e671c00fd26bdef999060a04121ff
7
+ data.tar.gz: 75d4f9effa54dd0010f5743dad3ccb700198d9227f6b216d338f44c4373932a84be887e84e359567811d4a4962aaa9e4e1d2928312c784d0e2fe37c6d54c2f7e
data/bin/dockrails CHANGED
@@ -18,7 +18,7 @@ command :init do |c|
18
18
  existing_files = ["Dockerfile", "docker-compose.yml", "docker-sync.yml"].map { |file| File.exist?(file) }
19
19
  if existing_files.include?(true)
20
20
  say "We detected an existing Docker install in this folder"
21
- answer = agree "Do you want to continue and override it?"
21
+ answer = agree "Do you want to continue and override it? (yes|no)"
22
22
  exit if !answer
23
23
  end
24
24
 
@@ -30,6 +30,15 @@ command :init do |c|
30
30
  end
31
31
 
32
32
  generate = Dockrails::Generate.new(app_path: rails_app)
33
+
34
+ (generate.check_system_requirements).each do |k,v|
35
+ if v == false
36
+ say "please install \"#{k}\" in order to continue\n"
37
+ exit
38
+ end
39
+ end
40
+
41
+ generate.configure
33
42
  generate.create_folders
34
43
  generate.create_dockerfile
35
44
  generate.create_start_script
@@ -1,62 +1,60 @@
1
1
  module Dockrails
2
2
  class Generate
3
3
 
4
- def initialize(app_path:)
5
- check_system_requirements
4
+ def initialize(app_path:, config: {})
6
5
  @app_path = app_path
7
- @config = ask_configuration
6
+ @config = config
8
7
  end
9
8
 
10
9
  def check_system_requirements
11
10
  requirement = Hash.new
12
- requirement["unison"] = system("which unison > /dev/null")
13
- requirement["docker"] = system("which docker > /dev/null")
14
- requirement["docker-sync"] = system("which docker-sync > /dev/null")
15
- requirement["docker-compose"] = system("which docker-compose > /dev/null")
16
-
17
- requirement.each do |k,v|
18
- if v == false
19
- say "please install \"#{k}\" in order to continue\n"
20
- end
11
+
12
+ ["unison", "docker", "docker-sync", "docker-compose"].each do |binary|
13
+ requirement[binary] = binary_present?(binary: binary)
21
14
  end
15
+
16
+ return requirement
17
+ end
18
+
19
+ def binary_present?(binary:)
20
+ system("which #{binary} > /dev/null")
22
21
  end
23
22
 
24
- def ask_configuration
25
- config = Hash.new
26
- config["ruby-version"] = choose("\nChoose a ruby version?", "latest", "2.4", "2.3", "2.2")
27
- config["db"] = choose("\nChoose a DB Engine?", :pgsql, :mysql)
28
- config["db_name"] = ask "\nChoose a database name"
29
- config["db_user"] = ask "\nChoose a database username"
30
- config["db_password"] = ask "\nChoose a database password"
31
- config["redis"] = agree("\nDo you need a Redis DB?")
32
- config["sidekiq"] = agree("\nDo you need a SideKiq Container") if config["redis"]
23
+ def configure
24
+ @config[:"ruby-version"] = choose("\nChoose a ruby version?", "latest", "2.4", "2.3", "2.2")
25
+ @config[:db] = choose("\nChoose a DB Engine", :pgsql, :mysql)
26
+ @config[:db_name] = ask "\nChoose a database name"
27
+ @config[:db_user] = ask "\nChoose a database username"
28
+ @config[:db_password] = ask "\nChoose a database password"
29
+ @config[:redis] = agree("\nDo you need a Redis DB? (yes|no)")
30
+ @config[:sidekiq] = agree("\nDo you need a SideKiq Container? (yes|no)") if @config[:redis]
33
31
 
34
32
  user_agree = agree "\nSummary:
35
- - Ruby version: #{config["ruby-version"]}
36
- - DB Engine: #{config["db"]}
37
- - DB Name: #{config["db_name"]}
38
- - DB Username: #{config["db_user"]}
39
- - DB Password: #{config["db_password"]}
40
- - Redis? #{config["redis"]}
41
- - Job Container? #{config["sidekiq"] ||= "false"}\n
42
- Is this correct?"
33
+ - Ruby version: #{@config[:"ruby-version"]}
34
+ - DB Engine: #{@config[:db]}
35
+ - DB Name: #{@config[:db_name]}
36
+ - DB Username: #{@config[:db_user]}
37
+ - DB Password: #{@config[:db_password]}
38
+ - Redis? #{@config[:redis]}
39
+ - Job Container? #{@config[:sidekiq] ||= false}\n
40
+ Is this correct? (yes|no)"
43
41
 
44
42
  unless user_agree
45
- ask_configuration
43
+ configure
46
44
  end
47
45
 
48
- return(config)
46
+ return(@config)
49
47
  end
50
48
 
51
49
  def create_folders
52
- system("rm -rf data")
53
- system("mkdir -p data/sql")
54
- system("mkdir -p data/redis") if @config["redis"]
50
+ FileUtils.rm_rf('data')
51
+ FileUtils.mkdir_p('data/sql')
52
+ FileUtils.mkdir_p('data/redis') if @config[:redis]
55
53
  end
56
54
 
57
55
  def create_dockerfile
58
56
  File.open("Dockerfile", 'w') do |f|
59
- f.write("FROM ruby:#{@config["ruby-version"]}
57
+ f.write("FROM ruby:#{@config[:"ruby-version"]}
60
58
  RUN apt-get update && apt-get install -y \
61
59
  build-essential \
62
60
  wget \
@@ -88,7 +86,7 @@ module Dockrails
88
86
  end
89
87
 
90
88
  def create_start_script
91
- system("mkdir -p #{@app_path}/scripts")
89
+ FileUtils.mkdir_p("#{@app_path}/scripts")
92
90
  File.open("#{@app_path}/scripts/start-dev.sh", "w") do |f|
93
91
  f.write("#!/bin/bash
94
92
  bundle check || bundle install
@@ -102,17 +100,17 @@ module Dockrails
102
100
  f.write "services:\n"
103
101
  f.write " db:\n"
104
102
 
105
- case @config["db"] when :mysql
103
+ case @config[:db] when :mysql
106
104
  f.write " image: mysql\n"
107
105
  f.write " volumes:\n"
108
106
  f.write " - ./data/sql:/var/lib/mysql\n"
109
107
  f.write " ports:\n"
110
108
  f.write " - \"3306:3306\"\n"
111
109
  f.write " environment:\n"
112
- f.write " MYSQL_DATABASE: #{@config["db_name"]}\n"
113
- f.write " MYSQL_USER: #{@config["db_user"]}\n"
114
- f.write " MYSQL_PASSWORD: #{@config["db_password"]}\n"
115
- f.write " MYSQL_ROOT_PASSWORD: #{@config["db_password"]}\n"
110
+ f.write " MYSQL_DATABASE: #{@config[:db_name]}\n"
111
+ f.write " MYSQL_USER: #{@config[:db_user]}\n"
112
+ f.write " MYSQL_PASSWORD: #{@config[:db_password]}\n"
113
+ f.write " MYSQL_ROOT_PASSWORD: #{@config[:db_password]}\n"
116
114
  when :pgsql
117
115
  f.write " image: postgres\n"
118
116
  f.write " volumes:\n"
@@ -120,12 +118,12 @@ module Dockrails
120
118
  f.write " ports:\n"
121
119
  f.write " - \"5432:5432\"\n"
122
120
  f.write " environment:\n"
123
- f.write " POSTGRES_DB: #{@config["db_name"]}\n"
124
- f.write " POSTGRES_USER: #{@config["db_user"]}\n"
125
- f.write " POSTGRES_PASSWORD: #{@config["db_password"]}\n"
121
+ f.write " POSTGRES_DB: #{@config[:db_name]}\n"
122
+ f.write " POSTGRES_USER: #{@config[:db_user]}\n"
123
+ f.write " POSTGRES_PASSWORD: #{@config[:db_password]}\n"
126
124
  end
127
125
 
128
- if @config["redis"]
126
+ if @config[:redis]
129
127
  f.write "\n redis:\n"
130
128
  f.write " image: redis\n"
131
129
  f.write " volumes:\n"
@@ -144,16 +142,16 @@ module Dockrails
144
142
  f.write " ports:\n"
145
143
  f.write " - \"3000:3000\"\n"
146
144
  f.write " environment:\n"
147
- f.write " REDIS_URL: redis://redis:6379\n" if @config["redis"]
148
- f.write " DB_USER: #{@config["db_user"]}\n"
149
- f.write " DB_PASSWORD: #{@config["db_password"]}\n"
145
+ f.write " REDIS_URL: redis://redis:6379\n" if @config[:redis]
146
+ f.write " DB_USER: #{@config[:db_user]}\n"
147
+ f.write " DB_PASSWORD: #{@config[:db_password]}\n"
150
148
  f.write " links:\n"
151
149
  f.write " - db\n"
152
- f.write " - redis\n" if @config["redis"]
150
+ f.write " - redis\n" if @config[:redis]
153
151
  f.write " tty: true\n"
154
152
  f.write " stdin_open: true\n"
155
153
 
156
- if @config["redis"] && @config["sidekiq"]
154
+ if @config[:redis] && @config[:sidekiq]
157
155
  f.write "\n job:\n"
158
156
  f.write " build: .\n"
159
157
  f.write " command: bundle exec sidekiq -C config/sidekiq.yml\n"
@@ -1,3 +1,3 @@
1
1
  module Dockrails
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+ require 'dockrails/generate'
3
+
4
+
5
+ class Dummy
6
+ def command_line
7
+ system("ls")
8
+ end
9
+ end
10
+
11
+ describe Dockrails::Generate do
12
+
13
+ before(:all) do
14
+ #$stderr = StringIO.new
15
+ #mock_terminal
16
+
17
+ @app_path = "rails_app"
18
+ @generate = Dockrails::Generate.new(app_path: @app_path)
19
+ end
20
+
21
+ describe ".check_system_requirements" do
22
+ it "should test for Unison, docker, docker-compose and docker-sync binaries" do
23
+ values = @generate.check_system_requirements.map{|k,v| k}
24
+ expect(values).to eql ["unison", "docker", "docker-sync", "docker-compose"]
25
+ end
26
+
27
+ context "when all requirements are met" do
28
+ it {
29
+ allow(@generate).to receive(:binary_present?).with(binary: "unison") { true }
30
+ allow(@generate).to receive(:binary_present?).with(binary: "docker") { true }
31
+ allow(@generate).to receive(:binary_present?).with(binary: "docker-sync") { true }
32
+ allow(@generate).to receive(:binary_present?).with(binary: "docker-compose") { true }
33
+
34
+ expect(@generate.check_system_requirements).to be_kind_of Hash
35
+ }
36
+ end
37
+
38
+ context "when NOT all requirements are met" do
39
+ it {
40
+ allow(@generate).to receive(:binary_present?).with(binary: "unison") { false }
41
+ allow(@generate).to receive(:binary_present?).with(binary: "docker") { true }
42
+ allow(@generate).to receive(:binary_present?).with(binary: "docker-sync") { true }
43
+ allow(@generate).to receive(:binary_present?).with(binary: "docker-compose") { true }
44
+
45
+ expect(@generate.check_system_requirements).to be_kind_of Hash
46
+ }
47
+ end
48
+ end
49
+
50
+ describe ".configure" do
51
+ end
52
+
53
+ context "once it's configured" do
54
+
55
+ before(:all) do
56
+ @app_path = "rails_app"
57
+
58
+ @config_with_redis = {
59
+ "ruby-version": "latest",
60
+ db: :pgsql,
61
+ db_name: "rails",
62
+ db_user: "rails",
63
+ db_password: "rails",
64
+ redis: true,
65
+ sidekiq: true
66
+ }
67
+
68
+ @config_without_redis = {
69
+ "ruby-version": "latest",
70
+ db: :pgsql,
71
+ db_name: "rails",
72
+ db_user: "rails",
73
+ db_password: "rails",
74
+ redis: false,
75
+ sidekiq: false
76
+ }
77
+
78
+ @config_with_mysql = {
79
+ "ruby-version": "latest",
80
+ db: :mysql,
81
+ db_name: "rails",
82
+ db_user: "rails",
83
+ db_password: "rails",
84
+ redis: false,
85
+ sidekiq: false
86
+ }
87
+
88
+ @generate_with_redis = Dockrails::Generate.new(app_path: @app_path, config: @config_with_redis)
89
+ @generate_without_redis = Dockrails::Generate.new(app_path: @app_path, config: @config_without_redis)
90
+ @generate_with_mysql = Dockrails::Generate.new(app_path: @app_path, config: @config_with_mysql)
91
+ end
92
+
93
+ describe ".create_folders" do
94
+ context "When Redis is not set" do
95
+ it "should create the data and data/sql folders" do
96
+ allow(FileUtils).to receive(:mkdir_p).with("data")
97
+ allow(FileUtils).to receive(:mkdir_p).with("data/sql")
98
+ @generate_without_redis.create_folders
99
+ end
100
+ end
101
+
102
+ context "When Redis is set" do
103
+ it "should create the data, data/sql and data/redis folders" do
104
+ allow(FileUtils).to receive(:mkdir_p).with("data")
105
+ allow(FileUtils).to receive(:mkdir_p).with("data/sql")
106
+ allow(FileUtils).to receive(:mkdir_p).with("data/redis")
107
+ @generate_with_redis.create_folders
108
+ end
109
+ end
110
+ end
111
+
112
+ describe ".create_dockerfile" do
113
+ it "Should create a Dockerfile" do
114
+ allow(File).to receive(:open).with("Dockerfile", 'w').once
115
+ @generate_with_redis.create_dockerfile
116
+ end
117
+ end
118
+
119
+ describe ".create_docker_compose" do
120
+ it "Should create a docker-compose.yml file" do
121
+ allow(File).to receive(:open).with("docker-compose.yml", 'w').once
122
+ @generate_with_redis.create_docker_compose
123
+ end
124
+
125
+ context "When PGSQL is set" do
126
+ it "Should contain the Pgsql config" do
127
+ @generate_with_redis.create_docker_compose
128
+ expect(File.read("docker-compose.yml")).to match /postgres/i
129
+ end
130
+ end
131
+
132
+ context "When MySQL is set" do
133
+ it "Should contain the Mysql config" do
134
+ @generate_with_mysql.create_docker_compose
135
+ expect(File.read("docker-compose.yml")).to match /mysql/i
136
+ end
137
+ end
138
+
139
+ context "When Redis is not set" do
140
+ it "Should not contain a Redis node" do
141
+ @generate_without_redis.create_docker_compose
142
+ expect(File.read("docker-compose.yml")).not_to match /redis/i
143
+ end
144
+
145
+ it "Should not contain a Sidekiq node" do
146
+ @generate_without_redis.create_docker_compose
147
+ expect(File.read("docker-compose.yml")).not_to match /sidekiq/i
148
+ end
149
+ end
150
+
151
+ context "When Redis & Sidekiq are set" do
152
+ it "Should contain a Redis node" do
153
+ @generate_with_redis.create_docker_compose
154
+ expect(File.read("docker-compose.yml")).to match /redis/i
155
+ end
156
+
157
+ it "Should contain a Sidekiq node" do
158
+ @generate_with_redis.create_docker_compose
159
+ expect(File.read("docker-compose.yml")).to match /sidekiq/i
160
+ end
161
+ end
162
+ end
163
+
164
+ describe ".create_docker_sync" do
165
+ it "Should create a docker-sync.yml file" do
166
+ allow(File).to receive(:open).with("docker-sync.yml", 'w').once
167
+ @generate_with_redis.create_docker_sync
168
+ end
169
+ end
170
+
171
+ describe ".create_start_script" do
172
+ it "Should create a scripts folder and start-dev.sh file" do
173
+ allow(File).to receive(:open).with("#{@app_path}/scripts/start-dev.sh", 'w').once
174
+ allow(FileUtils).to receive(:mkdir_p).with("#{@app_path}/scripts").once
175
+ @generate_with_redis.create_start_script
176
+ end
177
+ end
178
+ end
179
+
180
+ end
@@ -0,0 +1,20 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'commander'
5
+ require 'commander/methods'
6
+ require 'pry'
7
+ require 'fakefs/spec_helpers'
8
+
9
+ # Mock terminal IO streams so we can spec against them
10
+ def mock_terminal
11
+ @input = StringIO.new
12
+ @output = StringIO.new
13
+ $terminal = HighLine.new @input, @output
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Montard
@@ -38,6 +38,76 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
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: fakefs
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
41
111
  description: Docker + Rails + Mac + Dev = <3
42
112
  email:
43
113
  executables:
@@ -50,6 +120,8 @@ files:
50
120
  - lib/dockrails.rb
51
121
  - lib/dockrails/generate.rb
52
122
  - lib/dockrails/version.rb
123
+ - spec/generate_spec.rb
124
+ - spec/spec_helper.rb
53
125
  homepage: https://github.com/gmontard/dockrails/
54
126
  licenses:
55
127
  - MIT
@@ -74,4 +146,6 @@ rubygems_version: 2.5.2
74
146
  signing_key:
75
147
  specification_version: 4
76
148
  summary: Simple CLI to Generate and Run a Rails environment with Docker!
77
- test_files: []
149
+ test_files:
150
+ - spec/generate_spec.rb
151
+ - spec/spec_helper.rb