Skip to content

Commit de5c91d

Browse files
author
Matt Swanson
committed
Add support for Heroku button; move docs around a bit
1 parent 5cf9cbb commit de5c91d

File tree

11 files changed

+96
-182
lines changed

11 files changed

+96
-182
lines changed

Gemfile

-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ group :development, :test do
2121
gem "shotgun", "~> 0.9.0"
2222
end
2323

24-
group :heroku do
25-
gem "excon", "~> 0.31.0"
26-
gem "formatador", "~> 0.2.4"
27-
gem "netrc", "~> 0.7.7"
28-
gem "rendezvous", "~> 0.0.2"
29-
end
30-
3124
gem "activerecord", "~> 4.0"
3225
# need to work around bug in 4.0.1 https://github.com/rails/arel/pull/216
3326
gem 'arel', git: 'git://github.com/rails/arel.git', branch: '4-0-stable'

Gemfile.lock

-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ GEM
4848
diff-lcs (1.2.5)
4949
docile (1.1.1)
5050
dotenv (0.9.0)
51-
excon (0.31.0)
5251
faker (1.2.0)
5352
i18n (~> 0.5)
5453
feedbag (0.9.2)
@@ -60,7 +59,6 @@ GEM
6059
foreman (0.63.0)
6160
dotenv (>= 0.7)
6261
thor (>= 0.13.6)
63-
formatador (0.2.4)
6462
highline (1.6.20)
6563
hpricot (0.8.6)
6664
i18n (0.6.9)
@@ -73,7 +71,6 @@ GEM
7371
mini_portile (0.5.2)
7472
minitest (4.7.5)
7573
multi_json (1.8.2)
76-
netrc (0.7.7)
7774
nokogiri (1.6.1)
7875
mini_portile (~> 0.5.0)
7976
pg (0.17.1)
@@ -94,7 +91,6 @@ GEM
9491
rack-test (>= 0.5)
9592
raindrops (0.12.0)
9693
rake (10.1.1)
97-
rendezvous (0.0.2)
9894
rest-client (1.6.7)
9995
mime-types (>= 1.16)
10096
rspec (2.14.1)
@@ -165,23 +161,19 @@ DEPENDENCIES
165161
coveralls (~> 0.7)
166162
delayed_job (~> 4.0)
167163
delayed_job_active_record (~> 4.0)
168-
excon (~> 0.31.0)
169164
faker (~> 1.2)
170165
feedbag (~> 0.9.2)
171166
feedjira (~> 1.3.0)
172167
foreman (~> 0.63.0)
173-
formatador (~> 0.2.4)
174168
highline (~> 1.6, >= 1.6.20)
175169
i18n (~> 0.6.9)
176170
loofah (~> 2.0.0)
177-
netrc (~> 0.7.7)
178171
nokogiri (~> 1.6)
179172
pg (~> 0.17.1)
180173
pry-byebug (~> 1.2)
181174
rack-test (~> 0.6.2)
182175
racksh (~> 1.0)
183176
rake (~> 10.1, >= 10.1.1)
184-
rendezvous (~> 0.0.2)
185177
rspec (~> 2.14, >= 2.14.1)
186178
rspec-html-matchers (~> 0.4.3)
187179
shotgun (~> 0.9.0)

README.md

+5-35
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,12 @@ But it does have keyboard shortcuts and was made with love!
1818

1919
Stringer is a Ruby (2.0.0+) app based on Sinatra, ActiveRecord, PostgreSQL, Backbone.js and DelayedJob.
2020

21-
Instructions are provided for deploying to Heroku (runs fine on the free plan) but Stringer can be deployed anywhere that supports Ruby (setup instructions for a Linux-based VPS are provided [here](/docs/VPS.md), and for OpenShift, provided [here](/docs/OpenShift.md)).
21+
[![Deploy to Heroku](https://cdn.herokuapp.com/deploy/button.svg)](https://heroku.com/deploy)
2222

23-
```sh
24-
git clone git://github.com/swanson/stringer.git
25-
cd stringer
26-
heroku create
27-
git push heroku master
28-
29-
heroku config:set APP_URL=`heroku apps:info | grep -o 'http[^"]*'`
30-
heroku config:set SECRET_TOKEN=`openssl rand -hex 20`
31-
32-
heroku run rake db:migrate
33-
heroku restart
34-
35-
heroku addons:add scheduler
36-
heroku addons:open scheduler
37-
```
38-
39-
Add an hourly task that runs `rake lazy_fetch` (if you are not on Heroku you may want `rake fetch_feeds` instead).
40-
41-
Load the app and follow the instructions to import your feeds and start using the app.
23+
Stringer will run just fine on the Heroku free plan.
4224

43-
---
44-
45-
In the event that you need to change your password, run `heroku run rake change_password` from the app folder.
46-
47-
## Updating the app
48-
49-
From the app's directory:
50-
51-
```sh
52-
git pull
53-
git push heroku master
54-
heroku run rake db:migrate
55-
heroku restart
56-
```
25+
Instructions are provided for deploying to [Heroku manually](/docs/Heroku.md), to any Ruby
26+
compatible [Linux-based VPS](/docs/VPS.md), and to [OpenShift](/docs/OpenShift.md).
5727

5828
## Niceties
5929

@@ -107,7 +77,7 @@ To set your locale on Heroku, run `heroku config:set LOCALE=en`.
10777

10878
If you would like to translate Stringer to your preferred language, please use [LocaleApp](http://www.localeapp.com/projects/4637).
10979

110-
### Clean up old read stories
80+
### Clean up old read stories on Heroku
11181

11282
If you are on the Heroku free plan, there is a 10k row limit so you will
11383
eventually run out of space.

Rakefile

+1-132
Original file line numberDiff line numberDiff line change
@@ -81,135 +81,4 @@ begin
8181
task :default => [:speedy_tests]
8282
rescue LoadError
8383
# allow for bundle install --without development:test
84-
end
85-
86-
desc "deploy stringer on Heroku"
87-
task :deploy do
88-
89-
require 'excon'
90-
require 'formatador'
91-
require 'json'
92-
require 'netrc'
93-
require 'rendezvous'
94-
require 'securerandom'
95-
96-
Formatador.display_line("[negative]<> deploying stringer to Heroku[/]")
97-
98-
# grab netrc credentials, set by toolbelt via `heroku login`
99-
Formatador.display_line("[negative]<> reading your global Heroku credentials from ~/.netrc (set when you ran heroku login)...[/]")
100-
_, password = Netrc.read['api.heroku.com']
101-
102-
# setup excon for API calls
103-
heroku = Excon.new(
104-
'https://api.heroku.com',
105-
:headers => {
106-
"Accept" => "application/vnd.heroku+json; version=3",
107-
"Authorization" => "Basic #{[':' << password].pack('m').delete("\r\n")}",
108-
"Content-Type" => "application/json"
109-
}
110-
)
111-
112-
#heroku create
113-
Formatador.display_line("[negative]<> creating app[/]")
114-
app_data = JSON.parse(heroku.post(:path => "/apps").body)
115-
116-
#git push heroku master
117-
Formatador.display_line("[negative]<> pushing code to [underline]#{app_data['name']}[/]")
118-
`git push git@heroku.com:#{app_data['name']}.git master`
119-
120-
heroku.reset # reset socket as git push may take long enough for timeout
121-
122-
#heroku config:set SECRET_TOKEN=`openssl rand -hex 20`
123-
Formatador.display_line("[negative]<> setting SECRET_TOKEN on [underline]#{app_data['name']}[/]")
124-
heroku.patch(
125-
:body => { "SECRET_TOKEN" => SecureRandom.hex(20) }.to_json,
126-
:path => "/apps/#{app_data['id']}/config-vars"
127-
)
128-
129-
#heroku run rake db:migrate
130-
Formatador.display_line("[negative]<> running `rake db:migrate` on [underline]#{app_data['name']}[/]")
131-
run_data = JSON.parse(heroku.post(
132-
:body => {
133-
"attach" => true,
134-
"command" => "rake db:migrate"
135-
}.to_json,
136-
:path => "/apps/#{app_data['id']}/dynos"
137-
).body)
138-
Rendezvous.start(
139-
:url => run_data['attach_url']
140-
)
141-
142-
heroku.reset # reset socket as db:migrate may take long enough for timeout
143-
144-
#heroku restart
145-
Formatador.display_line("[negative]<> restarting [underline]#{app_data['name']}[/]")
146-
heroku.delete(:path => "/apps/#{app_data['id']}/dynos")
147-
148-
#heroku addons:add scheduler
149-
Formatador.display_line("[negative]<> adding scheduler:standard to [underline]#{app_data['name']}[/]")
150-
heroku.post(
151-
:body => { "plan" => { "name" => "scheduler:standard" } }.to_json,
152-
:path => "/apps/#{app_data['id']}/addons"
153-
)
154-
155-
#heroku addons:open scheduler
156-
Formatador.display_lines([
157-
"[negative]<> Add `[bold]rake lazy_fetch[/][negative]` hourly task at [underline]https://api.heroku.com/apps/#{app_data['id']}/addons/scheduler:standard[/]",
158-
"[negative]<> Impatient? After adding feeds, immediately fetch the latest with `heroku run rake fetch_feeds -a #{app_data['name']}`",
159-
"[negative]<> stringer available at [underline]#{app_data['web_url']}[/]"
160-
])
161-
end
162-
163-
desc "update stringer on heroku"
164-
task :update, :app do |task, args|
165-
166-
require 'excon'
167-
require 'formatador'
168-
require 'json'
169-
require 'netrc'
170-
require 'rendezvous'
171-
172-
unless args.app
173-
Formatador.display_line("[negative]! Error: App required, please run as `bundle exec rake update[app]`[/]")
174-
exit
175-
end
176-
177-
Formatador.display_line("[negative]<> updating Heroku stringer on [underline]#{args.app}[/]")
178-
179-
# grab netrc credentials, set by toolbelt via `heroku login`
180-
Formatador.display_line("[negative]<> reading your global Heroku credentials from ~/.netrc (set when you ran heroku login)...[/]")
181-
_, password = Netrc.read['api.heroku.com']
182-
183-
# setup excon for API calls
184-
heroku = Excon.new(
185-
'https://api.heroku.com',
186-
:headers => {
187-
"Accept" => "application/vnd.heroku+json; version=3",
188-
"Authorization" => "Basic #{[':' << password].pack('m').delete("\r\n")}",
189-
"Content-Type" => "application/json"
190-
}
191-
)
192-
193-
#git push heroku master
194-
Formatador.display_line("[negative]<> pushing code to [underline]#{args.app}[/]")
195-
`git push git@heroku.com:#{args.app}.git master`
196-
197-
#heroku run rake db:migrate
198-
Formatador.display_line("[negative]<> running `rake db:migrate` on [underline]#{args.app}[/]")
199-
run_data = JSON.parse(heroku.post(
200-
:body => {
201-
"attach" => true,
202-
"command" => "rake db:migrate"
203-
}.to_json,
204-
:path => "/apps/#{args.app}/dynos"
205-
).body)
206-
Rendezvous.start(
207-
:url => run_data['attach_url']
208-
)
209-
210-
heroku.reset # reset socket as db:migrate may take long enough for timeout
211-
212-
#heroku restart
213-
Formatador.display_line("[negative]<> restarting [underline]#{args.app}[/]")
214-
heroku.delete(:path => "/apps/#{args.app}/dynos")
215-
end
84+
end

app.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "Stringer",
3+
"description": "A self-hosted, anti-social RSS reader.",
4+
"logo": "https://raw.githubusercontent.com/swanson/testing-hb/master/screenshots/logo.png",
5+
"keywords": [
6+
"RSS",
7+
"Ruby"
8+
],
9+
"website": "https://github.com/swanson/stringer",
10+
"success_url": "/heroku",
11+
"scripts": {
12+
"postdeploy": "rake db:migrate"
13+
},
14+
"env": {
15+
"SECRET_TOKEN": {
16+
"description": "Secret key used as the session secret",
17+
"generator": "secret"
18+
},
19+
"LOCALE": {
20+
"description": "Specify the translation locale you wish to use",
21+
"value": "en"
22+
}
23+
},
24+
"addons": [
25+
"scheduler:standard"
26+
]
27+
}

app/controllers/debug_controller.rb

+4
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ class Stringer < Sinatra::Base
77
pending_migrations: MigrationStatus.new.pending_migrations
88
}
99
end
10+
11+
get "/heroku" do
12+
erb :heroku
13+
end
1014
end

app/helpers/authentication_helpers.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def needs_authentication?(path)
1313
return false if !UserRepository.setup_complete?
1414
return false if path == "/login" || path == "/logout"
1515
return false if path =~ /css/ || path =~ /js/ || path =~ /img/
16+
return false if path == "/heroku"
1617
true
1718
end
1819

app/views/heroku.erb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="setup" id="heroku-setup">
2+
<h1><%= t('tutorial.heroku_one_more_thing') %></h1>
3+
4+
<p>
5+
<%= t('tutorial.heroku_hourly_task') %>
6+
</p>
7+
<p>
8+
<%= t('tutorial.heroku_scheduler') %>:
9+
</p>
10+
<pre>
11+
Task: rake lazy_fetch
12+
Dyno Size: 1X
13+
Frequency: Hourly
14+
</pre>
15+
</div>
16+
17+
<div class="center">
18+
<a href="/" id="start" class="btn btn-primary"><%= t('tutorial.ready') %></a>
19+
</div>

config/locales/en.yml

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ en:
142142
as_read: as read
143143
click_to_read: (click to read)
144144
description: We're getting you some stories to read, give us a second.
145+
heroku_hourly_task: You need to add an hourly task to check for new stories.
146+
heroku_one_more_thing: One more thing...
147+
heroku_scheduler: Go to the Heroku Scheduler and add this task
145148
mark_all: mark all
146149
ready: Okay, it's ready!
147150
refresh: refresh

docs/Heroku.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```sh
2+
git clone git://github.com/swanson/stringer.git
3+
cd stringer
4+
heroku create
5+
git push heroku master
6+
7+
heroku config:set APP_URL=`heroku apps:info | grep -o 'http[^"]*'`
8+
heroku config:set SECRET_TOKEN=`openssl rand -hex 20`
9+
10+
heroku run rake db:migrate
11+
heroku restart
12+
13+
heroku addons:add scheduler
14+
heroku addons:open scheduler
15+
```
16+
17+
Add an hourly task that runs `rake lazy_fetch` (if you are not on Heroku you may want `rake fetch_feeds` instead).
18+
19+
Load the app and follow the instructions to import your feeds and start using the app.
20+
21+
See the "Niceties" section of the README for a few more tips and tricks for getting the most out of Stringer on Heroku.
22+
23+
## Updating the app
24+
25+
From the app's directory:
26+
27+
```sh
28+
git pull
29+
git push heroku master
30+
heroku run rake db:migrate
31+
heroku restart
32+
```
33+
34+
## Password Reset
35+
36+
In the event that you need to change your password, run `heroku run rake change_password` from the app folder.

screenshots/logo.png

21.6 KB
Loading

0 commit comments

Comments
 (0)