Difference between revisions of "Installation/Heroku"

From diaspora* project wiki
Jump to: navigation, search
(Style and updated)
Line 1: Line 1:
== Getting Started ==
+
{{Note|These instructions should are for Unix based operating systems. If you're on Windows you better get a virtual machine.}}
 +
 
 +
== First deploy ==
 +
 
 
We start with building a minimal pod entirely hosted on Heroku.
 
We start with building a minimal pod entirely hosted on Heroku.
 
It's good to have an RVM installation locally to leave your local system clean(er).
 
It's good to have an RVM installation locally to leave your local system clean(er).
 
   
 
   
 
Fork Diaspora and clone your fork to your local machine.
 
Fork Diaspora and clone your fork to your local machine.
There checkout a custom branch for your pod, we'll name it  `heroku` here.
+
There checkout a custom branch for your pod, we'll name it  <tt>heroku</tt> here.
  
<pre>cd diaspora
+
<syntaxhighlight lang="bash">
 +
cd diaspora
 
git checkout -b heroku origin/master  
 
git checkout -b heroku origin/master  
</pre>
+
</syntaxhighlight>
  
To update your `Gemfile.lock` run
+
We need to swithc the <tt>Gemfile.lock</tt> to PostgreSQL. To update it, run
  
<pre>
+
<syntaxhighlight lang="bash">
 
DB=postgres bundle --without development test heroku production assets
 
DB=postgres bundle --without development test heroku production assets
 
git add Gemfile.lock
 
git add Gemfile.lock
 
git commit -m "switch Gemfile.lock to pg exclusivly"
 
git commit -m "switch Gemfile.lock to pg exclusivly"
</pre>
+
</syntaxhighlight>
 
 
[Tester comment, Oct 12 2012 from a Windows user: Heroku writes Gemfile dynamically at compile time and uses a deploy mode that insists Gemfile.lock be in version control. If you deploy from a system that is not outfitted with ruby development tools, this can cause a pickle with conditional gems. To change Gemfile on Heroku it is necessary to run bundle locally and create a matching Gemfile.lock. Bundle, however, is not well supported at this time on native Windows systems. So, to deploy your Rails apps to Heroku more easily, either run a virtual Linux box under Windows or find an old PC and load Linux on it. ]
 
 
 
Install the `heroku` gem:
 
  
<pre>gem install heroku</pre>
+
Install the [https://toolbelt.heroku.com/ Heroku toolbelt].
  
  
Create an app, you must exchange `diasporadev` here and in all following cases with something unique:
+
Create an app, you must exchange <tt>diasporadev</tt> here and in all following cases with something unique:
  
<pre>heroku apps:create diasporadev</pre>
+
<syntaxhighlight lang="bash">
 +
heroku apps:create diasporadev
 +
</syntaxhighlight>
  
 
Enable required the addons:
 
Enable required the addons:
  
<pre>
+
<syntaxhighlight lang="bash">
 
heroku labs:enable user-env-compile
 
heroku labs:enable user-env-compile
 
heroku addons:add redistogo:nano
 
heroku addons:add redistogo:nano
 
heroku addons:add heroku-postgresql
 
heroku addons:add heroku-postgresql
</pre>
+
</syntaxhighlight>
  
And make the database available, replace the `REPLACEME` with corresponding part of `HEROKU_POSTGRESQL_REPLACEME_URL` that the last command gave you (or look it up with `heroku config`):
+
And make the database available, replace the <tt>REPLACEME</tt> with corresponding part of <tt>HEROKU_POSTGRESQL_REPLACEME_URL</tt> that the last command gave you (or look it up with <tt>heroku config</tt>):
  
<pre>heroku pg:promote HEROKU_POSTGRESQL_REPLACEME</pre>
+
<syntaxhighlight lang="bash">
 +
heroku pg:promote HEROKU_POSTGRESQL_REPLACEME
 +
</syntaxhighlight>
  
Set some basic configuration, remember to replace `diasporadev`:
+
Set some basic configuration, remember to replace <tt>diasporadev</tt>:
  
<pre>heroku config:add HEROKU=true  DB=postgres ENVIRONMENT_URL=https://diasporadev.herokuapp.com/ ENVIRONMENT_ASSETS_SERVE=true ENVIRONMENT_UNICORN_EMBED_RESQUE_WORKER=true  ENVIRONMENT_CERTIFICATE_AUTHORITIES=/usr/lib/ssl/certs/ca-certificates.crt</pre>
+
<syntaxhighlight lang="bash">
 +
heroku config:set HEROKU=true  ENVIRONMENT_URL=https://diasporadev.herokuapp.com/ ENVIRONMENT_ASSETS_SERVE=true SERVER_EMBED_SIDEKIQ_WORKER=true  ENVIRONMENT_CERTIFICATE_AUTHORITIES=/usr/lib/ssl/certs/ca-certificates.crt
 +
</syntaxhighlight>
  
You can now already go through `config/diaspora.yml.example` and add the settings you want to differ from the defaults (`config/defaults.yml`), converting them to environment variables as described at the top of the file.
+
You can now already go through <tt>config/diaspora.yml.example</tt> and add the settings you want to differ from the defaults (<tt>config/defaults.yml</tt>), converting them to environment variables as described at the top of the file.
  
 
Set a secure token:
 
Set a secure token:
  
<pre>heroku config:add SECRET_TOKEN=$(curl -s "http://www.random.org/cgi-bin/randbyte?nbytes=40&format=h" | tr -d " \n")</pre>
+
<syntaxhighlight lang="bash">
 +
heroku config:add SECRET_TOKEN=$(curl -s "http://www.random.org/cgi-bin/randbyte?nbytes=40&format=h" | tr -d " \n")
 +
</syntaxhighlight>
  
 
Now lets deploy:
 
Now lets deploy:
  
<pre>git push heroku heroku:master</pre>
+
<syntaxhighlight lang="bash">
 +
git push -u heroku heroku:master
 +
</syntaxhighlight>
  
 
And load the schema:
 
And load the schema:
  
<pre>heroku run rake db:schema:load</pre>
+
<syntaxhighlight lang="bash">
 +
heroku run rake db:schema:load
 +
</syntaxhighlight>
  
  
 
Restart to ensure you're not in the crashed state from the deploy with a unpopulated database:
 
Restart to ensure you're not in the crashed state from the deploy with a unpopulated database:
  
<pre>heroku restart</pre>
+
<syntaxhighlight lang="bash">
 +
heroku restart
 +
</syntaxhighlight>
  
 
That should give you a basic pod, to open it in your browser run
 
That should give you a basic pod, to open it in your browser run
  
<pre>heroku open</pre>
+
<syntaxhighlight lang="bash">
 +
heroku open
 +
</syntaxhighlight>
  
 
== Custom landing page ==
 
== Custom landing page ==
  
Edit `.gitignore` and remove the following line:
+
Edit <tt>.gitignore</tt> and remove the following line:
  
<pre>app/views/home/_show.*</pre>
+
<pre>
 +
app/views/home/_show.*
 +
</pre>
  
Create your landing page as described in [[Customize your splash page]]. Add it to your branch:
+
Create your landing page as described in [[Custom Splash Page]]. Add it to your branch:
  
<pre>
+
<syntaxhighlight lang="bash">
 
git add app/views/home/
 
git add app/views/home/
 
git commit -m "custom landing page"
 
git commit -m "custom landing page"
</pre>
+
</syntaxhighlight>
  
 
Deploy it:
 
Deploy it:
  
<pre>git push heroku heroku:master</pre>
+
<syntaxhighlight lang="bash">
 +
git push heroku heroku:master
 +
</syntaxhighlight>
  
== S3 Image and asset hosting ==
+
== Amazon S3 Image and asset hosting ==
  
 
To enable image hosting, first set your S3 data:
 
To enable image hosting, first set your S3 data:
  
<pre>  
+
<syntaxhighlight lang="bash">  
 
heroku config:add ENVIRONMENT_S3_ENABLE=true ENVIRONMENT_S3_KEY=changeme ENVIRONMENT_S3_SECRET=changeme ENVIRONMENT_S3_BUCKET=changeme ENVIRONMENT_IMAGE_REDIRECT_URL=https://changeme.s3.amazonaws.com/
 
heroku config:add ENVIRONMENT_S3_ENABLE=true ENVIRONMENT_S3_KEY=changeme ENVIRONMENT_S3_SECRET=changeme ENVIRONMENT_S3_BUCKET=changeme ENVIRONMENT_IMAGE_REDIRECT_URL=https://changeme.s3.amazonaws.com/
</pre>
+
</syntaxhighlight>
  
 
Change your region if it's different from the default:
 
Change your region if it's different from the default:
  
<pre>heroku config:add ENVIRONMENT_S3_REGION=eu-west-1</pre>
+
<syntaxhighlight lang="bash">
 +
heroku config:add ENVIRONMENT_S3_REGION=eu-west-1
 +
</syntaxhighlight>
  
 
To enable uploading assets to S3 and serving them from it:
 
To enable uploading assets to S3 and serving them from it:
  
<pre>heroku config:add ENVIRONMENT_ASSETS_UPLOAD=true ENVIRONMENT_ASSETS_HOST=https://changeme.s3.amazonaws.com</pre>
+
<syntaxhighlight lang="bash">
 +
heroku config:add ENVIRONMENT_ASSETS_UPLOAD=true ENVIRONMENT_ASSETS_HOST=https://changeme.s3.amazonaws.com
 +
</syntaxhighlight>
  
Run the following to upload your assets. Currently the integration into the rake task isn't working so you have to run this after each deploy:
+
The assets should be uploaded with the next deploy. If that's not working run the following afterwards:
  
<pre>heroku run 'rails runner "AssetSync.sync"'</pre>
+
<syntaxhighlight lang="bash">
 +
heroku run 'rails runner "AssetSync.sync"'
 +
</syntaxhighlight>
  
== RDS Database hosting ==
+
== Amazon RDS Database hosting ==
  
<pre>heroku config:set DB=mysql</pre>
+
<syntaxhighlight lang="bash">
 +
heroku config:set DB=mysql
 +
</syntaxhighlight>
  
Grab commit SHA:
+
Grab commit SHA from switch to PostgreSQL and revert it:
  
<pre>
+
<syntaxhighlight lang="bash">
 
git log --grep "switch Gemfile.lock to pg exclusivly"  
 
git log --grep "switch Gemfile.lock to pg exclusivly"  
 
git revert <commit-sha from previous command>
 
git revert <commit-sha from previous command>
</pre>
+
</syntaxhighlight>
  
Follow <https://devcenter.heroku.com/articles/amazon_rds>
+
Follow https://devcenter.heroku.com/articles/amazon_rds
  
 
Deploy.
 
Deploy.
Line 124: Line 152:
 
This isn't fool proof, think about what the commands do! Assuming you have committed to master and these commits are in your fork:
 
This isn't fool proof, think about what the commands do! Assuming you have committed to master and these commits are in your fork:
  
<pre>
+
<syntaxhighlight lang="bash">
 
git branch -m master oldheroku
 
git branch -m master oldheroku
 
git remote add upstream git://github.com/diaspora/diaspora.git # if not done already
 
git remote add upstream git://github.com/diaspora/diaspora.git # if not done already
Line 131: Line 159:
 
git push -f origin master oldheroku
 
git push -f origin master oldheroku
 
git checkout -b heroku origin/master
 
git checkout -b heroku origin/master
</pre>
+
</syntaxhighlight>
 
 
Heroku CLI is no longer in the Gemfile, ensure it's installed:
 
  
<pre>gem install heroku</pre>
+
Heroku CLI is no longer in the Gemfile, instead make sure the [https://toolbelt.heroku.com/ Heroku toolbelt is installed].
  
 
Replace diasporadev with your appname everywhere.
 
Replace diasporadev with your appname everywhere.
  
<pre>heroku config:set HEROKU=true  ENVIRONMENT_URL=https://diasporadev.herokuapp.com/ ENVIRONMENT_ASSETS_SERVE=true ENVIRONMENT_UNICORN_EMBED_RESQUE_WORKER=true  ENVIRONMENT_CERTIFICATE_AUTHORITIES=/usr/lib/ssl/certs/ca-certificates.crt</pre>
+
<syntaxhighlight lang="bash">
 +
heroku config:set HEROKU=true  ENVIRONMENT_URL=https://diasporadev.herokuapp.com/ ENVIRONMENT_ASSETS_SERVE=true SERVER_EMBED_SIDEKIQ_WORKER=true  ENVIRONMENT_CERTIFICATE_AUTHORITIES=/usr/lib/ssl/certs/ca-certificates.crt
 +
</syntaxhighlight>
  
Run `heroku config` to double check that `SECRET_TOKEN` is set, if not set one like above. Also check if `DB` is set to the database you use ("postgres" or "mysql"). `NO_SSL` is now `ENVIRONMENT_REQUIRE_SSL` and to disable SSL you have set it to `false`.
+
Run <tt>heroku config</tt> to double check that <tt>SECRET_TOKEN</tt> is set, if not set one like above. Also check if<tt>DB</tt> is set to the database you use ("postgres" or "mysql"). <tt>NO_SSL</tt> is now <tt>ENVIRONMENT_REQUIRE_SSL</tt> and to disable SSL you have set it to <tt>false</tt>.
  
Go through `config/diaspora.yml.example` and add the settings you want to differ from the defaults (`config/defaults.yml`), converting them to environment variables as described at the top of the file.
+
Go through <tt>config/diaspora.yml.example</tt> and add the settings you want to differ from the defaults (<tt>config/defaults.yml</tt>), converting them to environment variables as described at the top of the file.
  
 
If you want your custom splash page back:
 
If you want your custom splash page back:
  
<pre>
+
<syntaxhighlight lang="bash">
 
git checkout oldheroku
 
git checkout oldheroku
 
cp app/views/home/_show.html.haml _show.html.haml
 
cp app/views/home/_show.html.haml _show.html.haml
Line 155: Line 183:
 
git add app/views/home/_show.html.haml
 
git add app/views/home/_show.html.haml
 
git commit -m "custom landing page"
 
git commit -m "custom landing page"
</pre>
+
</syntaxhighlight>
  
 
You can migrate modifications like so:
 
You can migrate modifications like so:
<pre>
+
<syntaxhighlight lang="bash">
 
git log oldheroku # Grab the commit SHAs you want to port over
 
git log oldheroku # Grab the commit SHAs you want to port over
 
git cherry-pick <commit-sha> # For each commit
 
git cherry-pick <commit-sha> # For each commit
</pre>
+
</syntaxhighlight>
 +
 
 
Ensure the new S3 variables are set correctly as in the "S3 Image and asset hosting" section above, if you want to use it.
 
Ensure the new S3 variables are set correctly as in the "S3 Image and asset hosting" section above, if you want to use it.
  
 
Deploy initially with the following:
 
Deploy initially with the following:
  
<pre>git push -fu heroku heroku:master</pre>
+
<syntaxhighlight lang="bash">
 +
git push -fu heroku heroku:master
 +
</syntaxhighlight>
  
Simple `git push`s should be enough for future deploys.
+
Simple <tt>git push</tt>s should be enough for future deploys.
  
 
[[Category:Podmin]]
 
[[Category:Podmin]]
 
[[Category:Installation]]
 
[[Category:Installation]]

Revision as of 16:18, 14 June 2013

»» Note
These instructions should are for Unix based operating systems. If you're on Windows you better get a virtual machine.


First deploy

We start with building a minimal pod entirely hosted on Heroku. It's good to have an RVM installation locally to leave your local system clean(er).

Fork Diaspora and clone your fork to your local machine. There checkout a custom branch for your pod, we'll name it heroku here.

cd diaspora
git checkout -b heroku origin/master

We need to swithc the Gemfile.lock to PostgreSQL. To update it, run

DB=postgres bundle --without development test heroku production assets
git add Gemfile.lock
git commit -m "switch Gemfile.lock to pg exclusivly"

Install the Heroku toolbelt.


Create an app, you must exchange diasporadev here and in all following cases with something unique:

heroku apps:create diasporadev

Enable required the addons:

heroku labs:enable user-env-compile
heroku addons:add redistogo:nano
heroku addons:add heroku-postgresql

And make the database available, replace the REPLACEME with corresponding part of HEROKU_POSTGRESQL_REPLACEME_URL that the last command gave you (or look it up with heroku config):

heroku pg:promote HEROKU_POSTGRESQL_REPLACEME

Set some basic configuration, remember to replace diasporadev:

heroku config:set HEROKU=true  ENVIRONMENT_URL=https://diasporadev.herokuapp.com/ ENVIRONMENT_ASSETS_SERVE=true SERVER_EMBED_SIDEKIQ_WORKER=true  ENVIRONMENT_CERTIFICATE_AUTHORITIES=/usr/lib/ssl/certs/ca-certificates.crt

You can now already go through config/diaspora.yml.example and add the settings you want to differ from the defaults (config/defaults.yml), converting them to environment variables as described at the top of the file.

Set a secure token:

heroku config:add SECRET_TOKEN=$(curl -s "http://www.random.org/cgi-bin/randbyte?nbytes=40&format=h" | tr -d " \n")

Now lets deploy:

git push -u heroku heroku:master

And load the schema:

heroku run rake db:schema:load


Restart to ensure you're not in the crashed state from the deploy with a unpopulated database:

heroku restart

That should give you a basic pod, to open it in your browser run

heroku open

Custom landing page

Edit .gitignore and remove the following line:

app/views/home/_show.*

Create your landing page as described in Custom Splash Page. Add it to your branch:

git add app/views/home/
git commit -m "custom landing page"

Deploy it:

git push heroku heroku:master

Amazon S3 Image and asset hosting

To enable image hosting, first set your S3 data:

 
heroku config:add ENVIRONMENT_S3_ENABLE=true ENVIRONMENT_S3_KEY=changeme ENVIRONMENT_S3_SECRET=changeme ENVIRONMENT_S3_BUCKET=changeme ENVIRONMENT_IMAGE_REDIRECT_URL=https://changeme.s3.amazonaws.com/

Change your region if it's different from the default:

heroku config:add ENVIRONMENT_S3_REGION=eu-west-1

To enable uploading assets to S3 and serving them from it:

heroku config:add ENVIRONMENT_ASSETS_UPLOAD=true ENVIRONMENT_ASSETS_HOST=https://changeme.s3.amazonaws.com

The assets should be uploaded with the next deploy. If that's not working run the following afterwards:

heroku run 'rails runner "AssetSync.sync"'

Amazon RDS Database hosting

heroku config:set DB=mysql

Grab commit SHA from switch to PostgreSQL and revert it:

git log --grep "switch Gemfile.lock to pg exclusivly" 
git revert <commit-sha from previous command>

Follow https://devcenter.heroku.com/articles/amazon_rds

Deploy.

Migrate existing installation

This isn't fool proof, think about what the commands do! Assuming you have committed to master and these commits are in your fork:

git branch -m master oldheroku
git remote add upstream git://github.com/diaspora/diaspora.git # if not done already
git fetch upstream
git checkout -b master upstream/master
git push -f origin master oldheroku
git checkout -b heroku origin/master

Heroku CLI is no longer in the Gemfile, instead make sure the Heroku toolbelt is installed.

Replace diasporadev with your appname everywhere.

heroku config:set HEROKU=true  ENVIRONMENT_URL=https://diasporadev.herokuapp.com/ ENVIRONMENT_ASSETS_SERVE=true SERVER_EMBED_SIDEKIQ_WORKER=true  ENVIRONMENT_CERTIFICATE_AUTHORITIES=/usr/lib/ssl/certs/ca-certificates.crt

Run heroku config to double check that SECRET_TOKEN is set, if not set one like above. Also check ifDB is set to the database you use ("postgres" or "mysql"). NO_SSL is now ENVIRONMENT_REQUIRE_SSL and to disable SSL you have set it to false.

Go through config/diaspora.yml.example and add the settings you want to differ from the defaults (config/defaults.yml), converting them to environment variables as described at the top of the file.

If you want your custom splash page back:

git checkout oldheroku
cp app/views/home/_show.html.haml _show.html.haml
git checkout heroku
nano .gitignore # remove app/views/home/_show.*
mv _show.html.haml app/views/home/
git add app/views/home/_show.html.haml
git commit -m "custom landing page"

You can migrate modifications like so:

git log oldheroku # Grab the commit SHAs you want to port over
git cherry-pick <commit-sha> # For each commit

Ensure the new S3 variables are set correctly as in the "S3 Image and asset hosting" section above, if you want to use it.

Deploy initially with the following:

git push -fu heroku heroku:master

Simple git pushs should be enough for future deploys.