Change default project root - Heroku - ruby-on-rails

Heroku wants a git repository in an application root directory with a Procfile. What is common best practice for creating an outer directory? Ideally, this outer directory is the root of my git repo, and it contains documentation and high level deployment documentation, in addition to the application root. Obviously - if this would mean my git repo and application root are in different places.
How do I fix this? Do I have two different git repos? Do I make a submodule? Is there a way to just tell Heroku "Hey - this isn't the application root, that directory is though!"
Thanks

The standard structure (at least for Rails apps) is to have a root folder (which is also the application's and repository's root) which contains the application code, documentation and the Procfile.
I've never seen an "outer" folder in any of the apps and I don't see how this could be a good idea. It would just make things more complex.
Example: https://github.com/railstutorial/sample_app. In Rails apps for example, the documentation lives on the doc/ directory, the README is in the root folder README.md and the Procfile is also in the root folder.

Related

What is the purpose of the "system" folder in rails "public/system/"?

The standard place to store non-precompiled public assets in a rails app is in "public/system." Is there any reason for this? I'd like to keep things simple, why shouldn't I just put assets in the "public" folder?
The public/system folder isn't a Rails standard per se or even a documented recommendation. Deployment tools like Capistrano adopted that convention as a suggestion for you to organize user assets that are shared between deployments and shouldn't be in your repository. The idea is symlink public/system to capistrano's shared/system, which is outside of the releases folder.
If you take a look at paperclip's(which is a widely used upload library) docs you'll find:
By default, this location is
:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename. This location was chosen because, on standard Capistrano deployments,
the public/system directory can be symlinked to the app's shared
directory, meaning it survives between deployments.
In your development environment you're supposed to ignore that folder in .gitignore if you're willing to adopt that convention.

Different Folder Structure from Heroku

I'm building an app which requires the frontend and the api to be separate. The folder looks like this
application/
.git/
frontend/
api/
Procfile
The API is a rails application so I'd like to use the cedar stack from Heroku.
When I try and push the application I get the message
! Push rejected, no Cedar-supported app detected
Which makes sense as it needs to look in a subfolder. How do I tell heroku to only use the sub folder?
The folder structure you posted doesn't look like a Rails app at all.
If you want to split the frontend from the api, you can perfectly to that at controller level by having two different namespaces.
That will generate a structure like the following one
app/
controllers/
api/
whatever_controller.rb
frontend/
user_controller.rb
whatever_controller.rb
public/
log/
db/
Procfile
... other standard Rails folders and files
The structure you have seems to represent two completely different Rails app. If that's the case, then you need to use two different Heroku app.
If that's not the case, then that could not work. I don't even think how you can start it, given that it doesn't represent a standard Rails structure.

Ruby on Rails integration with Heroku/Engine Yard/similar services

I have a Ruby on Rails project that I've deployed to a PaaS service via GitHub. The Git repo is structured like so:
/ (root)
README
some random files here
src (directory)
a_folder
another_folder
my_rails_app
app (directory)
config (directory)
config.ru
db (directory)
...
Gemfile
...
Rakefile
README
...
As you can see, the Rails app is two directories underneath the root. I suppose I could move it to one file underneath root if necessary, but I definitely need to have other non-Rails files tracked under version control.
But since my Rails app isn't at the root, I'm having trouble using Engine Yard, Heroku, etc... they don't know where to find the Rakefile. I tried creating a Rakefile (https://gist.github.com/245400) and placing it at the root and src directories but it still doesn't work.
Do you know what's going on here or how to fix it?
(As requested ;-D)
If you want to deploy on Heroku/Engine Yard, etc. you might just want to put all those "other folders" within the app directory (e.g. in a folder called supporting_documents or something).
Then you can have those docs under source control AND deploy on Heroku. Also, with Heroku, you'll be able to add those additional documents to the slugignore file (http://devcenter.heroku.com/articles/slug-compiler) so they don't get compiled in the slug.

Deploy static assets only to a web server with separate app server

Using Rails 3.0.7 and git, deploying with capistrano. I'm using different machines as web and app servers. I cannot deploy the application code to the web server, only the static assets--basically the public/ folder.
This would seem common but no luck searching for a best practice.
Is anything build around capistrano to handle this case? Otherwise I'm thinking that adding tasks to create the structure, but scp the public directory from the app server would be the solution.
So I assume there's a business reason you can't deploy the app to the other server?
If there isn't then just deploy the whole code
and configure your web server to just serve the public folder.
(in Apache/Passenger the configs would be exactly the same, you just wouldn't enable passenger on the static server)
That is the only simple way to do it..
otherwise you're going to cause yourself a load of headaches..
Nevertheless I'm going to make up a way to solve this.
If you do need to deploy just the static code
then I suggest you create two repositories
the app (eg. git#myserver:app.git
the static files (eg. git#myserver:static.git)
Now in your app include git#myserver:static.git as a submodule mounted at public/
Having done this, you should search standard capistrano recipes for deploying with git submodules (in particular I guess you'll want to store a local cache of the submodules, update it, then git submodule init somehow with that)
You can then have two capistrano recipes
I suggest you check out capistrano multi-stage... defining app and static as two stages
You can therefore just specify git#myserver:app.git as the repository for "app"
and git#myserver:static.git as the repository for "static"
then a simple cap app deploy:migrations && cap static deploy should do it.
but remember these will not be simultaneous
I too wish there were more established practices published. We've done ours based on the Django book which recommends making your public app directory a networked directory.
This is much better as scp only works if your public directory is static. Many apps will write things to the public directory, e.g. image generation on-the-fly. These files also need to be copied to the web server immediately.
I recommend using a NFS, Samba Share or similar, so that your public directory is actually just a networked folder, so when you write to it, it's like writing to the remote folder.
To integrate it into capistrano we do the following:
create this networked folder in shared/public
After deploy:update_code:
move content from current/public to shared/public (overriding files as needed)
remove or rename current/public then symlink current/public to shared/public
Downsides:
* doesn't remove old files (like someone earlier said)
* no real rollback option (apart from redeploying older version)
Best approach I've come up with is to in fact scp files over to the web server.

first time pushing to github

I have a rails 3 application in local. I created reposority and i know the basics of git like git. I am using git for heroku but i haven't push my application to public place before. What i want to learn is :
Which files should i add to git ignore? Because i have some personal passwords and keys in environments.rb and also have some keys in initializers.
If i add some files in git ignore, i guess it will be a problem for people who clones it, because some files will be missing.
I will also keep on working on my application, i can always add new keys to environment.rb or somewhere else. Do i have to clone(branch) my application? I heard something "branch, master" but i have no idea about these terms?
The idea of gitignore is that often there are temporary files, or files that are specific to your IDE. They add nothing to source code, and sometimes they contain sensible information about your machine that you probably don't want to share.
This repo on github is a nice collection of gitignore templates:
https://github.com/github/gitignore
Rails template is available: https://github.com/github/gitignore/blob/master/Rails.gitignore
EDIT
If you have files with you current configuration, which are important for your app, remove all the sensitive information from them, check them in, and after that modify gitignore file.
If you have already checked in a file with passwords, use this manual: http://help.github.com/removing-sensitive-data/
Create a .gitignore file in your root directory, and add all the files which you do not want to track. Make sure those files are not already tracked. If they are, delete the files, commit the change to the git repository, and then add those files to your .gitignore file.
Your .gitignore file could look something like this
log
db/*.sqlite3
db/*.sql
*.tmproj
tmp
coverage
config/database.yml
*~
\#*\#
.\#*
target/*
**/.DS_Store
.DS_Store

Resources