rundoc 1.1.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/check_changelog.yml +16 -7
  3. data/.github/workflows/ci.yml +48 -0
  4. data/.standard.yml +6 -0
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +1 -1
  7. data/README.md +98 -5
  8. data/Rakefile +9 -10
  9. data/lib/rundoc/cli.rb +15 -17
  10. data/lib/rundoc/code_command/background/log/clear.rb +1 -1
  11. data/lib/rundoc/code_command/background/log/read.rb +1 -1
  12. data/lib/rundoc/code_command/background/process_spawn.rb +8 -9
  13. data/lib/rundoc/code_command/background/start.rb +7 -7
  14. data/lib/rundoc/code_command/background/stop.rb +1 -1
  15. data/lib/rundoc/code_command/background/wait.rb +2 -2
  16. data/lib/rundoc/code_command/background.rb +6 -6
  17. data/lib/rundoc/code_command/bash/cd.rb +6 -7
  18. data/lib/rundoc/code_command/bash.rb +10 -12
  19. data/lib/rundoc/code_command/file_command/append.rb +12 -16
  20. data/lib/rundoc/code_command/file_command/remove.rb +6 -9
  21. data/lib/rundoc/code_command/no_such_command.rb +0 -1
  22. data/lib/rundoc/code_command/pipe.rb +2 -5
  23. data/lib/rundoc/code_command/print/erb.rb +48 -0
  24. data/lib/rundoc/code_command/print/text.rb +33 -0
  25. data/lib/rundoc/code_command/raw.rb +1 -1
  26. data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -1
  27. data/lib/rundoc/code_command/rundoc/require.rb +2 -3
  28. data/lib/rundoc/code_command/rundoc_command.rb +3 -4
  29. data/lib/rundoc/code_command/website/driver.rb +17 -17
  30. data/lib/rundoc/code_command/website/navigate.rb +2 -2
  31. data/lib/rundoc/code_command/website/screenshot.rb +1 -1
  32. data/lib/rundoc/code_command/website/visit.rb +4 -5
  33. data/lib/rundoc/code_command/website.rb +4 -4
  34. data/lib/rundoc/code_command/write.rb +10 -11
  35. data/lib/rundoc/code_command.rb +28 -17
  36. data/lib/rundoc/code_section.rb +42 -25
  37. data/lib/rundoc/parser.rb +17 -19
  38. data/lib/rundoc/peg_parser.rb +57 -59
  39. data/lib/rundoc/version.rb +1 -1
  40. data/lib/rundoc.rb +10 -14
  41. data/rundoc.gemspec +19 -21
  42. data/test/fixtures/rails_4/rundoc.md +94 -30
  43. data/test/fixtures/rails_5/rundoc.md +69 -10
  44. data/test/fixtures/rails_6/rundoc.md +226 -165
  45. data/test/fixtures/rails_7/rundoc.md +477 -0
  46. data/test/integration/print_test.rb +194 -0
  47. data/test/rundoc/code_commands/append_file_test.rb +5 -8
  48. data/test/rundoc/code_commands/background_test.rb +3 -6
  49. data/test/rundoc/code_commands/bash_test.rb +7 -9
  50. data/test/rundoc/code_commands/pipe_test.rb +9 -9
  51. data/test/rundoc/code_commands/print_test.rb +94 -0
  52. data/test/rundoc/code_commands/remove_contents_test.rb +4 -5
  53. data/test/rundoc/code_section_test.rb +50 -56
  54. data/test/rundoc/parser_test.rb +28 -61
  55. data/test/rundoc/peg_parser_test.rb +49 -53
  56. data/test/rundoc/regex_test.rb +120 -127
  57. data/test/rundoc/test_parse_java.rb +1 -3
  58. data/test/test_helper.rb +4 -6
  59. metadata +39 -42
  60. data/.travis.yml +0 -8
  61. data/lib/rundoc/code_command/repl.rb +0 -37
@@ -5,6 +5,7 @@ email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`
5
5
  Rundoc.configure do |config|
6
6
  config.project_root = "myapp"
7
7
  config.filter_sensitive(email => "developer@example.com")
8
+ config.filter_sensitive(Dir.pwd => ".")
8
9
  end
9
10
  ```
10
11
 
@@ -16,66 +17,74 @@ end
16
17
  $ bin/rundoc build --path test/fixtures/rails_6/rundoc.md
17
18
  -->
18
19
 
19
- Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 6 on Heroku. For information on running previous versions of Rails on Heroku, see the tutorial for [Rails 5.x](getting-started-with-rails5) or [Rails 4.x](getting-started-with-rails4).
20
+ > warning
21
+ > The latest version of Rails available is [Rails 7](https://devcenter.heroku.com/articles/getting-started-with-rails7). If you're starting a new application, we recommend you use the most recently released version.
20
22
 
21
- ```
22
- :::-- $ ruby -e "exit 1 unless RUBY_VERSION == '2.6.6'"
23
- ```
23
+ Ruby on Rails is a popular web framework written in [Ruby](http://www.ruby-lang.org/). This guide covers using Rails 6 on Heroku. For information on running previous versions of Rails on Heroku, see the tutorial for [Rails 5.x](getting-started-with-rails5) or [Rails 4.x](getting-started-with-rails4).
24
24
 
25
- For this guide you will need:
25
+ The tutorial assumes that you have:
26
26
 
27
27
  - Basic familiarity with Ruby/Rails and Git
28
28
  - A locally installed version of Ruby 2.5.0+, Rubygems, Bundler, and Rails 6+
29
- - A Heroku user account: [Signup is free and instant](https://signup.heroku.com/devcenter).
29
+ - A locally installed version of the [Heroku CLI](heroku-cli#install-the-heroku-cli)
30
+ - A [verified Heroku Account](https://devcenter.heroku.com/articles/account-verification)
31
+ - A subscription to the [Eco dynos plan](eco-dyno-hours) (recommended)
30
32
 
31
- ## Local setup
33
+ >note
34
+ >Using dynos and databases to complete this tutorial counts towards your usage. We recommend using our [low-cost plans](https://blog.heroku.com/new-low-cost-plans) to complete this tutorial. Eligible students can apply for platform credits through our new [Heroku for GitHub Students program](https://blog.heroku.com/github-student-developer-program).
32
35
 
33
- Install the [Heroku CLI](heroku-cli#download-and-install) on your development machine.
36
+ ```
37
+ :::-- $ ruby -e "exit 1 unless RUBY_VERSION == '3.0.6'"
38
+ ```
34
39
 
35
- Once installed, the `heroku` command is available from your terminal. Log in using your Heroku account's email address and password:
40
+ ## Local Setup
41
+
42
+ After installing the [Heroku CLI](heroku-cli#install-the-heroku-cli), log in through your terminal:
36
43
 
37
44
  ```term
38
45
  $ heroku login
39
- heroku: Enter your Heroku credentials
40
- Email: schneems@example.com
41
- Password:
42
- Could not find an existing public key.
43
- Would you like to generate one? [Yn]
44
- Generating new SSH public key.
45
- Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
46
+ heroku: Press any key to open up the browser to login or q to exit
47
+ › Warning: If browser does not open, visit
48
+ › https://cli-auth.heroku.com/auth/browser/***
49
+ heroku: Waiting for login...
50
+ Logging in... done
51
+ Logged in as me@example.com
46
52
  ```
47
53
 
48
- Press Enter at the prompt to upload your existing `ssh` key or create a new one, used for pushing code later on.
54
+ This command opens your web browser to the Heroku login page. If your browser is already logged in to Heroku, click the **`Log in`** button on the page.
55
+
56
+ This authentication is required for the `heroku` and `git` commands to work correctly.
49
57
 
50
- ## Create a new Rails app (or upgrade an existing one)
58
+ ## Create a New or Upgrade an Existing Rails App
51
59
 
52
- To create a new app, first make sure that you're using Rails 6.x by running `rails -v`. If necessary, you can get the new version of rails by running the following:
60
+ Ensure that you're using Rails 6.x by running `rails -v`. If necessary, install it with this command:
53
61
 
54
62
  ```term
55
- :::>> $ gem install rails --no-document
63
+ :::>> $ gem install rails -v 6.1.7.3 --no-document
56
64
  ```
57
65
 
58
- Then create a new app and move into its root directory:
66
+ Create a Rails app:
59
67
 
60
68
  ```term
61
- :::>- $ rails new myapp --database=postgresql
69
+ :::>- $ rails _6.1.7.3_ new myapp --database=postgresql
62
70
  ```
63
71
 
64
- Then move into your application directory.
72
+ Move into the application directory and add the `x86_64-linux` and `ruby` platforms to `Gemfile.lock`.
65
73
 
66
74
  ```term
67
75
  :::>- $ cd myapp
76
+ :::>> $ bundle lock --add-platform x86_64-linux --add-platform ruby
68
77
  ```
69
78
 
70
- Create a database locally:
79
+ Create a local database:
71
80
 
72
81
  ```
73
82
  :::>> $ bin/rails db:create
74
83
  ```
75
84
 
76
- ## Add the pg gem
85
+ ## Add the pg Gem
77
86
 
78
- If you're using an existing app that was created without specifying `--database=postgresql`, you need to add the `pg` gem to your Rails project. Edit your `Gemfile` and change this line:
87
+ For new or existing apps where `--database=postgresql` isn’t defined, confirm the `sqlite3` gem doesn’t exist in the `Gemfile`. Add the `pg` gem in its place.
79
88
 
80
89
  ```ruby
81
90
  gem 'sqlite3'
@@ -87,34 +96,35 @@ To this:
87
96
  gem 'pg'
88
97
  ```
89
98
 
90
- > 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](heroku-postgresql#local-setup) now if it is not already on your system.
99
+ > callout
100
+ >Heroku highly recommends using PostgreSQL locally during development. Maintaining [parity between development](http://www.12factor.net/dev-prod-parity) and deployment environments prevents introducing subtle bugs due to the differences in environments.
101
+ >
102
+ > [Install Postgres locally](heroku-postgresql#local-setup). For more information on why Postgres is recommended instead of Sqlite3, see [why Sqlite3 is not compatible with Heroku](sqlite3).
91
103
 
92
- Now re-install your dependencies (to generate a new `Gemfile.lock`):
104
+ With the `Gemfile` updated, reinstall the dependencies:
93
105
 
94
106
  ```ruby
95
107
  $ bundle install
96
108
  ```
97
109
 
98
- For more information on why Postgres is recommended instead of Sqlite3, see [why you cannot use Sqlite3 on Heroku](sqlite3).
110
+ The installation also updates `Gemfile.lock` with the changes.
99
111
 
100
- In addition to using the `pg` gem, ensure that your `config/database.yml` file is using the `postgresql` adapter. The development section of your `config/database.yml` file should look something like this:
112
+ In addition to the `pg` gem, ensure that `config/database.yml` defines the `postgresql` adapter. The development section of `config/database.yml` file looks something like this:
101
113
 
102
114
  ```term
103
115
  :::>> $ cat config/database.yml
104
116
  ```
105
117
 
106
- Be careful here. If you omit the `sql` at the end of `postgresql` in the `adapter` section, your application will not work.
118
+ Be careful here. If the value of `adapter` is `postgres` and not `postgresql`, the application won’t work.
107
119
 
108
- ## Create a welcome page
120
+ ## Create a Welcome Page
109
121
 
110
- Rails 6 no longer has a static index page in production by default. 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:
122
+ Rails 6 no longer has a static index page in production by default. When you're using a new app, there isn't a root page in production, so you must create one. Create a controller called `welcome` for the home page:
111
123
 
112
124
  ```term
113
125
  :::>- $ rails generate controller welcome
114
126
  ```
115
127
 
116
- Next we'll add an index page:
117
-
118
128
  ```html
119
129
  :::>> file.write app/views/welcome/index.html.erb
120
130
  <h2>Hello World</h2>
@@ -123,7 +133,7 @@ Next we'll add an index page:
123
133
  </p>
124
134
  ```
125
135
 
126
- Now we need to make Rails route to this action. We'll edit `config/routes.rb` to set the index page to our new method:
136
+ Create a Rails route to this action. Edit `config/routes.rb` to set the index page to the new method:
127
137
 
128
138
  ```ruby
129
139
  :::>> file.append config/routes.rb#2
@@ -137,57 +147,59 @@ You can verify that the page is there by running your server:
137
147
  :::-- background.stop(name: "server")
138
148
  ```
139
149
 
140
- And visiting [http://localhost:3000](http://localhost:3000) in your browser. If you do not see the page, [use the logs](#view-logs) that are output to your server to debug.
141
-
142
- ## Heroku gems
150
+ Visit [http://localhost:3000](http://localhost:3000) in your browser. If you don't see the page, [use the logs](#view-application-logs) to debug. Rails outputs logs in the same terminal where `rails server` started.
143
151
 
144
- Previous versions of Rails required you to add a gem to your project [rails_12factor](https://github.com/heroku/rails_12factor) to enable static asset serving and logging on Heroku. If you are deploying a new application, this gem is not needed. If you are upgrading an existing application, you can remove this gem provided you have the appropriate configuration in your `config/environments/production.rb` file:
152
+ ## Specify the Ruby Version
145
153
 
154
+ Rails 6 requires Ruby 2.5.0 or above. Heroku has a recent version of Ruby installed by default. Specify an exact version with the `ruby` DSL in `Gemfile`. For example:
146
155
 
147
156
  ```ruby
148
- # config/environments/production.rb
149
- config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
150
-
151
- if ENV["RAILS_LOG_TO_STDOUT"].present?
152
- logger = ActiveSupport::Logger.new(STDOUT)
153
- logger.formatter = config.log_formatter
154
- config.logger = ActiveSupport::TaggedLogging.new(logger)
155
- end
157
+ :::-- $ sed -i'' -e '/^ruby/d' ./Gemfile
158
+ :::-> file.append Gemfile#4
159
+ ruby "3.0.6"
156
160
  ```
157
161
 
158
- ## Specify your Ruby version
162
+ Always use the same version of Ruby locally. Confirm the local version of ruby with `ruby -v`. Refer to the [Ruby Versions](ruby-versions) article for more details on defining a specific ruby version.
159
163
 
160
- Rails 6 requires Ruby 2.5.0 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`. Depending on your version of Ruby that you are currently running it might look like this:
164
+ ## Create a Procfile
161
165
 
166
+ Use a [Procfile](procfile), a text file in the root directory of your application, to explicitly declare what command to execute to start your app.
162
167
 
163
- ```ruby
164
- :::-- $ sed -i'' -e '/^ruby/d' ./Gemfile
165
- :::-> file.append Gemfile#4
166
- ruby "2.6.6"
168
+ This Procfile declares a single process type, `web`, and the command needed to run it. The name `web` is important here. It declares that this process type is attached to Heroku's [HTTP routing](http-routing) stack and receives web traffic when deployed.
169
+
170
+ By default, a Rails app’s web process runs `rails server`, which uses Puma in Rails 7. When you deploy a Rails 7 application without a Procfile, this command executes. However, we recommend explicitly declaring how to boot your server process via a Procfile.
171
+
172
+ ```
173
+ :::>> file.write Procfile
174
+ web: bundle exec puma -C config/puma.rb
167
175
  ```
168
176
 
169
- You should also be running the same version of Ruby locally. You can check this by running `$ ruby -v`. You can get more information on [specifying your Ruby version on Heroku here](https://devcenter.heroku.com/articles/ruby-versions).
177
+ >note
178
+ >The `Procfile` filename is case sensitive. There is no file extension.
179
+
180
+ If `config/puma.rb` doesn’t exist, create one using [Heroku’s Puma documentation](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server) for maximum performance.
181
+
182
+ A Procfile can contain additional process types. For example, you can declare a [background worker process](background-jobs-queueing#process-model) that processes items off a queue.
183
+
170
184
 
171
- ## Store your app in Git
185
+ ## Store The App in Git
172
186
 
173
- Heroku relies on [Git](http://git-scm.com/), a distributed source control management tool, for deploying your project. If your project is not already in Git, first verify that `git` is on your system:
187
+ Heroku relies on [Git](http://git-scm.com/), a distributed source control management tool, for deploying applications. If the application is not already in Git, first verify that `git` is on the system with `git --help`:
174
188
 
175
189
  ```term
176
190
  :::>- $ git --help
177
191
  :::>> | $ head -n 5
178
192
  ```
179
193
 
180
- If you don't see any output or get `command not found` you need to install Git on your system.
194
+ If the command produces no output or `command not found`, [install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
181
195
 
182
- Once you've verified that Git works, first make sure you are in your Rails app directory by running `$ ls`:
183
-
184
- The output should look like this:
196
+ Navigate to the root directory of the Rails app. Use the `ls` command to see its contents:
185
197
 
186
198
  ```term
187
199
  :::>> $ ls
188
200
  ```
189
201
 
190
- Now run these commands in your Rails app directory to initialize and commit your code to Git:
202
+ Within the Rails app directly, initialize a local empty Git repository and commit the app’s code:
191
203
 
192
204
  ```term
193
205
  :::>- $ git init
@@ -195,84 +207,145 @@ Now run these commands in your Rails app directory to initialize and commit your
195
207
  :::>- $ git commit -m "init"
196
208
  ```
197
209
 
198
- You can verify everything was committed correctly by running:
210
+ Verify everything committed correctly with `git status`:
199
211
 
200
212
  ```term
201
213
  :::>> $ git status
202
214
  ```
203
215
 
204
- Now that your application is committed to Git you can deploy to Heroku.
216
+ With the application committed to Git, it's ready to deploy to Heroku.
217
+
218
+ ## Fix a babel regression
205
219
 
206
- ## Deploy your application to Heroku
220
+ Rails 6 relies on the [webpacker gem](https://github.com/rails/webpacker) which uses babel as a dependency. Version 7.22.0 of [babel released a breaking change](https://github.com/babel/babel/issues/15679) in a minor version that caused new Rails 6.1.x apps to break. Rails 6 and webpacker are no longer receiving bug fixes so unless babel reverts the change, then you will need to workaround this bug in your new app.
207
221
 
208
- Make sure you are in the directory that contains your Rails app, then create an app on Heroku:
222
+ Test to see if your application is affected by this bug by running this command:
209
223
 
210
224
  ```term
211
- :::>> $ heroku create
225
+ :::>> $ rake webpacker:clobber webpacker:compile 2>&1 | grep "Cannot find package '@babel/plugin-proposal-private-methods'"
212
226
  ```
213
227
 
214
- You can verify that the remote was added to your project by running:
228
+ To fix this issue modify `babel.config.js`, replace `plugin-proposal-private-methods` with `plugin-transform-private-methods`:
229
+
230
+ ```diff
231
+ - '@babel/plugin-plugin-private-methods',
232
+ + '@babel/plugin-transform-private-methods',
233
+ ```
234
+
235
+ ```ruby
236
+ :::-- $ sed -i'' -e 's/plugin-proposal-private-methods/plugin-transform-private-methods/' ./babel.config.js
237
+ ```
238
+
239
+ Verify that it works correctly:
240
+
241
+ ```term
242
+ :::>- $ rake webpacker:clobber webpacker:compile
243
+ ```
244
+
245
+ Commit the fix to git:
246
+
247
+ ```
248
+ :::>- $ git add .
249
+ :::>- $ git commit -m "fix babel error"
250
+ ```
251
+
252
+ ## Create a Heroku App
253
+
254
+ >warning
255
+ >Using a dyno and a database to complete this tutorial counts towards your usage. [Delete your app](https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-apps-destroy), and [database](https://devcenter.heroku.com/articles/heroku-postgresql#removing-the-add-on) as soon as you're done to control costs.
256
+
257
+ To create an app on Heroku, use the Heroku CLI Inside the Rails app’s root directory:
258
+
259
+ ```term
260
+ :::>> $ heroku create --stack heroku-20
261
+ ```
262
+
263
+ When you create an app, a git remote called `heroku` is also created and associated with your local git repository. Git remotes are versions of your repository that live on other servers. You deploy your app by pushing its code to that special Heroku-hosted remote associated with your app. Verify the remote is set with `git config`:
215
264
 
216
265
  ```term
217
266
  :::>> $ git config --list --local | grep heroku
218
267
  ```
219
268
 
220
- If you see `fatal: not in a git directory` then you are likely not in the correct directory. Otherwise, you can deploy your code. After you deploy your code, you need to migrate your database, make sure it is properly scaled, and use logs to debug any issues that come up.
269
+ If the current directory is incorrect or Git isn't [initialized](#store-the-app-in-git), Git returns `fatal: not in a git directory`. If Git returns a list of remotes, it's ready to deploy.
221
270
 
222
271
  >note
223
272
  >Following changes in the industry, Heroku has updated our default git branch name to `main`. If the project you’re deploying uses `master` as its default branch name, use `git push heroku master`.
224
273
 
225
- Deploy your code:
274
+ ## Provision a Database
275
+
276
+ Provision a [Heroku Postgres](https://devcenter.heroku.com/articles/heroku-postgresql) database, one of the add-ons available through the [Elements Marketplace](https://www.heroku.com/elements/addons). Add-ons are cloud services that provide out-of-the-box additional services for your application, such as logging, monitoring, databases, and more.
277
+
278
+ >note
279
+ >A `mini` Postgres size costs [$5 a month, prorated to the minute](https://elements.heroku.com/addons/heroku-postgresql). At the end of this tutorial, we prompt you to [delete your database](https://devcenter.heroku.com/articles/heroku-postgresql#removing-the-add-on) to minimize costs.
280
+
281
+ ```term
282
+ :::>> $ heroku addons:create heroku-postgresql:mini
283
+ ```
284
+
285
+ Your Heroku app can now access this Postgres database. The `DATABASE_URL` environment variable stores your credentials, which Rails connects to by convention.
286
+
287
+ ## Deploy the App to Heroku
288
+
289
+ >warning
290
+ >Using a dyno to complete this tutorial counts towards your usage. [Delete your app](https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-apps-destroy) as soon as you're done to control costs.
291
+
292
+ Deploy your code. This command pushes the `main` branch of the sample repo to your `heroku` remote, which then deploys to Heroku:
226
293
 
227
294
  ```term
228
295
  :::>> $ git push heroku main
229
296
  ```
230
297
 
231
- 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.
298
+ If the output displays warnings or error messages, check the output and make adjustments.
232
299
 
233
- ## Migrate your database
300
+ After a successful deployment, complete these tasks as necessary:
234
301
 
235
- If you are using the database in your application, you need to manually migrate the database by running:
302
+ * Database migrations
303
+ * Scale your dynos
304
+ * Check the app’s logs if issues arise
305
+
306
+ ## Migrate The Database
307
+
308
+ If you're using a database in your application, trigger a migration by using the Heroku CLI to start a one-off [dyno](dynos). You can run commands, typically scripts and applications that are part of your app, in one-off dynos using the `heroku run` command. You can trigger a database migration with this command:
236
309
 
237
310
  ```term
238
311
  $ heroku run rake db:migrate
239
312
  ```
240
313
 
241
- Any commands after the `heroku run` are executed on a Heroku [dyno](dynos). You can obtain an interactive shell session by running `$ heroku run bash`.
242
-
243
- ## Visit your application
314
+ To use an interactive shell session instead, you can execute `heroku run bash`.
244
315
 
245
- You've deployed your code to Heroku. You can now instruct Heroku to execute a process type. Heroku does this by running the associated command in a [dyno](dynos), which is a lightweight container that is the basic unit of composition on Heroku.
316
+ ## Scale and Access the Application
246
317
 
247
- Let's ensure we have one dyno running the `web` process type:
318
+ Heroku runs application code using defined processes and [process types](procfile). New applications don't a process type active by default. The following command scales your app up to one dyno, running the `web` process:
248
319
 
249
320
  ```term
250
321
  :::>- $ heroku ps:scale web=1
251
322
  ```
252
323
 
253
- You can check the state of the app's dynos. The `heroku ps` command lists the running dynos of your application:
324
+ Use the Heroku CLI’s `ps` command to display the state of all app dynos in the terminal:
254
325
 
255
326
  ```term
256
327
  :::>> $ heroku ps
257
328
  ```
258
329
 
259
- Here, one dyno is running.
330
+ By default, apps use Eco dynos if you're subscribed to [Eco](eco-dyno-hours). Otherwise, it defaults to Basic dynos. The Eco dynos plan is shared across all Eco dynos in your account and is recommended if you plan on deploying many small apps to Heroku. Eco dynos sleep if they don't receive any traffic for half an hour. This sleep behavior causes a few seconds delay for the first request upon waking. Eco dynos consume from a monthly, account-level quota of [eco dyno hours](eco-dyno-hours). As long as you haven't exhausted the quota, your apps can continue to run.
260
331
 
261
- We can now visit the app in our browser with `heroku open`.
332
+ To avoid dyno sleeping, upgrade to a Basic or higher dyno type as described in the [Dyno Types](dyno-types) article. Upgrading to at least Standard dynos also allows you to scale up to multiple dynos per process type.
333
+
334
+ To launch the app in the browser, run `heroku open`:
262
335
 
263
336
  ```term
264
337
  :::>> $ heroku open
265
338
  ```
266
339
 
267
- You should now see the "Hello World" text we inserted above.
340
+ The browser displays the Hello World text. If it doesn't, or there's an error, [review and confirm the welcome page contents](#create-a-welcome-page).
268
341
 
269
- Heroku gives you a default web URL for simplicity while you are developing. When you are ready to scale up and use Heroku for production you can add your own [custom domain](https://devcenter.heroku.com/articles/custom-domains).
342
+ Heroku provides a [default web URL](app-names-and-subdomains) for every application during development. When the application is ready for production, add a [custom domain](https://devcenter.heroku.com/articles/custom-domains).
270
343
 
271
- ## View logs
344
+ ## View Application Logs
272
345
 
273
- If you run into any problems getting your app to perform properly, you will need to check the logs.
346
+ The app logs are a valuable tool if the app is not performing correctly or generating errors.
274
347
 
275
- You can view information about your running app using one of the [logging commands](logging), `heroku logs`:
348
+ View information about a running app using the Heroku CLI [logging command](logging), `heroku logs`. Here's example output:
276
349
 
277
350
  ```term
278
351
  :::>> $ heroku logs
@@ -284,15 +357,13 @@ You can also get the full stream of logs by running the logs command with the `-
284
357
  $ heroku logs --tail
285
358
  ```
286
359
 
287
- ## Dyno sleeping and scaling
288
-
289
- By default, new applications are deployed to a free dyno. Free apps will "sleep" to conserve resources. You can find more information about this behavior by reading about [free dyno behavior](free-dyno-hours).
360
+ By default, Heroku stores 1500 lines of logs from your application, but the full log stream is available as a service. Several [add-on providers](https://elements.heroku.com/addons/#logging) have logging services that provide things such as log persistence, search, and email and SMS alerts.
290
361
 
291
- 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.
362
+ ## Optional Steps
292
363
 
293
- ## Run the Rails console
364
+ ### Use The Rails Console
294
365
 
295
- 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:
366
+ Use the Heroku CLI `run` command to trigger [one-off dynos](one-off-dynos) to run scripts and applications only when necessary. Use the command to launch a Rails console process attached to the local terminal for experimenting in the app's environment:
296
367
 
297
368
  ```term
298
369
  $ heroku run rails console
@@ -300,59 +371,29 @@ irb(main):001:0> puts 1+1
300
371
  2
301
372
  ```
302
373
 
303
- Another useful command for debugging is `$ heroku run bash` which will spin up a new dyno and give you access to a bash session.
374
+ ### Run Rake Commands
304
375
 
305
- ## Run Rake commands
306
-
307
- Rake can be run as an attached process exactly like the console:
376
+ Run `rake` commands, such as `db:migrate`, using the `run` command exactly like the Rails console:
308
377
 
309
378
  ```term
310
379
  $ heroku run rake db:migrate
311
380
  ```
312
381
 
313
- ## Configure your webserver
314
-
315
- By default, your app's web process runs `rails server`, which uses Puma in Rails 6. If you are upgrading an app you'll need to add `puma` to your application `Gemfile`:
382
+ ### Use a Procfile locally
316
383
 
317
- ```ruby
318
- gem 'puma'
319
- ```
384
+ To use the `Procfile` locally, use the `heroku local` CLI command.
320
385
 
321
- Then run
322
-
323
- ```term
324
- :::>- $ bundle install
325
- ```
326
-
327
- Now you are ready to configure your app to use Puma. For this tutorial we will use the default `config/puma.rb` of that ships with Rails 6, but we recommend 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).
328
-
329
- Finally you will need to tell Heroku how to run your Rails app by creating a `Procfile` in the root of your application directory.
330
-
331
- ### Create a Procfile
332
-
333
- Change the command used to launch your web process by creating a file called [Procfile](procfile) and entering this:
334
-
335
- ```
336
- :::>> file.write Procfile
337
- web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
338
- ```
339
-
340
- > Note: This file must be named `Procfile` exactly.
341
-
342
- 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.
343
-
344
- To use the Procfile locally, you can use `heroku local`.
345
-
346
- In addition to running commands in your `Procfile` `heroku local` can also help you manage environment variables locally through a `.env` file. Set the local `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 environment your Heroku app will run in.
386
+ In addition to running commands in the `Procfile`, the `heroku local` command can also manage environment variables locally through a `.env` file. Set `RACK_ENV` to `development` for the local environment and the `PORT` for Puma.
347
387
 
348
388
  ```term
349
389
  :::>> $ echo "RACK_ENV=development" >>.env
350
390
  :::>> $ echo "PORT=3000" >> .env
351
391
  ```
352
392
 
353
- > Note: Another alternative to using environment variables locally with a `.env` file is the [dotenv](https://github.com/bkeepers/dotenv) gem.
393
+ >note
394
+ > Another alternative to using environment variables locally with a `.env` file is the [dotenv](https://github.com/bkeepers/dotenv) gem.
354
395
 
355
- You'll also want to add `.env` to your `.gitignore` since this is for local environment setup.
396
+ Add `.env` to `.gitignore` as these variables are for local environment setup only.
356
397
 
357
398
  ```term
358
399
  :::>- $ echo ".env" >> .gitignore
@@ -360,55 +401,46 @@ You'll also want to add `.env` to your `.gitignore` since this is for local envi
360
401
  :::>- $ git commit -m "add .env to .gitignore"
361
402
  ```
362
403
 
363
- If you're running Rails 6.0.0 you'll need to create a `tmp/pids` directory:
364
-
365
- ```term
366
- :::>> $ mkdir -p tmp/pids
367
- :::>> $ touch tmp/pids/.gitkeep
368
- ```
369
-
370
- Test your Procfile locally using Foreman. You can now start your web server by running:
404
+ Test the Procfile locally using [Foreman](heroku-local#run-your-app-locally-using-foreman)​​. Start the web server with `local`:
371
405
 
372
406
  ```term
373
407
  :::>> background.start("heroku local", name: "local", wait: "Ctrl-C to stop", timeout: 15)
374
408
  :::-- background.stop(name: "local")
375
409
  ```
376
410
 
377
- Looks good, so press `Ctrl+C` to exit and you can deploy your changes to Heroku:
411
+ Press `Ctrl+C` or `Cmd+C` to exit.
378
412
 
379
- ```term
380
- :::>- $ git add .
381
- :::>- $ git commit -m "use puma via procfile"
382
- :::>- $ git push heroku main || git push heroku master
383
- ```
413
+ ## Rails asset pipeline
384
414
 
385
- Check `ps`. You'll see that the web process uses your new command specifying Puma as the web server.
415
+ When deploying to Heroku, there are several options for invoking the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html). See the [Rails 3.1+ Asset Pipeline on Heroku Cedar](rails-asset-pipeline) article for general information on the asset pipeline.
386
416
 
387
- ```term
388
- :::>> $ heroku ps
389
- ```
417
+ Rails 6 removed the `config.assets.initialize_on_precompile` option because it's no longer needed. Additionally, any failure in asset compilation now causes the push to fail. For Rails 6 asset pipeline support, see the [Ruby Support](ruby-support#rails-5-x-applications) page.
390
418
 
391
- The logs also reflect that we are now using Puma.
419
+ ## Remove Heroku Gems
392
420
 
393
- ```term
394
- $ heroku logs
395
- ```
421
+ Previous versions of Rails required you to add a gem to your project [rails_12factor](https://github.com/heroku/rails_12factor) to enable static asset serving and logging on Heroku. If you are deploying a new application, this gem is not needed. If you are upgrading an existing application, you can remove this gem provided you have the appropriate configuration in your `config/environments/production.rb` file:
396
422
 
397
- ## Rails asset pipeline
398
423
 
399
- 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.
424
+ ```ruby
425
+ # config/environments/production.rb
426
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
400
427
 
401
- The `config.assets.initialize_on_precompile` option has been removed is and not needed for Rails 6. Also, any failure in asset compilation will now cause the push to fail. For Rails 6 asset pipeline support see the [Ruby Support](ruby-support#rails-5-x-applications) page.
428
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
429
+ logger = ActiveSupport::Logger.new(STDOUT)
430
+ logger.formatter = config.log_formatter
431
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
432
+ end
433
+ ```
402
434
 
403
435
  ## Troubleshooting
404
436
 
405
- If you push up your app and it crashes (`heroku ps` shows state `crashed`), check your logs to find out what went wrong. Here are some common problems.
437
+ If an app deployed to Heroku crashes, for example, `heroku ps` shows the state `crashed`, review the app’s logs. The following section covers common causes of app crashes.
406
438
 
407
- ### Runtime dependencies on development/test gems
439
+ ### Runtime Dependencies on Development or Test Gems
408
440
 
409
- 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.
441
+ If a gem is missing during deployment, check the Bundler groups. Heroku builds apps without the `development` or `test` groups, and if the app depends on a gem from one of these groups to run, move it out of the group.
410
442
 
411
- One common example is using the RSpec tasks in your `Rakefile`. If you see this in your Heroku deploy:
443
+ A common example is using the RSpec tasks in the `Rakefile`. The error often looks like this:
412
444
 
413
445
  ```term
414
446
  $ heroku run rake -T
@@ -416,7 +448,8 @@ Running `bundle exec rake -T` attached to terminal... up, ps.3
416
448
  rake aborted!
417
449
  no such file to load -- rspec/core/rake_task
418
450
  ```
419
- Then you've hit this problem. First, duplicate the problem locally:
451
+
452
+ First, duplicate the problem locally by running `bundle install` without the development or test gem groups:
420
453
 
421
454
  ```term
422
455
  $ bundle install --without development:test
@@ -426,9 +459,10 @@ rake aborted!
426
459
  no such file to load -- rspec/core/rake_task
427
460
  ```
428
461
 
429
- > Note: The `--without` option on bundler is sticky. You can get rid of this option by running `bundle config --delete without`.
462
+ >note
463
+ >The `--without` option on `bundler` is persistent. To remove this option, run `bundle config --delete without`.
430
464
 
431
- Now you can fix it by making these Rake tasks conditional on the gem load. For example:
465
+ Fix the error by making these Rake tasks conditional during gem load. For example:
432
466
 
433
467
  ```ruby
434
468
  begin
@@ -444,11 +478,38 @@ rescue LoadError
444
478
  end
445
479
  ```
446
480
 
447
- Confirm it works locally, then push to Heroku.
481
+ Confirm it works locally, then push it to Heroku.
448
482
 
449
- ## Next steps
483
+ ## Next Steps
450
484
 
451
- Congratulations! You have deployed your first Rails 6 application to Heroku. Here's some recommended reading:
485
+ Congratulations! You deployed your first Rails 6 application to Heroku. Review the following articles next:
452
486
 
453
487
  * Visit the [Ruby support category](/categories/ruby-support) to learn more about using Ruby and Rails on Heroku.
454
488
  * The [Deployment category](/categories/deployment) provides a variety of powerful integrations and features to help streamline and simplify your deployments.
489
+
490
+ ## Deleting Your App and Add-on
491
+
492
+ Remove the app and database from your account. You're only charged for the resources you used.
493
+
494
+ >warning
495
+ >This action removes your add-on and any data saved in the database.
496
+
497
+ ```term
498
+ $ heroku addons:destroy heroku-postgresql
499
+ ```
500
+
501
+ >warning
502
+ >This action permanently deletes your application
503
+
504
+ ```term
505
+ $ heroku apps:destroy
506
+ ```
507
+
508
+ You can confirm that your add-on and app are gone with the commands:
509
+
510
+ ```term
511
+ $ heroku addons --all
512
+ $ heroku apps -all
513
+ ```
514
+
515
+ You're now ready to <a href= "https://devcenter.heroku.com/articles/preparing-a-codebase-for-heroku-deployment" target= "_blank">deploy your app</a>.