Class: Conjure::Service::RailsServer
- Inherits:
-
Object
- Object
- Conjure::Service::RailsServer
- Defined in:
- lib/conjure/service/rails_server.rb
Instance Method Summary collapse
- #apt_packages_required_for_gems ⇒ Object
- #base_image ⇒ Object
- #console ⇒ Object
- #database_exists ⇒ Object
-
#initialize(host, app_name, rails_environment) ⇒ RailsServer
constructor
A new instance of RailsServer.
- #initialize_database ⇒ Object
- #install_gems ⇒ Object
- #log(options = {}) ⇒ Object
- #migrate_database ⇒ Object
- #rake(command) ⇒ Object
- #restart_server ⇒ Object
- #ruby_version ⇒ Object
- #run ⇒ Object
- #server_image ⇒ Object
- #update_database ⇒ Object
Constructor Details
#initialize(host, app_name, rails_environment) ⇒ RailsServer
Returns a new instance of RailsServer.
4 5 6 7 8 |
# File 'lib/conjure/service/rails_server.rb', line 4 def initialize(host, app_name, rails_environment) @host = host @app_name = app_name @rails_environment = rails_environment end |
Instance Method Details
#apt_packages_required_for_gems ⇒ Object
108 109 110 |
# File 'lib/conjure/service/rails_server.rb', line 108 def apt_packages_required_for_gems ["libpq-dev", "libmysqlclient-dev"] end |
#base_image ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/conjure/service/rails_server.rb', line 10 def base_image @base_image ||= @host.shell.prepare( label: "rails_base", setup_commands: [ "apt-get install -y curl git", "curl -L https://get.rvm.io | bash -s stable", "rvm install #{ruby_version}", "bash -c 'source /usr/local/rvm/scripts/rvm; rvm use #{ruby_version}@global --default'", "apt-get install -y #{apt_packages_required_for_gems.join ' '}", "echo 'deb http://us.archive.ubuntu.com/ubuntu/ precise universe' >>/etc/apt/sources.list", "apt-get install -y python-software-properties software-properties-common", "add-apt-repository -y ppa:chris-lea/node.js-legacy", "apt-get update", "apt-get install -y nodejs", ], environment: { PATH:"/usr/local/rvm/gems/ruby-1.9.3-p448@global/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", RAILS_ENV: @rails_environment, GITHUB_TOKEN: ENV["GITHUB_TOKEN"], FRECKLE_SUBDOMAIN: "neomind", }, host_volumes: {"/rails_app" => "/#{@app_name}"}, ) end |
#console ⇒ Object
98 99 100 101 102 |
# File 'lib/conjure/service/rails_server.rb', line 98 def console base_image.command "cd #{@app_name}; bundle exec rails console", :stream_stdin => true do |stdout, stderr| print stdout end end |
#database_exists ⇒ Object
61 62 63 64 |
# File 'lib/conjure/service/rails_server.rb', line 61 def database_exists Conjure.log "[ rails] Checking the database status" base_image.command("cd #{@app_name}; bundle exec rake db:version; true").include? "Current version:" end |
#initialize_database ⇒ Object
71 72 73 74 |
# File 'lib/conjure/service/rails_server.rb', line 71 def initialize_database Conjure.log "[ rails] Setting up the database" base_image.command "cd #{@app_name}; bundle exec rake db:setup" end |
#install_gems ⇒ Object
52 53 54 55 |
# File 'lib/conjure/service/rails_server.rb', line 52 def install_gems Conjure.log "[ rails] Installing gems" base_image.command "cd #{@app_name}; bundle --deployment" end |
#log(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/conjure/service/rails_server.rb', line 81 def log( = {}) arguments = [] arguments << "-n #{options[:lines]}" if [:lines] arguments << "-f" if [:tail] log_file = "#{@app_name}/log/#{@rails_environment}.log" base_image.command "tail #{arguments.join ' '} #{log_file}" do |stdout, stderr| puts stdout end rescue Interrupt => e end |
#migrate_database ⇒ Object
66 67 68 69 |
# File 'lib/conjure/service/rails_server.rb', line 66 def migrate_database Conjure.log "[ rails] Migrating the database" base_image.command "cd #{@app_name}; bundle exec rake db:migrate" end |
#rake(command) ⇒ Object
92 93 94 95 96 |
# File 'lib/conjure/service/rails_server.rb', line 92 def rake(command) base_image.command "cd #{@app_name}; bundle exec rake #{command}" do |stdout, stderr| print stdout end end |
#restart_server ⇒ Object
76 77 78 79 |
# File 'lib/conjure/service/rails_server.rb', line 76 def restart_server server_image.stop server_image.run "cd #{@app_name}; rm -f tmp/pids/server.pid; bundle exec rails server -p 80" end |
#ruby_version ⇒ Object
104 105 106 |
# File 'lib/conjure/service/rails_server.rb', line 104 def ruby_version Conjure.config.file_contents("../.ruby-version").strip end |
#run ⇒ Object
46 47 48 49 50 |
# File 'lib/conjure/service/rails_server.rb', line 46 def run install_gems update_database restart_server end |
#server_image ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/conjure/service/rails_server.rb', line 36 def server_image @server_image ||= base_image.prepare( label: "rails_server", ports: [80], environment: { PATH:"/usr/local/rvm/gems/ruby-1.9.3-p448@global/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", }, ) end |
#update_database ⇒ Object
57 58 59 |
# File 'lib/conjure/service/rails_server.rb', line 57 def update_database database_exists ? migrate_database : initialize_database end |