Heroku and Github integration (how to structure the project) - deployment

I'm creating a webservice and I want to store the source on github and run the app on heroku. I haven't seen my exact scenario addressed anywhere on the 'net so far, so I'll ask it here:
I want to have the following directory structure:
/project
.git
README <-- project readme file
TODO.otl <-- project outline
... <-- other project-related stuff
/my_rails_app
app
config
...
README <-- rails' readme file
In the above, project corresponds to http://github.com/myuser/project, and my_rails_app is the code that should be pushed to heroku. Do I need a separate branch for the rails app, or is there a simpler way that I'm missing?
I guess my project-related non-rails files could live in my_rails_app, but the rails README already lives there and it seems inconsistent to overwrite that. However, if I leave it, my github page for the rails app will contain the rails readme, which makes no sense.
Also ... I tried just setting it up as described above and running
git push heroku
from the main project folder. Of course, heroku doesn't know I want to deploy the subfolder:
-----> Heroku receiving push
! Heroku push rejected, no Rails or Rack app detected.

Here's a simple solution that may or may not work for you.
Create two projects on GitHub. One project should be just the Rails app (i.e. everything inside the Rails app directory). The other project should be everything outside the Rails app directory.
Add the Rails app project as a git-submodule within the "container" project.
Now you can add Heroku as a remote on the Rails app repository separately and push it to heroku. Heroku will accept the push because it is just a Rails app with the expected directories and files.

A solution for the Heroku situation (not the README file):
If you're using the new Heroku Cedar (I believe it wasn't available when you first asked your question) then your processes (like the rails server process) start up using Foreman. Thus, you can place a Procfile in the root github directory that looks like this:
web: my_rails_app/script/runserver.sh
And then my_rails_app/script/runserver.sh could be a simple
#!/bin/sh
cd my_rails_app
bundle exec rails server -p $PORT
Locally, you should also create a file called .env (note the . at the beginning), which contains
PORT=3000
This file is read by foreman and used to set environment variables so that the port is set when you execute foreman start on your machine (from the root github directory, where the Procfile lies). The Heroku server takes care of the .env file on your dyno. The big advantage is you can set up multiple processes on the dyno that way!

Just overwrite Rails' default README file. There's no reason to keep it around. Put your other project-management-related stuff in the doc directory. While you certainly have valid reasons for wanting to set it up the way you did, you're just creating a headache for yourself by going against convention, and it's probably not worth the benefit.

I would add everything underneath /my_rails_app to the Heroku git repository. Then add GitHub as a remote and add everything underneath /project to the GitHub repository. Then you can push the Rails application to Heroku (from /my_rails_app) and push the full project to GitHub (from /project).

Related

Using .gitignore on Heroku

I recently added an extra file that I want hidden (hushed.js). I created a .gitignore file and added hushed.js to it. I tested it out locally, and it works perfectly. Pushed everything up, and now it breaks in Heroku. In the logs, Heroku says it cannot find that file (Error: Cannot find module '../hushed.js').
My Github and Heroku accounts are connected, so I just push to Github, and it automatically gets deployed in Heroku.
I deleted the .gitignore file, and pushed it up. The Heorku app works perfect now, but alas, the hushed.js is visible in Github.
How can I keep that file "hidden" on Github, but still used by Heroku?
You cannot. If the file is not in GitHub, Heroku will not be able to fetch it, as it retrieves the files directly from GitHub.
If this file contains sensitive data that you don't want to see in GitHub, you can use config variables.
You could also auto-generate that file at deploy time by running the generation code on postinstall.

openshift nodejs copy written file to repo

I have a nodejs app on openshift an one of the things the app does is write a text file.
Problem is, whenever I update code in the app and deploy it, the text file is gone because the live repo address has changed.
Is there a way using build hooks to get any files saved in a particular folder, add them to my git repo and then deploy the app? I'm not completely clear what I would write in a hook or what to save the hook as so any help would be awesome!
Thank you!
You need to store the file inside of your OPENSHIFT_DATA_DIR so that it will not get over-written each time. You can not copy the file into your git repo on the gear. You might want to try something like the WordPress cartridge does, which is create a symlink (using the deploy action hook) to create a folder in your repo dir that is linked to your OPENSHIFT_DATA_DIR (https://github.com/openshift/wordpress-example/blob/master/.openshift/action_hooks/deploy)

Overwriting an existing Heroku app

I have a Sinatra app, hosted on Heroku. Lately, I've been developing that same app from a different folder. It's not a branch, it's just a parallel app / directory with identical contents but different code. I want to push this new app to Heroku, overwriting the app that's currently there. I don't want to merge the two locally, just continue from the new one while keeping the old. What's the proper command sequence for this? I have doubts about running heroku create, as that will result in a new app. Thanks!
Firstly this is certainly possible. The process is quite simple, firstly we need to add Heroku as a new remote repository to your new app.
heroku git:remote -a project
You would replace the 'project' with your Heroku app name. Secondly you would need to force a push to Heroku.
git push -f heroku master
Note: We are using an '-f' to force the push.

Mercurial deployment

I'm quite new to mercurial so this might sound silly..
I am developing a PHP application locally and pushing changes to remote linux server. I have a hgweb.wsgi script publishing my repository which is accessible via url (hg.example.com/repository).
Now I am wondering what is the best way to automate deployment of the app to see it in action on the same server as repository? Obviously I can't just go to hg.example.com/repository since it just shows the web interface of the repository and not the app..
You're mixing up two things which are not necessarily related:
the path part of the URL of your repository, and
the path of the actual repository on your server.
To get a better picture, consider we use SSH, not HTTP, for repository access. This means we probably specify the full path to the repo in the server file system within the path, e.g., to sync with my server in a similar setup, I push to ssh://example.com//var/www/wsgi/example.com (I have a WSGI app, not a PHP one, but that's not important now). The app itself is available at http://example.com/, i.e., site root if /var/www/wsgi/example.com.
Well now, nothing can prevent me to set up HTTP access to this repo using hgweb on a hg.example.com subdomain, so the repo push path is http://hg.example.com/example.com.
Thus:
I push to http://hg.example.com/example.com (repo pulished at this URL)
The repo is located under /var/www/wsgi/example.com (server file system path)
This directory is in some way set up to be considered the site root by the web server
Site root = http://example.com/
P.S. Don't forget about the changegroup hook Ton mentioned.
There are two things you'll need to do:
Add a webserver that can serve PHP-pages (like apache) and let it serve the repository root (as always make sure it's save)
Add a hook to the mercurial server for the changegroup hook. This hook can be as simple as:
update.changegroup = hg up
That will update the working folder of the repository with the latest version.

Deploy Gollum wiki to Heroku

Gollum is "A simple, Git-powered wiki with a sweet API and local frontend."
It's hosted on GitHub: http://github.com/github/gollum
It seems to be a simple Sinatra app, and as such, it seems like it should be easy to deploy to Heroku. I can't seem to get it to work. Mostly because I know next to nothing about Rake and config.ru files.
Is it even possible to deploy a Gollum wiki to Heroku? If so, what would my config.ru file need to look like?
Update/Edit
lib/gollum/frontend/app:
module Precious
class App < Sinatra::Base
This gets called from bin/gollum
require 'gollum/frontend/app'
Precious::App.set(:gollum_path, gollum_path)
Precious::App.run!(options)
It's not possible to run Gollum from heroku. Certainly not as an editable wiki. The Heroku filesystem is read only. You might be able to use it to serve static content, but I'm not sure about that even.
As already mentioned, the problem is that the heroku filesystem is readonly.
But the real problem is underlying grit, which relies on the git command line tool. You can't work with remote repositories without cloning them to the local directory.
See the related question.
So, the solution will be to clone the repo to temporary path, work there and push changes to the remote repo. There is a much overhead: you need to clone repo every time a user browse a wiki page.
Another solution that comes to mind is making some API for grit that will enable to work with git remotely.
Yet another solution is to work with git over ssh.
http://docs.heroku.com/rack#sinatra
require 'hello'
run Sinatra::Application
if it is a sinatra app, that should do it for you.