Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #95 from OSC/product_types
Browse files Browse the repository at this point in the history
Product types
  • Loading branch information
ericfranz committed Dec 14, 2016
2 parents aa378e1 + 6234bc5 commit 7843b2d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
33 changes: 33 additions & 0 deletions app/apps/ood_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ def run_setup_production
end
end

def passenger_rack_app?
path.join("config.ru").file?
end

def passenger_nodejs_app?
path.join("app.js").file?
end

def passenger_python_app?
path.join("passenger_wsgi.py").file?
end

def passenger_meteor_app?
path.join(".meteor").exist?
end

def passenger_app?
passenger_rack_app? || passenger_nodejs_app? || passenger_python_app? || passenger_meteor_app?
end

def passenger_rails_app?
return @passenger_rails_app if defined? @passenger_rails_app
@passenger_rails_app = (passenger_rack_app? && bundler_helper.has_gem?("rails"))
end

def passenger_railsdb_app?
# FIXME: assumes a rails db ood app will always use sqlite3
return @passenger_railsdb_app if defined? @passenger_railsdb_app
@passenger_railsdb_app = (passenger_rails_app? && bundler_helper.has_gem?("sqlite3"))
end



private

def load_manifest
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/products_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ def ssh_key
target = Pathname.new("~/.ssh/id_rsa.pub").expand_path
File.read(target) if target.file?
end

def command_btn(title:, key:, display:)
button_tag(title,
class: "btn btn-default btn-block",
data: {
toggle: "cli",
target: cli_product_path(key, name: @product.name, type: @type),
title: title,
cmd: display
})
end
end
10 changes: 8 additions & 2 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Product
include ActiveModel::Model

delegate :passenger_rack_app?, :passenger_rails_app?, :passenger_app?, to: :app

TEMPLATE = "https://raw.githubusercontent.com/AweSim-OSC/rails-application-template/remote_source/awesim.rb"

attr_accessor :name
Expand All @@ -16,8 +18,12 @@ class Product

# lint a given app
validate :manifest_is_valid, on: [:show_app, :list_apps]
validate :gemfile_is_valid, on: :show_app
validate :gems_installed, on: :show_app

with_options if: :passenger_rails_app?, on: :show_app do |app|
app.validate :gemfile_is_valid
app.validate :gems_installed
end

validate :is_git_repo, on: :show_app

def app_does_not_exist
Expand Down
18 changes: 5 additions & 13 deletions app/views/products/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,13 @@
</p>
</div><!-- /.col-md-6 -->
<div class="col-md-2 col-xs-6">
<%= link_to 'Shell', OodAppkit.shell.url(host: ENV['OOD_DEV_SSH_HOST'], path: @product.router.path.realdirpath).to_s, target: '_blank', class: 'btn btn-default btn-block' %>
<%= link_to 'Files', OodAppkit.files.url(path: @product.router.path.realdirpath).to_s, target: '_blank', class: 'btn btn-default btn-block' %>
<%= command_btn(title: "Bundle Install", key: "bundle_install", display:"<code>scl enable rh-ruby22 nodejs010 -- bin/bundle install --path=vendor/bundle</code>") if @product.passenger_rails_app? %>
<%= command_btn(title: "Precompile Assets", key: "precompile_assets", display: "RAILS_ENV=production scl enable rh-ruby22 nodejs010 -- <<< 'bin/rake assets:clobber && bin/rake assets:precompile && bin/rake tmp:clear'") if @type == :usr && @product.passenger_rails_app? %>
<%= command_btn(title: "Restart App", key: "restart_app", display: "<code>mkdir -p tmp && touch tmp/restart.txt</code>") if @product.passenger_app? %>
</div><!-- /.col-md-2 -->
<div class="col-md-2 col-xs-6">
<button class="btn btn-default btn-block" data-toggle="cli" data-target="<%= cli_product_path('bundle_install', name: @product.name, type: @type) %>" data-title="Bundle Install" data-cmd="<code>scl enable rh-ruby22 nodejs010 -- bin/bundle install --path=vendor/bundle</code>">
Bundle Install
</button>
<% if @type == :usr %>
<button class="btn btn-default btn-block" data-toggle="cli" data-target="<%= cli_product_path('precompile_assets', name: @product.name, type: @type) %>" data-title="Precompile Assets" data-cmd="RAILS_ENV=production scl enable rh-ruby22 nodejs010 -- <<< 'bin/rake assets:clobber && bin/rake assets:precompile && bin/rake tmp:clear'">
Build Assets
</button>
<% end %>
<button class="btn btn-default btn-block" data-toggle="cli" data-target="<%= cli_product_path('restart_app', name: @product.name, type: @type) %>" data-title="Restart App" data-cmd="mkdir -p tmp && touch tmp/restart.txt">
Restart App
</button>
<%= link_to 'Shell', OodAppkit.shell.url(host: ENV['OOD_DEV_SSH_HOST'], path: @product.router.path.realdirpath).to_s, target: '_blank', class: 'btn btn-default btn-block' %>
<%= link_to 'Files', OodAppkit.files.url(path: @product.router.path.realdirpath).to_s, target: '_blank', class: 'btn btn-default btn-block' %>
</div><!-- /.col-md-2 -->

</div><!-- /.row -->
Expand Down

0 comments on commit 7843b2d

Please sign in to comment.