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 +4 -4
- data/README.md +2 -1
- data/lib/dockerfile-rails/scanner.rb +4 -1
- data/lib/generators/dockerfile_generator.rb +24 -2
- data/lib/generators/templates/docker-compose.yml.erb +71 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 536685e13e342227e5d6af85e3d778539668bbdab81b5430902ae08286a57c62
|
4
|
+
data.tar.gz: a3155769a131089493ae0682e195f6108dd4c81d03c79c6774ce21af0eda04be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|