rundoc 0.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/check_changelog.yml +13 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +22 -0
  6. data/Dockerfile +24 -0
  7. data/Gemfile +1 -0
  8. data/README.md +276 -74
  9. data/bin/rundoc +4 -52
  10. data/lib/rundoc.rb +15 -1
  11. data/lib/rundoc/cli.rb +84 -0
  12. data/lib/rundoc/code_command.rb +25 -6
  13. data/lib/rundoc/code_command/background.rb +9 -0
  14. data/lib/rundoc/code_command/background/log/clear.rb +17 -0
  15. data/lib/rundoc/code_command/background/log/read.rb +16 -0
  16. data/lib/rundoc/code_command/background/process_spawn.rb +96 -0
  17. data/lib/rundoc/code_command/background/start.rb +38 -0
  18. data/lib/rundoc/code_command/background/stop.rb +17 -0
  19. data/lib/rundoc/code_command/background/wait.rb +19 -0
  20. data/lib/rundoc/code_command/bash.rb +1 -1
  21. data/lib/rundoc/code_command/bash/cd.rb +21 -3
  22. data/lib/rundoc/code_command/file_command/append.rb +16 -11
  23. data/lib/rundoc/code_command/file_command/remove.rb +6 -5
  24. data/lib/rundoc/code_command/no_such_command.rb +4 -0
  25. data/lib/rundoc/code_command/pipe.rb +18 -5
  26. data/lib/rundoc/code_command/raw.rb +18 -0
  27. data/lib/rundoc/code_command/rundoc/depend_on.rb +37 -0
  28. data/lib/rundoc/code_command/rundoc/require.rb +41 -0
  29. data/lib/rundoc/code_command/rundoc_command.rb +6 -2
  30. data/lib/rundoc/code_command/website.rb +7 -0
  31. data/lib/rundoc/code_command/website/driver.rb +111 -0
  32. data/lib/rundoc/code_command/website/navigate.rb +29 -0
  33. data/lib/rundoc/code_command/website/screenshot.rb +28 -0
  34. data/lib/rundoc/code_command/website/visit.rb +47 -0
  35. data/lib/rundoc/code_command/write.rb +22 -7
  36. data/lib/rundoc/code_section.rb +41 -66
  37. data/lib/rundoc/parser.rb +5 -4
  38. data/lib/rundoc/peg_parser.rb +282 -0
  39. data/lib/rundoc/version.rb +2 -2
  40. data/rundoc.gemspec +9 -3
  41. data/test/fixtures/build_logs/rundoc.md +56 -0
  42. data/test/fixtures/depend_on/dependency/rundoc.md +5 -0
  43. data/test/fixtures/depend_on/main/rundoc.md +10 -0
  44. data/test/fixtures/java/rundoc.md +9 -0
  45. data/test/fixtures/rails_4/rundoc.md +151 -188
  46. data/test/fixtures/rails_5/rundoc.md +445 -0
  47. data/test/fixtures/rails_6/rundoc.md +451 -0
  48. data/test/fixtures/require/dependency/rundoc.md +5 -0
  49. data/test/fixtures/require/main/rundoc.md +10 -0
  50. data/test/fixtures/screenshot/rundoc.md +10 -0
  51. data/test/rundoc/code_commands/append_file_test.rb +33 -6
  52. data/test/rundoc/code_commands/background_test.rb +69 -0
  53. data/test/rundoc/code_commands/bash_test.rb +1 -1
  54. data/test/rundoc/code_commands/pipe_test.rb +1 -1
  55. data/test/rundoc/code_commands/remove_contents_test.rb +3 -4
  56. data/test/rundoc/code_section_test.rb +95 -2
  57. data/test/rundoc/parser_test.rb +7 -13
  58. data/test/rundoc/peg_parser_test.rb +381 -0
  59. data/test/rundoc/regex_test.rb +6 -6
  60. data/test/rundoc/test_parse_java.rb +1 -1
  61. data/test/test_helper.rb +1 -3
  62. metadata +143 -18
  63. data/Gemfile.lock +0 -38
@@ -1,3 +1,3 @@
1
1
  module Rundoc
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "1.1.1"
3
+ end
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Rundoc::VERSION
9
9
  gem.authors = ["Richard Schneeman"]
10
10
  gem.email = ["richard.schneeman+rubygems@gmail.com"]
11
- gem.description = %q{rundoc turns docs to runable code}
12
- gem.summary = %q{rundoc generates runable code from docs}
11
+ gem.description = %q{RunDOC turns docs to runable code}
12
+ gem.summary = %q{RunDOC generates runable code from docs}
13
13
  gem.homepage = "https://github.com/schneems/rundoc"
14
14
  gem.license = "MIT"
15
15
 
@@ -18,11 +18,17 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
-
22
21
  gem.add_dependency "thor"
23
22
  gem.add_dependency "repl_runner"
23
+ gem.add_dependency 'parslet', '~> 1'
24
+ gem.add_dependency 'capybara', '~> 3'
25
+ gem.add_dependency 'selenium-webdriver', '~> 3'
26
+
27
+ gem.add_dependency 'aws-sdk-s3', '~> 1'
28
+ gem.add_dependency 'dotenv'
24
29
 
25
30
  gem.add_development_dependency "rake"
26
31
  gem.add_development_dependency "mocha"
32
+ gem.add_development_dependency "minitest"
27
33
  end
28
34
 
@@ -0,0 +1,56 @@
1
+ Logs produced while building your application (deploying) are separated from your [runtime logs](https://devcenter.heroku.com/articles/logging#log-retrieval). The build logs for failed and successful deploys are available via the dashboard of the application.
2
+
3
+ ```
4
+ :::-- $ touch Gemfile
5
+ :::-- $ bundle _1.15.2_ install
6
+ :::-- $ git init && git add . && git commit -m first
7
+ :::-- $ heroku create
8
+ :::-- $ git push heroku master
9
+ ```
10
+
11
+ To view your build logs, first visit the dashboard for the application (`https://dashboard.heroku.com/apps/<app-name>`):
12
+
13
+ ```
14
+ :::>> website.visit(name: "dashboard", url: "https://dashboard.heroku.com", visible: true)
15
+
16
+ while current_url != "https://dashboard.heroku.com/apps"
17
+ puts "waiting for successful login: #{current_url}"
18
+ sleep 1
19
+ end
20
+
21
+ git_url = `git config --get remote.heroku.url`.chomp
22
+ app_name = git_url.split("/").last.gsub(".git", "")
23
+ session.visit "https://dashboard.heroku.com/apps/#{app_name}"
24
+ sleep 2
25
+
26
+ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
27
+ session.execute_script %Q{$("span:contains(#{email}").html('developer@example.com')}
28
+
29
+ :::>> website.screenshot(name: "dashboard", upload: "s3")
30
+ ```
31
+
32
+ Next click on the "Activity" tab:
33
+
34
+ ```
35
+ :::>> website.nav(name: "dashboard")
36
+ session.first(:link, "Activity").click
37
+ sleep 2
38
+
39
+ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
40
+ session.execute_script %Q{$("span:contains(#{email}").html('developer@example.com')}
41
+
42
+ :::>> website.screenshot(name: "dashboard", upload: "s3")
43
+ ```
44
+
45
+ From here you can click on "View build log" to see your most recent build:
46
+
47
+ ```
48
+ :::>> website.nav(name: "dashboard")
49
+ session.first(:link, "View build log").click
50
+ sleep 2
51
+
52
+ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
53
+ session.execute_script %Q{$("span:contains(#{email}").html('developer@example.com')}
54
+
55
+ :::>> website.screenshot(name: "dashboard", upload: "s3")
56
+ ```
@@ -0,0 +1,5 @@
1
+ ```
2
+ :::>> $ mkdir foo
3
+ :::>> $ cd foo
4
+ :::>> $ echo "hello" >> hello.txt
5
+ ```
@@ -0,0 +1,10 @@
1
+ # Hello
2
+
3
+ ```
4
+ :::-- rundoc.depend_on "../dependency/rundoc.md"
5
+ ```
6
+
7
+ ```
8
+ :::>> $ ruby -e "raise 'nope' unless File.read('hello.txt').chomp == 'hello'"
9
+ ```
10
+
@@ -0,0 +1,9 @@
1
+
2
+ Hello
3
+
4
+ ```
5
+ :::>- $ git clone https://github.com/heroku/java-getting-started
6
+ :::>- $ cd java-getting-started
7
+ ```
8
+
9
+ world
@@ -4,11 +4,18 @@ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
4
4
 
5
5
  Rundoc.configure do |config|
6
6
  config.project_root = "myapp"
7
- config.filter_sensitive(email, "developer@example.com")
7
+ config.filter_sensitive(email => "developer@example.com")
8
8
  end
9
9
  ```
10
+ <!--
11
+ rundoc src:
12
+ https://github.com/schneems/rundoc/blob/master/test/fixtures/rails_4/rundoc.md
13
+ -->
10
14
 
11
- Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 4 on Heroku, running previous versions of Rails on Heroku see [Getting Started with Rails 3.x on Heroku](https://devcenter.heroku.com/articles/rails3).
15
+ > warning
16
+ > The latest version of Rails available is [Rails 5](https://devcenter.heroku.com/articles/getting-started-with-rails5). If you are starting a new application we recommend you use the most recently released version.
17
+
18
+ Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 4 on Heroku. For information about running previous versions of Rails on Heroku, see [Getting Started with Rails 3.x on Heroku](getting-started-with-rails3).
12
19
 
13
20
  > callout If you are already familiar with Heroku and Rails, reference the [simplifed Rails 4 on Heroku guide](https://devcenter.heroku.com/articles/rails4) instead. For general information on how to develop and architect apps for use on Heroku, see [Architecting Applications for Heroku](https://devcenter.heroku.com/articles/architecting-apps).
14
21
 
@@ -17,18 +24,18 @@ For this guide you will need:
17
24
  - Basic Ruby/Rails knowledge
18
25
  - Locally installed version of Ruby 2.0.0+, Rubygems, Bundler, and Rails 4+
19
26
  - Basic Git knowledge
20
- - A Heroku user account: [Signup is free and instant](https://api.heroku.com/signup/devcenter)
27
+ - A Heroku user account: [Signup is free and instant](https://signup.heroku.com/devcenter)
21
28
 
22
29
  ## Local Workstation Setup
23
30
 
24
- Install the [Heroku Toolbelt](https://toolbelt.heroku.com/) on your local workstation. This ensures that you have access to the [Heroku command-line client](/categories/command-line), Foreman, and the Git revision control system. You will also need [Ruby and Rails installed](http://guides.railsgirls.com/install/).
31
+ Install the [Heroku Toolbelt](https://toolbelt.heroku.com/) on your local workstation. This ensures that you have access to the [Heroku command-line client](/categories/command-line), Foreman, and the Git revision control system. You will also need [Ruby and Rails installed](http://guides.railsgirls.com/install).
25
32
 
26
33
  Once installed, you'll have access to the `$ heroku` command from your command shell. Log in using the email address and password you used when creating your Heroku account:
27
34
 
28
35
 
29
36
  > callout Note that `$` symbol before commands indicates they should be run on the command line, prompt, or terminal with appropriate permissions. Do not copy the `$` symbol.
30
37
 
31
- ```sh
38
+ ```term
32
39
  $ heroku login
33
40
  Enter your Heroku credentials.
34
41
  Email: schneems@example.com
@@ -48,34 +55,80 @@ Press enter at the prompt to upload your existing `ssh` key or create a new one,
48
55
 
49
56
  You may be starting from an existing app, if so [upgrade to Rails 4](http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0) before continuing. If not, a vanilla Rails 4 app will serve as a suitable sample app. To build a new app make sure that you're using the Rails 4.x using `$ rails -v`. You can get the new version of rails by running,
50
57
 
51
- ```sh
52
- :::= $ gem install rails --no-ri --no-rdoc
58
+ ```term
59
+ :::>> $ gem install rails -v 4.2.9 --no-document
53
60
  ```
54
61
 
62
+ Note: There may be a [more recent version of Rails](https://rubygems.org/gems/rails/versions) available, we recommend always running the latest. You may want to [run Rails 5 on Heroku](https://devcenter.heroku.com/articles/getting-started-with-rails5).
63
+
55
64
  Then create a new app:
56
65
 
57
- ```sh
58
- ::: $ rails new myapp --database=postgresql
66
+ <!--
67
+ You may run into this bug when tring to use a
68
+ specific version of rails:
69
+
70
+ https://github.com/rubygems/rubygems/issues/1932#issuecomment-304133990
71
+ -->
72
+
73
+ ```term
74
+ $ rails new myapp --database=postgresql
75
+ :::- $ rails _4.2.9_ new myapp --database=postgresql
59
76
  ```
60
77
 
61
- Once finished change your directory to the newly created Rails app
78
+ Then move into your application directory.
62
79
 
63
- ```sh
64
- ::: $ cd myapp
80
+ ```term
81
+ :::> $ cd myapp
65
82
  ```
66
83
 
67
84
  > callout If you experience problems or get stuck with this tutorial, your questions may be answered in a later part of this document. Once you experience a problem try reading through the entire document and then going back to your issue. It can also be useful to review your previous steps to ensure they all executed correctly.
68
85
 
86
+ If already have an app that was created without specifying `--database=postgresql` you will need to add the `pg` gem to your Rails project. Edit your `Gemfile` and change this line:
87
+
88
+ ```ruby
89
+ gem 'sqlite3'
90
+ ```
91
+
92
+ To this:
93
+
94
+ ```ruby
95
+ gem 'pg'
96
+ ```
97
+
98
+ > callout We highly recommend using PostgreSQL during development. Maintaining [parity between your development](http://www.12factor.net/dev-prod-parity) and deployment environments prevents subtle bugs from being introduced because of differences between your environments. [Install Postgres locally](https://devcenter.heroku.com/articles/heroku-postgresql#local-setup) now if it is not allready on your system.
99
+
100
+ Now re-install your dependencies (to generate a new `Gemfile.lock`):
101
+
102
+ ```ruby
103
+ $ bundle install
104
+ ```
105
+
106
+ You can get more information on why this change is needed and how to configure your app to run postgres locally see [why you cannot use Sqlite3 on Heroku](https://devcenter.heroku.com/articles/sqlite3).
107
+
108
+ In addition to using the `pg` gem, you'll also need to ensure the `config/database.yml` is using the `postgresql` adapter.
109
+
110
+ The development section of your `config/database.yml` file should look something like this:
111
+
112
+ ```term
113
+ :::> $ cat config/database.yml
114
+ :::>> | $ head -n 23
115
+ ```
116
+
117
+ Be careful here, if you omit the `sql` at the end of `postgresql` in the `adapter` section your application will not work.
118
+
119
+ ## Welcome page
120
+
69
121
  Rails 4 no longer has a static index page in production. When you're using a new app, there will not be a root page in production, so we need to create one. We will first create a controller called `welcome` for our home page to live:
70
122
 
71
- ```sh
72
- ::: $ rails generate controller welcome
123
+
124
+ ```term
125
+ :::> $ rails generate controller welcome
73
126
  ```
74
127
 
75
128
  Next we'll add an index page.
76
129
 
77
- ```sh
78
- :::= file.write app/views/welcome/index.html.erb
130
+ ```html
131
+ :::>> file.write app/views/welcome/index.html.erb
79
132
  <h2>Hello World</h2>
80
133
  <p>
81
134
  The time is now: <%= Time.now %>
@@ -85,87 +138,42 @@ Next we'll add an index page.
85
138
  Now we need to have Rails route to this action. We'll edit `config/routes.rb` to set the index page to our new method:
86
139
 
87
140
  ```ruby
88
- :::= file.append config/routes.rb#2
141
+ :::>> file.append config/routes.rb#2
89
142
  root 'welcome#index'
90
143
  ```
91
144
 
92
145
  You can verify that the page is there by running your server:
93
146
 
94
- ```sh
147
+ ```term
95
148
  $ rails server
96
149
  ```
97
150
 
98
- And visiting [http://localhost:3000](http://localhost:3000) in your browser. If you do not see the page, use the logs that are output to your server to debug.
151
+ And visiting [http://localhost:3000](http://localhost:3000) in your browser. If you do not see the page, [use the logs](#view-the-logs) that are output to your server to debug.
99
152
 
100
153
  ## Heroku gems
101
154
 
102
155
  Heroku integration has previously relied on using the Rails plugin system, which has been removed from Rails 4. To enable features such as static asset serving and logging on Heroku please add `rails_12factor` gem to your `Gemfile`.
103
156
 
104
157
  ```ruby
105
- :::= file.append Gemfile
158
+ :::>> file.append Gemfile
106
159
  gem 'rails_12factor', group: :production
107
160
  ```
108
161
 
109
162
  Then run:
110
163
 
111
- ```sh
112
- ::: $ bundle install
164
+ ```term
165
+ :::> $ bundle install
113
166
  ```
114
167
 
115
168
  We talk more about Rails integration on our [Ruby Support page](https://devcenter.heroku.com/articles/ruby-support#injected-plugins).
116
169
 
117
- ## Use Postgres
118
-
119
- > callout We highly recommend using PostgreSQL during development. Maintaining [parity between your development](http://www.12factor.net/dev-prod-parity) and deployment environments prevents subtle bugs from being introduced because of differences between your environments. [Install Postgres locally](https://devcenter.heroku.com/articles/heroku-postgresql#local-setup) now if it is not allready on your system.
120
-
121
- If you did not specify `postgresql` while creating your app (using `--database=postgresql`) you will need to add the `pg` gem to your Rails project. Edit your `Gemfile` and change this line:
122
-
123
- ```ruby
124
- gem 'sqlite3'
125
- ```
126
-
127
- To this:
128
-
129
- ```ruby
130
- gem 'pg'
131
- ```
132
-
133
- You can get more information on why this change is needed and how to configure your app to run postgres locally see [why you cannot use Sqlite3 on Heroku](https://devcenter.heroku.com/articles/sqlite3).
134
-
135
- In addition to using the `pg` gem, you'll also need to ensure the `config/database.yml` is using the `postgresql` adapter.
136
-
137
- You will also need to remove the `username` field in your `database.yml` if there is one so:
138
-
139
- ```
140
- :::= file.remove config/database.yml
141
- username: myapp
142
- ```
143
-
144
- This line tells rails that the database `myapp_development` should be run under a role of `myapp`. Since you likely don't have this role in your database we will remove it. With the line remove Rails will try to access the database as user who is currently logged into the computer.
145
-
146
- The development section of your `config/database.yml` file should look something like this:
147
-
148
- ```sh
149
- ::: $ cat config/database.yml
150
- :::= | $ head -n 23
151
- ```
152
-
153
- Be careful here, if you omit the `sql` at the end of `postgresql` your application will not work.
154
-
155
- Now re-install your dependencies (to generate a new `Gemfile.lock`):
156
-
157
- ```ruby
158
- $ bundle install
159
- ```
160
-
161
170
  ## Specify Ruby version in app
162
171
 
163
-
164
- Rails 4 requires Ruby 1.9.3 or above. Heroku has a recent version of Ruby installed, however you can specify an exact version by using the `ruby` DSL in your `Gemfile`. For this guide we'll be using Ruby 2.0.0 so add this to your `Gemfile`:
172
+ Rails 4 requires Ruby 1.9.3 or above. Heroku has a recent version of Ruby installed by default, however you can specify an exact version by using the `ruby` DSL in your `Gemfile`. For this guide we'll be using Ruby 2.
165
173
 
166
174
  ```ruby
167
- :::= file.append Gemfile
168
- ruby "2.0.0"
175
+ :::>> file.append Gemfile
176
+ ruby "2.3.4"
169
177
  ```
170
178
 
171
179
  You should also be running the same version of Ruby locally. You can verify by running `$ ruby -v`. You can get more information on [specifying your Ruby version on Heroku here](https://devcenter.heroku.com/articles/ruby-versions).
@@ -174,37 +182,33 @@ You should also be running the same version of Ruby locally. You can verify by r
174
182
 
175
183
  Heroku relies on [git](http://git-scm.com/), a distributed source control managment tool, for deploying your project. If your project is not already in git first verify that `git` is on your system:
176
184
 
177
- ```sh
178
- ::: $ git --help
179
- :::= | $ head -n 10
185
+ ```term
186
+ :::> $ git --help
187
+ :::-> | $ head -n 5
180
188
  ```
181
189
 
182
190
  If you don't see any output or get `command not found` you will need to install it on your system, verify that the [Heroku toolbelt](https://toolbelt.heroku.com/) is installed.
183
191
 
184
- Once you've verified that git works, first make sure you are in your Rails app directory by running:
185
-
186
- ```sh
187
- $ ls
188
- ```
192
+ Once you've verified that git works, first make sure you are in your Rails app directory by running `$ ls`:
189
193
 
190
194
  The output should look like this:
191
195
 
192
- ```sh
193
- :::= $ ls
196
+ ```term
197
+ :::>> $ ls
194
198
  ```
195
199
 
196
200
  Now run these commands in your Rails app directory to initialize and commit your code to git:
197
201
 
198
- ```sh
199
- ::: $ git init
200
- ::: $ git add .
201
- ::: $ git commit -m "init"
202
+ ```term
203
+ :::> $ git init
204
+ :::> $ git add .
205
+ :::> $ git commit -m "init"
202
206
  ```
203
207
 
204
208
  You can verify everything was committed correctly by running:
205
209
 
206
- ```sh
207
- :::= $ git status
210
+ ```term
211
+ :::>> $ git status
208
212
  ```
209
213
 
210
214
  Now that your application is committed to git you can deploy to Heroku.
@@ -213,22 +217,22 @@ Now that your application is committed to git you can deploy to Heroku.
213
217
 
214
218
  Make sure you are in the directory that contains your Rails app, then create an app on Heroku:
215
219
 
216
- ```sh
217
- :::= $ heroku create
220
+ ```term
221
+ :::>> $ heroku create
218
222
  ```
219
223
 
220
224
  You can verify that the remote was added to your project by running
221
225
 
222
- ```sh
223
- $ git config -e
226
+ ```term
227
+ :::>> $ git config --list | grep heroku
224
228
  ```
225
229
 
226
- If you see `fatal: not in a git directory` then you are likely not in the corect directory. Otherwise you may deploy your code. After you deploy your code, you will need to migrate your database, make sure it is properly scaled and use logs to debug any issues that come up.
230
+ If you see `fatal: not in a git directory` then you are likely not in the correct directory. Otherwise you may deploy your code. After you deploy your code, you will need to migrate your database, make sure it is properly scaled and use logs to debug any issues that come up.
227
231
 
228
232
  Deploy your code:
229
233
 
230
- ```sh
231
- :::= $ git push heroku master
234
+ ```term
235
+ :::>> $ git push heroku master
232
236
  ```
233
237
 
234
238
  It is always a good idea to check to see if there are any warnings or errors in the output. If everything went well you can migrate your database.
@@ -237,12 +241,11 @@ It is always a good idea to check to see if there are any warnings or errors in
237
241
 
238
242
  If you are using the database in your application you need to manually migrate the database by running:
239
243
 
240
- ```sh
244
+ ```term
241
245
  $ heroku run rake db:migrate
242
246
  ```
243
247
 
244
- Any commands after the `heroku run` will be executed on a Heroku [dyno](dynos).
245
-
248
+ Any commands after the `heroku run` will be executed on a Heroku [dyno](dynos). You can obtain an interactive shell session by running `$ heroku run bash`.
246
249
 
247
250
  ## Visit your application
248
251
 
@@ -251,22 +254,22 @@ You've deployed your code to Heroku. You can now instruct Heroku to execute a pr
251
254
 
252
255
  Let's ensure we have one dyno running the `web` process type:
253
256
 
254
- ```sh
255
- ::: $ heroku ps:scale web=1
257
+ ```term
258
+ :::> $ heroku ps:scale web=1
256
259
  ```
257
260
 
258
261
  You can check the state of the app's dynos. The `heroku ps` command lists the running dynos of your application:
259
262
 
260
- ```sh
261
- :::= $ heroku ps
263
+ ```term
264
+ :::>> $ heroku ps
262
265
  ```
263
266
 
264
267
  Here, one dyno is running.
265
268
 
266
269
  We can now visit the app in our browser with `heroku open`.
267
270
 
268
- ```sh
269
- :::= $ heroku open
271
+ ```term
272
+ :::>> $ heroku open
270
273
  ```
271
274
 
272
275
  You should now see the "Hello World" text we inserted above.
@@ -279,37 +282,31 @@ If you run into any problems getting your app to perform properly, you will need
279
282
 
280
283
  You can view information about your running app using one of the [logging commands](logging), `heroku logs`:
281
284
 
282
- ```sh
283
- :::= $ heroku logs
285
+ ```term
286
+ :::>> $ heroku logs
284
287
  ```
285
288
 
286
289
  You can also get the full stream of logs by running the logs command with the `--tail` flag option like this:
287
290
 
288
- ```sh
291
+ ```term
289
292
  $ heroku logs --tail
290
293
  ```
291
294
 
292
295
  ## Dyno sleeping and scaling
293
296
 
294
- Having only a single web dyno running will result in the dyno [going to sleep](dynos#dyno-sleeping) after one hour of inactivity. This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally.
295
-
296
- To avoid this, you can scale to more than one web dyno. For example:
297
+ By default, your app is deployed on a free dyno. Free dynos will sleep after a half hour of inactivity and they can be active (receiving traffic) for no more than 18 hours a day before [going to sleep](dynos#dyno-sleeping). If a free dyno is sleeping, and it hasn't exceeded the 18 hours, any web request will wake it. This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally.
297
298
 
298
- ```sh
299
- $ heroku ps:scale web=2
300
- ```
301
-
302
- For each application, Heroku provides [750 free dyno-hours](usage-and-billing#750-free-dyno-hours-per-app). Running your app at 2 dynos would exceed this free, monthly allowance, so let's scale back:
303
-
304
- ```sh
299
+ ```term
305
300
  $ heroku ps:scale web=1
306
301
  ```
307
302
 
303
+ To avoid dyno sleeping, you can upgrade to a hobby or professional dyno type as described in the [Dyno Types](dyno-types) article. For example, if you migrate your app to a professional dyno, you can easily scale it by running a command telling Heroku to execute a specific number of dynos, each running your web process type.
304
+
308
305
  ## Console
309
306
 
310
- Heroku allows you to run commands in a [one-off dyno](oneoff-admin-ps) - scripts and applications that only need to be executed when needed - using the `heroku run` command. Use this to launch a Rails console process attached to your local terminal for experimenting in your app's environment:
307
+ Heroku allows you to run commands in a [one-off dyno](one-off-dynos) - scripts and applications that only need to be executed when needed - using the `heroku run` command. Use this to launch a Rails console process attached to your local terminal for experimenting in your app's environment:
311
308
 
312
- ```sh
309
+ ```term
313
310
  $ heroku run rails console
314
311
  irb(main):001:0> puts 1+1
315
312
  2
@@ -319,65 +316,28 @@ irb(main):001:0> puts 1+1
319
316
 
320
317
  Rake can be run as an attached process exactly like the console:
321
318
 
322
- ```sh
319
+ ```term
323
320
  $ heroku run rake db:migrate
324
321
  ```
325
322
 
326
323
  ## Webserver
327
324
 
328
- By default, your app's web process runs `rails server`, which uses Webrick. This is fine for testing, but for production apps you'll want to switch to a more robust webserver. On Cedar, [we recommend Unicorn as the webserver](ruby-production-web-server). Regardless of the webserver you choose, production apps should always specify the webserver explicitly in the `Procfile`.
325
+ By default, your app's web process runs `rails server`, which uses Webrick. This is fine for testing, but for production apps you'll want to switch to a more robust webserver. On Cedar, [we recommend Puma as the webserver](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server). Regardless of the webserver you choose, production apps should always specify the webserver explicitly in the `Procfile`.
329
326
 
330
- First, add Unicorn to your application `Gemfile`:
327
+ First, add Puma to your application `Gemfile`:
331
328
 
332
329
  ```ruby
333
- :::= file.append Gemfile
334
- gem 'unicorn'
330
+ :::>> file.append Gemfile
331
+ gem 'puma'
335
332
  ```
336
333
 
337
334
  Then run
338
335
 
339
- ```sh
340
- ::: $ bundle install
341
- ```
342
-
343
- Now you are ready to configure your app to use Unicorn.
344
-
345
- Create a configuration file for Unicorn at `config/unicorn.rb`:
346
-
347
- ```sh
348
- ::: $ touch config/unicorn.rb
349
- ```
350
-
351
- Now we're going to add Unicorn specific configuration options, that we explain in detail in [Heroku's Unicorn documentation](https://devcenter.heroku.com/articles/rails-unicorn):
352
-
353
- ```ruby
354
- :::= file.write config/unicorn.rb
355
-
356
- worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
357
- timeout 15
358
- preload_app true
359
-
360
- before_fork do |server, worker|
361
- Signal.trap 'TERM' do
362
- puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
363
- Process.kill 'QUIT', Process.pid
364
- end
365
-
366
- defined?(ActiveRecord::Base) and
367
- ActiveRecord::Base.connection.disconnect!
368
- end
369
-
370
- after_fork do |server, worker|
371
- Signal.trap 'TERM' do
372
- puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
373
- end
374
-
375
- defined?(ActiveRecord::Base) and
376
- ActiveRecord::Base.establish_connection
377
- end
336
+ ```term
337
+ :::> $ bundle install
378
338
  ```
379
339
 
380
- This default configuration assumes a standard Rails app with Active Record. You should get acquainted with the different options in [the official Unicorn documentation](http://unicorn.bogomips.org/Unicorn/Configurator.html).
340
+ Now you are ready to configure your app to use Puma. For this tutorial we will use the default settings of Puma, but we recommend generating a `config/puma.rb` file and reading more about configuring your application for maximum performance by [reading the Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server)
381
341
 
382
342
  Finally you will need to tell Heroku how to run your Rails app by creating a `Procfile` in the root of your application directory.
383
343
 
@@ -386,36 +346,40 @@ Finally you will need to tell Heroku how to run your Rails app by creating a `Pr
386
346
  Change the command used to launch your web process by creating a file called [Procfile](procfile) and entering this:
387
347
 
388
348
  ```
389
- :::= file.write Procfile
390
- web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
349
+ :::>> file.write Procfile
350
+ web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
391
351
  ```
392
352
 
393
353
  Note: The case of `Procfile` matters, the first letter must be uppercase.
394
354
 
355
+
356
+ We recommend generating a puma config file based on [our Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server) for maximum performance.
357
+
358
+
395
359
  Set the `RACK_ENV` to development in your environment and a `PORT` to connect to. Before pushing to Heroku you'll want to test with the `RACK_ENV` set to production since this is the enviroment your Heroku app will run in.
396
360
 
397
- ```sh
398
- :::= $ echo "RACK_ENV=development" >>.env
399
- :::= $ echo "PORT=3000" >> .env
361
+ ```term
362
+ :::>> $ echo "RACK_ENV=development" >>.env
363
+ :::>> $ echo "PORT=3000" >> .env
400
364
  ```
401
365
 
402
366
  You'll also want to add `.env` to your `.gitignore` since this is for local enviroment setup.
403
367
 
404
- ```sh
405
- ::: $ echo ".env" >> .gitignore
406
- ::: $ git add .gitignore
407
- ::: $ git commit -m "add .env to .gitignore"
368
+ ```term
369
+ :::> $ echo ".env" >> .gitignore
370
+ :::> $ git add .gitignore
371
+ :::> $ git commit -m "add .env to .gitignore"
408
372
  ```
409
373
 
410
374
  Test your Procfile locally using Foreman:
411
375
 
412
- ```sh
413
- ::: $ gem install foreman
376
+ ```term
377
+ :::> $ gem install foreman
414
378
  ```
415
379
 
416
380
  You can now start your web server by running
417
381
 
418
- ```sh
382
+ ```term
419
383
  $ foreman start
420
384
  18:24:56 web.1 | I, [2013-03-13T18:24:56.885046 #18793] INFO -- : listening on addr=0.0.0.0:5000 fd=7
421
385
  18:24:56 web.1 | I, [2013-03-13T18:24:56.885140 #18793] INFO -- : worker=0 spawning...
@@ -427,27 +391,27 @@ $ foreman start
427
391
 
428
392
  Looks good, so press Ctrl-C to exit and you can deploy your changes to Heroku:
429
393
 
430
- ```sh
431
- ::: $ git add .
432
- ::: $ git commit -m "use unicorn via procfile"
433
- ::: $ git push heroku master
394
+ ```term
395
+ :::> $ git add .
396
+ :::> $ git commit -m "use puma via procfile"
397
+ :::> $ git push heroku master
434
398
  ```
435
399
 
436
- Check `ps`, you'll see the web process uses your new command specifying Unicorn as the web server
400
+ Check `ps`, you'll see the web process uses your new command specifying Puma as the web server
437
401
 
438
- ```sh
439
- :::= $ heroku ps
402
+ ```term
403
+ :::>> $ heroku ps
440
404
  ```
441
405
 
442
- The logs also reflect that we are now using Unicorn:
406
+ The logs also reflect that we are now using Puma:
443
407
 
444
- ```sh
408
+ ```term
445
409
  $ heroku logs
446
410
  ```
447
411
 
448
412
  ## Rails Asset Pipeline
449
413
 
450
- There are several options for invoking the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html) when deploying to Heroku. For general information on the asset pipeline please see the [Rails 3.1+ Asset Pipeline on Heroku Cedar](rails3x-asset-pipeline-cedar) article.
414
+ There are several options for invoking the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html) when deploying to Heroku. For general information on the asset pipeline please see the [Rails 3.1+ Asset Pipeline on Heroku Cedar](rails-asset-pipeline) article.
451
415
 
452
416
  The `config.assets.initialize_on_precompile` option has been removed is and not needed for Rails 4. Also, any failure in asset compilation will now cause the push to fail. For Rails 4 asset pipeline support see the [Ruby Support](https://devcenter.heroku.com/articles/ruby-support#rails-4-x-applications) page.
453
417
 
@@ -457,11 +421,11 @@ If you push up your app and it crashes (`heroku ps` shows state `crashed`), chec
457
421
 
458
422
  ### Runtime dependencies on development/test gems
459
423
 
460
- If you're missing a gem when you deploy, check your Bundler groups. Heroku builds your app without the `development` or `test` groups, and if you app depends on a gem from one of these groups to run, you should move it out of the group.
424
+ If you're missing a gem when you deploy, check your Bundler groups. Heroku builds your app without the `development` or `test` groups, and if your app depends on a gem from one of these groups to run, you should move it out of the group.
461
425
 
462
426
  One common example using the RSpec tasks in your `Rakefile`. If you see this in your Heroku deploy:
463
427
 
464
- ```sh
428
+ ```term
465
429
  $ heroku run rake -T
466
430
  Running `bundle exec rake -T` attached to terminal... up, ps.3
467
431
  rake aborted!
@@ -470,7 +434,7 @@ no such file to load -- rspec/core/rake_task
470
434
 
471
435
  Then you've hit this problem. First, duplicate the problem locally:
472
436
 
473
- ```sh
437
+ ```term
474
438
  $ bundle install --without development:test
475
439
 
476
440
  $ bundle exec rake -T
@@ -498,7 +462,6 @@ end
498
462
 
499
463
  Confirm it works locally, then push to Heroku.
500
464
 
501
-
502
465
  ## Done
503
466
 
504
467
  You now have your first application deployed to Heroku. The next step is to deploy your own application. If you're interested in reading more you can read more about [Ruby on Heroku at the Devcenter](https://devcenter.heroku.com/categories/ruby).