Skip to content

Adding asset compilation + Access to rails console #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions centos-ruby/bin/prepare
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ if [ -f Gemfile ]; then
fi

# TODO: Add `rake assets:precompile` step here for Rails applications
rake_assets_precompile

# TODO: Add `rake db:migrate` if linked with DB container

popd >/dev/null
14 changes: 13 additions & 1 deletion centos-ruby/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ cd $app_root_dir
# Allow users to inspect/debug the builder image itself, by using:
# $ docker run -i -t openshift/centos-ruby-builder --debug
#
[ "$1" == "--debug" ] && exec /bin/bash
# Allow rails users to directly attache rails console by using:
# $ docker run -i -t openshift/centos-ruby-builder --console

case $1 in
"--debug") exec /bin/bash;;
"--console")
if is_rails_app; then
exec /opt/ruby/bin/ruby_context bundle exec rails console ${RAILS_ENV}
else
exec /bin/bash;
fi
;;
esac

if is_puma_installed; then
bundle_exec "puma --config ${HOME}/etc/puma.cfg"
Expand Down
22 changes: 22 additions & 0 deletions centos-ruby/etc/sdk
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ function bundle_install() {
BUNDLE_WITHOUT=${BUNDLE_WITHOUT:-"development:test"}
ruby_context bundle install $@
}

function rake_assets_precompile() {
if is_rails_app && has_assets; then
echo
echo "---> Starting asset compilation."
/opt/ruby/bin/ruby_context bundle exec rake assets:precompile
echo
fi
}

function is_rails_app() {
[ ! -f Gemfile ] && return 1
[ ! -f Rakefile ] && return 1
! grep " rails " Gemfile.lock >/dev/null && return 1
return 0
}

function has_assets(){
! grep " execjs " Gemfile.lock >/dev/null && return 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User may already have compiled their assets and not want the builder to do it for them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I don't think we can assume that they will use asset compilation gems that require execjs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarterclayton, yes they may, but also they may not have the assets precompiled. In openshift 2.0 we use the disable_asset_compilation marker to disable the precompilation. Wasn't sure how to disable the precompilation in a dockerish way, cause we would need to introduce some kind of convention, which we don't want.
Any tip on that ?

@jwforres yes we can't but if the application is a rails app, in order to precompile the assets the app Gemfile needs to contains a JavaScript runtime (rubyracer, therubyrhino, ...) which will also install execjs as a dependency and so it will be located in the Gemfile.lock.
Thats why I also check in the rake_assets_precompile function that the app is a rails app.
It is similar approach like we use right now in the ruby cartridge.

! /opt/ruby/bin/ruby_context bundle exec "rake -T" | grep "assets:precompile" >/dev/null && return 1
return 0
}