Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. Stringer on OpenShift
  2. ========================
  3.  
  4. Deploying into OpenShift
  5. ------------------------
  6.  
  7. 1. Creating new OpenShift Ruby 2.0 application with the Postgresql cartridge (command-line).
  8.  
  9. ```sh
  10. rhc app create feeds ruby-2.0 postgresql-9.2
  11. ```
  12.  
  13. 2. Pull the code from the Stringer Github repository.
  14.  
  15. ```sh
  16. cd feeds
  17. git remote add upstream git://github.com/swanson/stringer.git
  18. git pull -s recursive -X theirs upstream master
  19. ```
  20.  
  21. 3. 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.
  22.  
  23. ```
  24. pushd ${OPENSHIFT_REPO_DIR} > /dev/null
  25. bundle exec rake db:migrate RACK_ENV="production"
  26. popd > /dev/null
  27. ```
  28.  
  29. 4. Make sure that the file created above is executable on Unix-like systems.
  30.  
  31. ```sh
  32. chmod +x .openshift/action_hooks/deploy
  33. Windows: git update-index --chmod=+x .openshift/action_hooks/deploy
  34. ```
  35.  
  36. 5. Set the SECRET_TOKEN as a rhc environment variable by generating it with the command below.
  37.  
  38. ```sh
  39. rhc env set SECRET_TOKEN="`openssl rand -hex 20`"
  40. ```
  41.  
  42. 6. 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.
  43.  
  44. ```
  45. production:
  46. adapter: postgresql
  47. database: <%= ENV["OPENSHIFT_APP_NAME"] %>
  48. host: <%= ENV["OPENSHIFT_POSTGRESQL_DB_HOST"] %>
  49. port: <%= ENV["OPENSHIFT_POSTGRESQL_DB_PORT"] %>
  50. username: <%= ENV["OPENSHIFT_POSTGRESQL_DB_USERNAME"] %>
  51. password: <%= ENV["OPENSHIFT_POSTGRESQL_DB_PASSWORD"] %>
  52. ```
  53.  
  54. 7. Due to an older version of bundler being used in OpenShift (1.3.5), some changes need to be made in the Gemfile.
  55.  
  56. Remove the Ruby version specification from the Gemfile below (error reporting wrong Ruby version when deploying to OpenShift).
  57.  
  58. ```
  59. ruby '2.0.0'
  60. ```
  61.  
  62. Then change the two gem dependencies below to use the hash rocket syntax for the "require" option.
  63.  
  64. ```
  65. gem "coveralls", "~> 0.7", require: false
  66. gem "sinatra-assetpack", "~> 0.3.1", require: "sinatra/assetpack"
  67. ```
  68. to
  69. ```
  70. gem "coveralls", "~> 0.7", :require => false
  71. gem "sinatra-assetpack", "~> 0.3.1", :require => "sinatra/assetpack"
  72. ```
  73.  
  74. 8. Finally, once completed, all changes should be committed and pushed to OpenShift. Note that it might take a while when pushing to OpenShift.
  75.  
  76. ```sh
  77. git add .
  78. git commit -m "Deployment of Stringer"
  79. git push origin
  80. ```
  81.  
  82. 9. 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!
  83.  
  84.  
  85. Adding Cronjob to Fetch Feeds
  86. -----------------------------
  87.  
  88. After importing feeds, a cron job is needed on OpenShift to fetch feeds.
  89.  
  90. 1. Add a new cron cartridge for the cron job.
  91.  
  92. ```sh
  93. rhc cartridge add cron -a feeds
  94. ```
  95.  
  96. 2. Add a new executable file, .openshift/cron/hourly/fetch_feeds and put the below 4 lines into it.
  97.  
  98. ```
  99. ./usr/bin/rhcsh
  100. pushd ${OPENSHIFT_REPO_DIR} > /dev/null
  101. bundle exec rake fetch_feeds RACK_ENV="production"
  102. popd > /dev/null
  103. ```
  104.  
  105. 3. Make the file executable.
  106.  
  107. ```sh
  108. chmod +x .openshift/cron/hourly/fetch_feeds
  109. Windows: git update-index --chmod=+x .openshift/cron/hourly/fetch_feeds
  110. ```
  111.  
  112. 4. Push all changes to OpenShift.
  113.  
  114. ```sh
  115. git add .
  116. git commit -m "Added Cronjob"
  117. git push origin
  118. ```
  119.  
  120. 5. Done! The cron job should fetch feeds every hour.
  121.  
  122. Password Reset
  123. --------------
  124. In the event that you need to change your password, run the following commands
  125. ```
  126. rhc ssh feeds
  127. cd app-root/repo
  128. bundle exec rake change_password RACK_ENV="production"
  129. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement