Override windows gem version deploying to Openshift - ruby-on-rails

I'm attempting to deploy a Rails app which I have developed on Windows, to Openshift. However, the bundle is not complete, because Gemfile.lock contains lines like:
pg (0.17.0-x86-mingw32)
which therefore don't get installed on the Linux instance at Openshift.
Knowing that Heroku works around this by detecting a Windows Gemfile.lock and removing it, I have tried adding a `.openshift/action_hooks/pre_build script doing either
rm Gemfile.lock
or
sed -i /mingw32/d Gemfile.lock
But neither helps. How can I deploy my app to Openshift and have it pick up suitable Linux versions of all gems?

Try including a full path to the file, like this: rm $OPENSHIFT_REPO_DIR/Gemfile.lock
You should be able to connect to the server via rhc ssh in order to test the solution.

Related

how to use bundle install without network access

I have a Windows 2012 server that is on an internal network. I used Railsinstaller to put the basic framework on the system. Rails new doesn't work when I reach the bundler section since I can't reach the net.
I have used "gem install rails -i repo --no-rdoc --no-ri" on a net accessible system then placed the gems on my server and ran "gem install --force --local *.gem".
Then "rails new D:\DTS_WEB --edge" and now fail at "unable to connect to github.com". Trying to start the rails server fails telling me that nothing has been checked out.
I modified my gems file with
"gem 'rails', path: '....\Ruby2.2.0\lib\ruby\gems\'" but it still tries github.
I installed git with Railsinstaller along with rails. How can I get past this last obstacle and force everything to use local resources?
Is it possible to build everything on the net accessible node and just copy it into place on the server to use? My first attempt at that failed.
On a machine that has a network connection, you can install your app's gems to a directory within the project using --path:
$ bundle install --path=vendor/bundle
Then, you can copy the project folder (along with all the gems in vendor/bundle) to your internal machine.

Issue with Deploying Ruby on Rails on my Hosting Service

So I am trying to deploy a Rails app on my web hosting service. I have developed an app locally, but this is the first time I have tried to get it to work on another server. My service provider is Blue Host and I am on their most basic shared hosting plan. Just as a test, I created a fresh application on the server, and everything ran fine. However, whenever I add any gem to the Gemfile and run 'bundle install', I get this error:
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
Gem::Exception: Cannot load gem at [/usr/lib64/ruby/gems/1.9.3/cache/rake-10.4.2.gem] in /home/user/application
An error occurred while installing rake (10.4.2), and Bundler cannot continue.
Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.
Whenever I run gem install rake -v '10.4.2' the gem installs fine.
I get similar errors that mention 'sudo' when i try to run other commands as well.
I am not quite sure what this error means. Do I not have the required permissions on my server?
Always use a continuous deployment/integration.
Capistrano does part of the job. It is very simple, you develop you application offline, push to a remote repository, like BitBucket or Github, and then Capistrano takes care of cloning the remote repository to your server (you can also have many), restarting services etc.
If you want to go a step forward you can use continuous integration, so when you push to remote tests will automatically be performed and if they pass your application will be deployed.
This is a basic introduction on how deployment works, you can check online, there are plenty of resources about how to deploy rails.
Go with root user
su root
root$ /etc/

Gitlab CI can't install gem

I'm building a rails app using gitlab ci and a few issues came up.
The first was it couldn't find rake to run the tests
I installed rake on my digital ocean manually to solve this
Then it was complaining the gitlab_ci_runner is not in the sudoers list
I added gitlab ci to the sudoers list which solved that problem
Now when running bundle install it is complaining that Bundler::GemspecError: Could not read gem for every single gem unless I install them myself.
Am I missing something with the way I setup gitlab ci?
Try using the 'gitlab_ci_runner' w/o switching user.
sudo -u gitlab_ci_runner -H bundle install --deployment
If you're root user that has a password (meaning your NOT using a SSH-Key) use this to switch back to root user.
su

using github for windows can't start rails server after pulling a repo

I added some collaborators to a rails project on github. They pull down the project using github for windows but then cannot start the rails server
rails server gives them the same output as typing rails
When we do ls we get:
From the Github directory I tried chmod -R 777 sindika but it didn't work. Why can't they pull down the project and start the server?
Seems like the version of your globally installed rails gem is different from the one the project is built on, so Rails don't recognize this folder as its project. Doing bundle && bundle exec rails s should do the trick. Another way to solve this would be to uninstall the current version of the Rails gem and install the one that corresponds to your project.

Using Hunspell With Heroku

I'm building a Rails app that uses Hunspell and the hunspell-ffi gem so that Ruby can interface with it. I'm deploying the app to heroku, but unfortunately it needs Hunspell to be installed on the server in order for the gem to work.
Is there any way for me to install Hunspell on Heroku? Or am I going to have to migrate to EC2?
Thanks in advance :)
You need to build the required Hunspell library and include it in your Heroku project directly.
Heroku runs on 64-bit Ubuntu therefore the binary has to be compiled under that system. The best approach is to simply use Heroku's Vulcan build server to compile on a Heroku instance.
Compiling for Heroku
gem install vulcan
vulcan create vulcan-compile-me last argument is your own app name.
Download Hunspell source
Extract
vulcan build -v -s ./hunspell-1.3.2 Tells Vulcan to build it and downloads the finished product automatically to /tmp/hunspell..
The build server requires the cloudant add-on, this is installed automatically but you have to make sure to have a verified (credit card added) Heroku account. If you get errors in step six of no build output then do heroku addons:add cloudant --app vulcan-compile-me
Adding to Your Project
Extract the Heroku Vulcan build tar from /tmp
Copy the entire lib folder to vendor/hunspell in your project root directory
Tell Heroku where to look for libraries: heroku config:add LD_LIBRARY_PATH=vendor/hunspell/lib.
Install Dictionaries
Download some dictionaries from Open Office and add them to your project. A good location is a folder called dictionaries at root level. This path is then referenced when initializing Hunspell in Ruby.
http://extensions.services.openoffice.org/dictionary
ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/
Using
Install your favorite Hunspell gem, I use hunspell-ffi. There is a newer gem for Hunspell but I prefer the previous FFI gem. To use initialize the Hunspell object with your dictionaries folder path and language (language match the dictionary file name).
dict = Hunspell.new("dictionaries", "en_US")
if dict.check('caribean') == false
suggestions = dict.suggest('caribean')
if (suggestions.size)
correction = suggestions.first # returns 'caribbean'
end
end
Vendoring for More Complex Projects
You can also vendor the library into your project by putting the tar built by the Vulcan server in the first step into a public accessible server such as Google Storage and then changing the Heroku build pack to download the tar on each instance startup.
heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
The vendor build pack looks for a .vendor_urls file at the root level with HTTP links to the tar balls to install (needs to end in a new line to work).
http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
Vendoring unpacks the tar into the root folder so the lib path for the Heroku settings would then just be "lib". heroku config:add LD_LIBRARY_PATH=lib
Unless I am mistaken or something has changed (I cannot find any evidence of this), you cannot install external native libraries on Heroku. If the library is not already installed (this is the case, I think, for ImageMagick, and perhaps others), you will not be able to use the gem.
Checkout this url: http://gems-summary.heroku.com/2011-07-19
It's freaking amazing how much support Heroku has for the gem community. So all you need to to is add the gem to your bundle since Hunspell is on rubygems, bundle install, and then deploy.
Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'
Then add to git:
git add .
git commit -m 'added hunspell'
Then bundle:
bundle
And deploy:
git push heroku
With Bundler, you should be able to install any gem. According to http://devcenter.heroku.com/articles/how-do-i-install-gems-for-my-app, "Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket."
AFAIK, when your app is spun up, gems in the Gemfile are installed on-the-fly to the server your app is spun up to.
The Aspen stack has pre-installed gems, but you still should be able to add gems not pre-installed.
The bamboo stack has no pre-installed gems, so all gem dependencies must be declared explicitly. I believe that is the same for the Celadon stack.

Resources