Bits and Bytes

Notes from the deviant pursuits of a technical vagrant

Publishing a Github-Based Rails App to Openshift

Environment

Ubuntu 16.04 (64 bit), rails 4.1.4 (deemed to be appropriate, given that the rails version used in the sample Openshift rails project [3] is 4.1.4.

Process

  1. Create the Github repository
  2. Clone the repository locally
git clone [Github clone url]
  1. Enter the root directory or the repository
cd [Repository name]
  1. Create a new rails project in the repository, poviding a name for the project
rails _4.1.4_ new [Project name] --database=postgresql
  1. Move the contents of the root directory of the newly created rails project to the root directory of the repository, then remove the root directory of the rails project
mv [Project name]/* .
rm -rf [Project name]
  1. Create an Openshift 'Rails 4' application
  2. In the locally cloned Github repository, add the Openshift repository as a remote repository
git remote add openshift -f [Openshift clone url]
  1. Remove files which cause subsequent merge complications
rm config/secrets.yml
rm -rf log/.keep
  1. Merge the contents of the Openshift repository into the Github repository
git merge openshift/master -s recursive -X ours
  1. Replace the contents of the config/database.yml file with those found in the same file within the repository of the Openshift sample Rails 4 application [3], afterwards (at time of writing) the contents of the file should appear as follows

sqlite: &sqlite
adapter: sqlite3
database: db/<%= Rails.env %>.sqlite3

mysql: &mysql
adapter: mysql2
database: "<%=ENV['OPENSHIFT_APP_NAME']%>"
username: "<%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>"
password: "<%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>"
host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>

postgresql: &postgresql
adapter: postgresql
database: <%=ENV['OPENSHIFT_APP_NAME']%>
username: <%=ENV['OPENSHIFT_POSTGRESQL_DB_USERNAME']%>
password: <%=ENV['OPENSHIFT_POSTGRESQL_DB_PASSWORD']%>
host: <%=ENV['OPENSHIFT_POSTGRESQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_POSTGRESQL_DB_PORT']%>
min_messages: ERROR
reconnect: false

defaults: &defaults
pool: 5
timeout: 5000
encoding: utf8
<<: *<%= ENV['RAILS_DB'] || "sqlite" %>

development:
<<: *defaults

test: &test
<<: *defaults

production:
<<: *defaults

  1. Publish application to Openshift by pushing the changes to the remote repository
git push openshift HEAD

A copy of the resulting source can be found [here](https://github.com/adlawren/Openshift-Rails-App-Test).

Comments

comments powered by Disqus