Class: Deployku::RailsPlugin

Inherits:
Plugin
  • Object
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



38
39
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
# File 'lib/deployku/plugins/rails.rb', line 38

def build_dockerfile(path)
  app_path = File.join(path, 'app')
  ruby_version = detect_ruby_version(app_path)
  dockerfile_path = File.join(path, 'Dockerfile')
  # TODO: process Dockerfile with erubis
  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 << "FROM \#{Deployku::Config.from}\n\nENV DEBIAN_FRONTEND noninteractive\n\nRUN apt-get update\n\nRUN /bin/bash -l -c 'rvm install \#{ruby_version} && rvm use \#{ruby_version} --default'\nRUN /bin/bash -l -c 'rvm rubygems current'\nRUN /bin/bash -l -c 'gem install bundler'\n\nRUN /bin/bash -l -c 'rvm cleanup all'\n\nRUN apt-get install -y \#{packages.join(' ')}\n\nRUN apt-get -y autoclean\nRUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*\n\nEXPOSE \#{Deployku::Config.port}\nCMD []\nENTRYPOINT [\"/start\"]\n\nADD start /start\n\nADD app /app\nRUN /bin/bash -l -c 'cd app && RAILS_ENV=production bundle install --without development test'\n"
    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
# 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 << "#!/usr/bin/env bash\nsource /usr/local/rvm/scripts/rvm\ncd app\nexport RAILS_ENV=production\nbundle exec rake db:migrate RAILS_ENV=production\nbundle exec rake assets:precompile RAILS_ENV=production\n\nbundle exec rails s -p \#{Deployku::Config.port} -b 0.0.0.0 -e production\n"
    end
  end
  File.chmod(0755, start_path)
end

#detect(path) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/deployku/plugins/rails.rb', line 79

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



89
90
91
92
93
94
95
96
97
98
# File 'lib/deployku/plugins/rails.rb', line 89

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

#portObject



11
12
13
# File 'lib/deployku/plugins/rails.rb', line 11

def port
  3000
end

#volumesObject



7
8
9
# File 'lib/deployku/plugins/rails.rb', line 7

def volumes
  ['/app/public/']
end