I have Ruby (2) on Rails (4) app deployed on OpenShift Enterprise running a Postgres database. After initial deployment the app worked perfectly, information was persisted in the database, routing was working, all the tests were passing - everything was good.
Then I deployed some new changes with git push openshift master. When I went back to the app it was still running, but all the database content (including table structure) was gone.
The output from the push was clean. I didn't write any hooks, or have any funky cron jobs running. I could repeat the process, rebuilding the database, and watch it get blown away on every deployment. This problem was not occurring in my local instance.
tl;dr: Make sure you have a .openshift directory at your project's root, use this as an example: https://github.com/openshift/rails4-example
Here's what was going on.
When I created the Rails app I didn't know where I would end up deploying it. Consequently I didn't start with an OpenShift Rails skeleton app or by using rhc app create ruby-X.X.X -a railsX.
When I was told to deploy on open shift I just configured rhc and set up an openshift git remote.
This meant there was no .openshift directory in my project's root. Once I cloned https://github.com/openshift/rails4-example and moved that project's .openshift directory into my project root I was able to deploy without losing my database.
Related
i have a rails app developed with 4.2.6 and ruby 2.2.4. Its my application so I am the only one responsible for the development, testing and deployment.Now I have few questions related to deployment and would appreciate if someone can help me.
I have two separate servers on digital ocean for staging and production.So how can i deploy my application or what should be the order of deployment when i am done with the development and testing.So..
i should be deploying the code on Staging(quite obvious) and then after testing successfully, in the staging server, deploy it to the production.Is this the way to go ahead.
Or deploy the code on staging and after testing, just deploy the changes only to the production and restart the production server.
Moreover, having separate git repository for both pro and staging good or how should i proceed with code maintenance.
What is the best approach.Is there something which i really need to understand or missing.Kindly help me the goodies with deployment and what suits the best?
Thanks in advance.
First, Yes your first assumption is correct you run you app in development on your local machine then when you are satisfied you test in in a production like environment which is staging then if you test everything an its fine then do a final deploy to production where its ready to be accessed by your users.
Second you dont need to have different git repos for both you should have a main branch where everything goes when its ready for production most of the times this is called master....then for the feature you are working create a separate branch where the changes goes and this is the branch where you add new features to your application usually known as develop or the name of the feature or name bug you are fixing...capistrano will allow you to choose what branch to deploy
Third afer you install capistrano it generates 2 file a staging and production file in the directory config/deploy customize this individually place the ip or endpoin/url of staging server in staging.rb and for production server inproduction.rb
So here what I did and the following output:
root#ubuntu-512mb-sfo1-01:/var/lib/dokku/plugins# dokku postgres:link DATABASE ubuntu-512mb-sfo1-01
2016/02/18 05:24:38 open /var/lib/dokku/plugins/available/pg-plugin/plugin.toml: no such file or directory
2016/02/18 05:24:38 open /var/lib/dokku/plugins/available/pg-plugin/plugin.toml: no such file or directory
no config vars for ubuntu-512mb-sfo1-01
Can someone help me? I try to deploy rails to digital ocean.
I use http://blog.flatironschool.com/using-digital-ocean-and-dokku-for-easier-rails-app-deploys/ - this tutorial but it seems to be horribly outdated. I ran into so many errors so I am thinking of giving this up and staying with heroku hosting.
It means that you don't have a Postgres docker container active. Take a look at the dokku-pg-pluging to know how to configure and instantiate a postgres docker container.
By the way, since your objective is to change from Heroku to DigitalOcean, and you're having trouble using dokku, may I suggest you using deploy bot instead? I did managed to successfully deploy an rails 4 app to DigitalOcean using deploy bot. Follow this tutorial. And you can easily follow this guide with deploy bot, adapting the unicorn and nginx stop/start services with the hooks that deploy bot provides.
Edit:
Since you wanted a more specific answer for the deploy bot solution, here goes my approach (this was +/- 3/4 months ago):
Create the droplet and follow the guide to create a droplet, install ruby, rails, unicorn and nginx and the script to control unicorn (it's in the tutorial).
Configure the deploy bot and make sure you run bundle install and another rails' specific commands (changing environments and so on) after the upload (this is a predefined hook).
The last command should be service nginx restart to restart the server (using the script from step 1).
Profit!
I have made an app with the use of Git and Heroku.
I'm curious if i can deploy Ruby on Rails locally without using Git.
If you aren't going to deploy to Heroku, you don't technically need Git at all. Just delete the .git folder. Given that Git is a great tool however, doing this is a bad idea.
You can deploy a Rails app locally, and the typical way to do this is with Apache and Passenger ( I'm assuming you are using a flavor of linux, OSX may have a host running already ).
It has been a while since I had done this, but this page seems to have the right idea:
https://nathanhoad.net/how-to-ruby-on-rails-ubuntu-apache-with-passenger
Rails s or rails server (in terminal) and you have localhost:3000. This is your local rails program and is incredibly convienent for development. Of course you need to be in the directory of your program to deploy it on localhost
I am creating a Rails app for work and until I can install the app on a "in house" server, I am deploying it to Heroku so that we can start using it now. However, I am going to want to be able to copy its database with all of its data over to the final production server when I ready. I am assuming this is somehow possible, but I don't know where to start. Is there a way you can copy a production database (Postgres) from Heroku and move it to a new server to be used there? How would one go about doing this with Rails?
Heroku provides all of this functionality via the PGBackups plugins. There you'll find everything you need to know about importing, exporting, etc...
I am developing 2 applications in Rails 3.1 (will upgrade soon), and have noticed that my current strategy has its drawbacks. What I am doing currently is:
Work directly on the development directory, have there version control with Git (which works perfect for me).
I have defined the databases like (omitted not interesting parts):
development:
database: db/dev.db
production:
database: db/dev.db
I have both applications running all the time in production mode, where the ports are defined as 3008 and 3009.
From time to time, I want to change little things, and start then a development server for one of the two applications directly with the defaults: rails s thin (port == 3000).
I have noticed that the following things don't work very well.
When I change CSS or Javascript files, I have often to cleanup (and after development rebuild) the assets.
Sometimes, the development server takes the files (CSS and Javascript) from one server and uses them for the other server. I have to manually clean the caches for the browser to avoid that.
What would be a better strategy to develop and use the two applications in parallel locally on my computer? Any tips and hints are welcome. Should I use a deployment tool (Capistrano) for that? Shall I roll my own Rake task for the divide? Or do I miss some magic switch that will heal the wounds (sounds pathetic :-))?
At the end, it is a mix of changes, so I answer my own questions and hope that others may learn something from it. At the end, there are 2 major decisions (and some minor ones):
Work with different repositories for development and production, even on the same machine. Add another one (a bare one) to synchronize the two. Push only from the development, pull only from production.
Use different ports all the time for different applications. Make a scheme like:
appA: dev ==> 4001, prod ==> 3001
appB: dev ==> 4002, prod ==> 3002
...
Here are the changes that I have done. rails/root is the root directory of my application, the overall directory structure is the following:
rails/
root/
another/
...
bare/
root.git/
another.git/
...
production/
root/
another/
...
Create 2 new repositories from the old one, one as a bare repository, the other one for production only:
mkdir rails/production
mkdir rails/bare
cd rails/bare
git clone ../root --bare
cd ../root
git remote add bare ../bare/root
cd rails/production
git clone ../bare/root
cd root
git remote add bare ../../bare/root
Don't use one (the same) database for development and production, just to be sure that Git can do its magic.
Develop (only) on the development repository.
After enough tests, do the following 2 steps:
root> git push bare
root/../production/root> git pull bare
Start the development server (only) with: root> rails s thin -p 4009
and the production server (only) with: root/../production/root> rails s thin -e production -p 3009
So as a result, I have a little more work to do, to stage changes from development to production, but I will eliminate those small irritations that were around all the time.
Running production servers on the development machine, or developing on the production machine is an unusual, even discouraged setup. Use your local machine to develop, run the server in development mode and run your test suite. Commit changes to git. Then, from time, to time, deploy to a server that runs in production mode. That's the recommended setup. As production server you could set up your own (e.g. your own machine or one in the cloud like EC2) and use Capistrano for deployment. More simply and with a lot less trouble, however, you can deploy to a service like Heroku. All you need to do is a git push and the app will deploy. A single instance of concurrency on Heroku is free, even.
Also, Windows is not a very well supported environment for running a Rails server, you're better off with Linux. For development, Windows may do the trick, but you'll definitely be in the minority. Most people are on Mac or Linux. Sometimes people recommend installing Ubuntu Linux on top of Windows in a virtual machine for Rails development.