dockerfile-rails 0.0.2 → 0.1.0

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: 8e00977164abc39c9b3b66c636834cda09f32f939045db5a5f496b51a455ee4f
4
- data.tar.gz: bc3305fa419473f18eace29a65a9461fbd90c423106ff3cf1c5c42d0ed3b58ba
3
+ metadata.gz: 536685e13e342227e5d6af85e3d778539668bbdab81b5430902ae08286a57c62
4
+ data.tar.gz: a3155769a131089493ae0682e195f6108dd4c81d03c79c6774ce21af0eda04be
5
5
  SHA512:
6
- metadata.gz: d92c231f9d0484dcc196837aab9a3f3c3b6158202d5c8d942a61231ec9d5ec3fa0af8cf54a8daffea5d6f1103241aa5bb88a79cb9ea0a29974a08b579f7b2356
7
- data.tar.gz: 1e65aec6411ddac4d9785f087f16c2b8645e0895701fe6da58d93369d45d2aa8b71c4cb48c777e64737cf805a08ca4fc4da66a44d0ab007fa36f2351065ffc95
6
+ metadata.gz: 0547a5c9224213fdab9b99a2ca03e5aa411f086abb723b121561226079968e6da769f9acdf76ee123b1fbd57a64aa7d622c5dc44a48ab05717d9a523322955a1
7
+ data.tar.gz: 37923bd9eaa647b9ca44433ce374d30e0250799e7078669b180f2ac5734241dc7af757a58b12227de999d78e3d4171ae7e3e9ebbbf828e90f2d71184999fb8c7
data/README.md CHANGED
@@ -12,9 +12,10 @@ bin/rails generate dockerfile
12
12
  General options:
13
13
 
14
14
  * `--force` - overwrite existing files
15
- * `--ci` - include test gems in bundle
15
+ * `--ci` - include test gems in deployed image
16
16
  * `--cache` - use build caching to speed up builds
17
17
  * `--parallel` - use multi-stage builds to install gems and node modules in parallel
18
+ * `--compose` - generate a `docker-compose.yml` file
18
19
 
19
20
  Dependencies:
20
21
 
@@ -18,6 +18,7 @@ module DockerfileRails
18
18
  ### ruby gems ###
19
19
 
20
20
  @gemfile = []
21
+ @git = false
21
22
 
22
23
  if File.exist? 'Gemfile.lock'
23
24
  parser = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock'))
@@ -25,7 +26,9 @@ module DockerfileRails
25
26
  end
26
27
 
27
28
  if File.exist? 'Gemfile'
28
- @gemfile += Bundler::Definition.build('Gemfile', nil, []).dependencies.map(&:name)
29
+ gemfile_definition = Bundler::Definition.build('Gemfile', nil, [])
30
+ @gemfile += gemfile_definition.dependencies.map(&:name)
31
+ @git = !gemfile_definition.spec_git_paths.empty?
29
32
  end
30
33
 
31
34
  @sidekiq = @gemfile.include? 'sidekiq'
@@ -10,6 +10,9 @@ class DockerfileGenerator < Rails::Generators::Base
10
10
  class_option :parallel, type: :boolean, default: false,
11
11
  desc: 'use build stages to install gems and node modules in parallel'
12
12
 
13
+ class_option :compose, type: :boolean, default: false,
14
+ desc: 'generate a docker-compose.yml file'
15
+
13
16
  class_option :redit, type: :boolean, default: false,
14
17
  desc: 'include redis libraries'
15
18
 
@@ -34,6 +37,8 @@ class DockerfileGenerator < Rails::Generators::Base
34
37
 
35
38
  template 'docker-entrypoint.erb', 'bin/docker-entrypoint'
36
39
  chmod "bin/docker-entrypoint", 0755 & ~File.umask, verbose: false
40
+
41
+ template 'docker-compose.yml.erb', 'docker-compose.yml'
37
42
  end
38
43
 
39
44
  private
@@ -43,6 +48,10 @@ private
43
48
  @using_node = File.exist? 'package.json'
44
49
  end
45
50
 
51
+ def using_redis?
52
+ options.redis? or @redis
53
+ end
54
+
46
55
  def parallel?
47
56
  using_node? && options.parallel
48
57
  end
@@ -61,8 +70,11 @@ private
61
70
  packages << 'libpq-dev' if options.postgresql? or @postgresql
62
71
  packages << 'default-libmysqlclient-dev' if options.mysql or @mysql
63
72
 
73
+ # add git if needed to install gems
74
+ packages << 'git' if @git
75
+
64
76
  # add redis in case Action Cable, caching, or sidekiq are added later
65
- packages << "redis" if options.redis? or @redis
77
+ packages << "redis" if using_redis?
66
78
 
67
79
  # ActiveStorage preview support
68
80
  packages << "libvips" if @gemfile.include? 'ruby-vips'
@@ -103,7 +115,7 @@ private
103
115
  packages << 'default-mysql-client' if options.mysql or @mysql
104
116
 
105
117
  # add redis in case Action Cable, caching, or sidekiq are added later
106
- packages << "redis" if options.redis? or @redis
118
+ packages << "redis" if using_redis?
107
119
 
108
120
  # ActiveStorage preview support
109
121
  packages << "libvips" if @gemfile.include? 'ruby-vips'
@@ -140,6 +152,16 @@ private
140
152
  binfixups
141
153
  end
142
154
 
155
+ def deploy_database
156
+ if options.postgresql? or @postgresql
157
+ 'postgresql'
158
+ elsif options.mysql or @mysql
159
+ 'mysql'
160
+ else
161
+ 'sqlite3'
162
+ end
163
+ end
164
+
143
165
  def node_version
144
166
  using_node? and `node --version`[/\d+\.\d+\.\d+/]
145
167
  rescue
@@ -0,0 +1,71 @@
1
+ version: "3.8"
2
+ services:
3
+ web:
4
+ build: .
5
+ ports:
6
+ - "3000:3000"
7
+ environment:
8
+ - RAILS_MASTER_KEY=$RAILS_MASTER_KEY
9
+ <% if using_redis? -%>
10
+ - REDIS_URL=redis://redis-db:6379
11
+ <% end -%>
12
+ <% if deploy_database == 'postgresql' -%>
13
+ - DATABASE_URL=postgres://root:password@postgres-db/
14
+ <% elsif deploy_database == 'mysql' -%>
15
+ - DATABASE_URL=mysql2://root:password@mysql-db/
16
+ <% end -%>
17
+ <% if deploy_database == 'sqlite3' -%>
18
+ volumes:
19
+ - ./db:/rails/db
20
+ <% end -%>
21
+ <% if using_redis? or deploy_database != 'sqlite3' -%>
22
+ depends_on:
23
+ <% if using_redis? -%>
24
+ redis-db:
25
+ condition: service_started
26
+ <% end -%>
27
+ <% if deploy_database == 'postgresql' -%>
28
+ postgres-db:
29
+ condition: service_healthy
30
+ <% elsif deploy_database == 'mysql' -%>
31
+ mysql-db:
32
+ condition: service_healthy
33
+ <% end -%>
34
+ <% if deploy_database == 'postgresql' -%>
35
+
36
+ postgres-db:
37
+ image: postgres
38
+ environment:
39
+ POSTGRES_USER: root
40
+ POSTGRES_PASSWORD: password
41
+ volumes:
42
+ - ./tmp/db:/var/lib/postgresql/data
43
+ ports:
44
+ - "5432:5432"
45
+ healthcheck:
46
+ test: pg_isready
47
+ interval: 2s
48
+ timeout: 5s
49
+ retries: 30
50
+ <% elsif deploy_database == 'mysql' -%>
51
+
52
+ mysql-db:
53
+ image: mysql
54
+ command:
55
+ - --default-authentication-plugin=mysql_native_password
56
+ environment:
57
+ MYSQL_ROOT_PASSWORD: password
58
+ volumes:
59
+ - ./tmp/db:/var/lib/mysql
60
+ healthcheck:
61
+ test: mysqladmin ping -h 127.0.0.1 -u root --password=password
62
+ interval: 2s
63
+ timeout: 5s
64
+ retries: 30
65
+ <% end -%>
66
+ <% end -%>
67
+ <% if using_redis? -%>
68
+
69
+ redis-db:
70
+ image: redis
71
+ <% end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerfile-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
@@ -37,6 +37,7 @@ files:
37
37
  - lib/dockerfile-rails/scanner.rb
38
38
  - lib/generators/dockerfile_generator.rb
39
39
  - lib/generators/templates/Dockerfile.erb
40
+ - lib/generators/templates/docker-compose.yml.erb
40
41
  - lib/generators/templates/docker-entrypoint.erb
41
42
  - lib/generators/templates/dockerignore.erb
42
43
  - lib/generators/templates/node-version.erb