Class: Deployku::RailsPlugin
- Inherits:
-
Plugin
- Object
- Plugin
- Deployku::RailsPlugin
show all
- Defined in:
- lib/deployku/plugins/rails.rb
Constant Summary
collapse
- PACKAGES =
['nodejs']
Instance Method Summary
collapse
Methods inherited from Plugin
<<, command_description, filter_plugins, find_plugin, help, inherited, instance, #packages, run
Instance Method Details
#build_dockerfile(path) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/deployku/plugins/rails.rb', line 40
def build_dockerfile(path)
app_path = File.join(path, 'app')
ruby_version = detect_ruby_version(app_path)
dockerfile_path = File.join(path, 'Dockerfile')
custom_docker_file = File.join(app_path, 'Dockerfile')
if File.exists?(custom_docker_file)
FileUtils.cp(custom_docker_file, dockerfile_path)
else
File.open(dockerfile_path, 'w') do |f|
f << <<EOF
FROM #{Deployku::Config.from}
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN /bin/bash -l -c 'rvm install #{ruby_version} && rvm use #{ruby_version} --default'
RUN /bin/bash -l -c 'rvm rubygems current'
RUN /bin/bash -l -c 'gem install bundler'
RUN /bin/bash -l -c 'rvm cleanup all'
RUN apt-get install -y rsync #{packages.join(' ')}
RUN apt-get -y autoclean
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE #{Deployku::Config.port}
CMD []
ENTRYPOINT ["/start"]
ADD start /start
ADD app /app
RUN /bin/bash -l -c 'mkdir -p /public'
RUN /bin/bash -l -c 'cd app && RAILS_ENV=production bundle install --without development test'
EOF
end
end
end
|
#build_start_script(path) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/deployku/plugins/rails.rb', line 15
def build_start_script(path)
app_path = File.join(path, 'app')
start_path = File.join(path, 'start')
custom_start_path = File.join(app_path, 'start')
if File.exists?(custom_start_path)
FileUtils.cp(custom_start_path, start_path)
else
File.open(start_path, 'w') do |f|
f << <<EOF
#!/usr/bin/env bash
source /usr/local/rvm/scripts/rvm
cd app
export RAILS_ENV=production
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
rsync -av public/ /public/
bundle exec rails s -p #{Deployku::Config.port} -b 0.0.0.0 -e production
EOF
end
end
File.chmod(0755, start_path)
end
|
#detect(path) ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/deployku/plugins/rails.rb', line 82
def detect(path)
gem_file_path = File.join(path, 'Gemfile')
if File.exists?(gem_file_path)
if File.read(gem_file_path) =~ %r{^\s*gem\s+['"](rails)['"]}m
return true
end
end
false
end
|
#detect_ruby_version(path) ⇒ Object
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/deployku/plugins/rails.rb', line 92
def detect_ruby_version(path)
gem_file_path = File.join(path, 'Gemfile')
if File.exists?(gem_file_path)
ruby_version = File.read(gem_file_path).gsub(%r{.*ruby\s+['"]([^'"]+)['"].*}m, '\1')
end
if not ruby_version || ruby_version == ''
ruby_version = '2.1.7'
end
ruby_version
end
|
#port ⇒ Object
11
12
13
|
# File 'lib/deployku/plugins/rails.rb', line 11
def port
3000
end
|
#volumes ⇒ Object
7
8
9
|
# File 'lib/deployku/plugins/rails.rb', line 7
def volumes
['/public/']
end
|