Skip to content

Latest commit

 

History

History
123 lines (90 loc) · 3.51 KB

OpenShift.md

File metadata and controls

123 lines (90 loc) · 3.51 KB

Stringer on OpenShift

Deploying into OpenShift

  1. Creating new OpenShift Ruby 2.0 application with the Postgresql cartridge (command-line).
   rhc app create feeds ruby-2.0 postgresql-9.2
  1. Pull the code from the Stringer Github repository.
   cd feeds
   git remote add upstream git@github.com:stringer-rss/stringer.git
   git pull -s recursive -X theirs upstream main
  1. To enable migrations for the application, a new action_hook is required. Add the file, .openshift/action_hooks/deploy, with the below 3 lines into it.
   pushd ${OPENSHIFT_REPO_DIR} > /dev/null
   bundle exec rake db:migrate RAILS_ENV="production"
   popd > /dev/null
  1. Make sure that the file created above is executable on Unix-like systems.
   chmod +x .openshift/action_hooks/deploy
  1. Set the environment variables by generating them with the commands below.
   rhc env set SECRET_KEY_BASE="`openssl rand -hex 64`"
   rhc env set ENCRYPTION_PRIMARY_KEY="`openssl rand -hex 64`"
   rhc env set ENCRYPTION_DETERMINISTIC_KEY="`openssl rand -hex 64`"
   rhc env set ENCRYPTION_KEY_DERIVATION_SALT="`openssl rand -hex 64`"
  1. Configuration of the database server is next. Open the file config/database.yml and add in the configuration for Production as shown below. OpenShift is able to use environment variables to push the information into the application.
   production:
   	adapter: postgresql
   	database: <%= ENV["OPENSHIFT_APP_NAME"] %>
   	host: <%= ENV["OPENSHIFT_POSTGRESQL_DB_HOST"] %>
   	port: <%= ENV["OPENSHIFT_POSTGRESQL_DB_PORT"] %>
   	username: <%= ENV["OPENSHIFT_POSTGRESQL_DB_USERNAME"] %>
   	password: <%= ENV["OPENSHIFT_POSTGRESQL_DB_PASSWORD"] %> 
  1. Due to an older version of bundler being used in OpenShift (1.3.5), some changes need to be made in the Gemfile.

    Remove the Ruby version specification from the Gemfile below (error reporting wrong Ruby version when deploying to OpenShift).

   ruby '2.0.0'
Then change the two gem dependencies below to use the hash rocket syntax for the "require" option.
   gem "coveralls", "~> 0.7", require: false
   gem "rubocop", "~> 0.35.1", require: false
   gem "sinatra-assetpack", "~> 0.3.1", require: "sinatra/assetpack"
to
   gem "coveralls", "~> 0.7", :require => false
   gem "rubocop", "~> 0.35.1", :require => false
   gem "sinatra-assetpack", "~> 0.3.1", :require => "sinatra/assetpack"
  1. Finally, once completed, all changes should be committed and pushed to OpenShift. Note that it might take a while when pushing to OpenShift.
   git add .
   git commit -m "Deployment of Stringer"
   git push origin
  1. Check that you are able to access the website at the URL given, i.e. feeds-username.rhcloud.com. Then set your password, import your feeds and all good to go!

Adding Cronjob to Fetch Feeds

After importing feeds, a cron job is needed on OpenShift to fetch feeds.

  1. Add a new cron cartridge for the cron job.
   rhc cartridge add cron -a feeds
  1. Add a new executable file, .openshift/cron/hourly/fetch_feeds and put the below 4 lines into it.
   ./usr/bin/rhcsh
   pushd ${OPENSHIFT_REPO_DIR} > /dev/null
   bundle exec rake fetch_feeds RAILS_ENV="production"
   popd > /dev/null
  1. Make the file executable.
   chmod +x .openshift/cron/hourly/fetch_feeds
  1. Push all changes to OpenShift.
   git add .
   git commit -m "Added Cronjob"
   git push origin
  1. Done! The cron job should fetch feeds every hour.