rundoc 1.1.2 → 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 +12 -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 +12 -13
  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 +100 -33
  43. data/test/fixtures/rails_5/rundoc.md +77 -14
  44. data/test/fixtures/rails_6/rundoc.md +231 -167
  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 +12 -7
  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,77 +5,86 @@ 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
 
11
12
  <!--
12
13
  rundoc src:
13
- https://github.com/schneems/rundoc/blob/master/test/fixtures/rails_6/rundoc.md
14
+ https://github.com/schneems/rundoc/blob/main/test/fixtures/rails_6/rundoc.md
14
15
 
15
16
  Command:
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.
170
179
 
171
- ## Store your app in Git
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.
172
181
 
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:
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
+
184
+
185
+ ## Store The App in Git
186
+
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.
181
-
182
- Once you've verified that Git works, first make sure you are in your Rails app directory by running `$ ls`:
194
+ If the command produces no output or `command not found`, [install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
183
195
 
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,161 +207,193 @@ 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.
205
217
 
206
- ## Deploy your application to Heroku
218
+ ## Fix a babel regression
207
219
 
208
- Make sure you are in the directory that contains your Rails app, then create an app on 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.
221
+
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`:
215
229
 
216
- ```term
217
- :::>> $ git config --list | grep heroku
230
+ ```diff
231
+ - '@babel/plugin-plugin-private-methods',
232
+ + '@babel/plugin-transform-private-methods',
218
233
  ```
219
234
 
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.
235
+ ```ruby
236
+ :::-- $ sed -i'' -e 's/plugin-proposal-private-methods/plugin-transform-private-methods/' ./babel.config.js
237
+ ```
221
238
 
222
- Deploy your code:
239
+ Verify that it works correctly:
223
240
 
224
241
  ```term
225
- :::>> $ git push heroku main || git push heroku master
242
+ :::>- $ rake webpacker:clobber webpacker:compile
226
243
  ```
227
244
 
228
- 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.
245
+ Commit the fix to git:
229
246
 
230
- ## Migrate your database
231
-
232
- If you are using the database in your application, you need to manually migrate the database by running:
233
-
234
- ```term
235
- $ heroku run rake db:migrate
247
+ ```
248
+ :::>- $ git add .
249
+ :::>- $ git commit -m "fix babel error"
236
250
  ```
237
251
 
238
- 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`.
239
-
240
- ## Visit your application
252
+ ## Create a Heroku App
241
253
 
242
- 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.
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.
243
256
 
244
- Let's ensure we have one dyno running the `web` process type:
257
+ To create an app on Heroku, use the Heroku CLI Inside the Rails app’s root directory:
245
258
 
246
259
  ```term
247
- :::>- $ heroku ps:scale web=1
260
+ :::>> $ heroku create --stack heroku-20
248
261
  ```
249
262
 
250
- You can check the state of the app's dynos. The `heroku ps` command lists the running dynos of your application:
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`:
251
264
 
252
265
  ```term
253
- :::>> $ heroku ps
266
+ :::>> $ git config --list --local | grep heroku
254
267
  ```
255
268
 
256
- Here, one dyno is running.
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.
270
+
271
+ >note
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`.
273
+
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.
257
277
 
258
- We can now visit the app in our browser with `heroku open`.
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.
259
280
 
260
281
  ```term
261
- :::>> $ heroku open
282
+ :::>> $ heroku addons:create heroku-postgresql:mini
262
283
  ```
263
284
 
264
- You should now see the "Hello World" text we inserted above.
265
-
266
- 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).
285
+ Your Heroku app can now access this Postgres database. The `DATABASE_URL` environment variable stores your credentials, which Rails connects to by convention.
267
286
 
268
- ## View logs
287
+ ## Deploy the App to Heroku
269
288
 
270
- If you run into any problems getting your app to perform properly, you will need to check the logs.
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.
271
291
 
272
- You can view information about your running app using one of the [logging commands](logging), `heroku logs`:
292
+ Deploy your code. This command pushes the `main` branch of the sample repo to your `heroku` remote, which then deploys to Heroku:
273
293
 
274
294
  ```term
275
- :::>> $ heroku logs
295
+ :::>> $ git push heroku main
276
296
  ```
277
297
 
278
- You can also get the full stream of logs by running the logs command with the `--tail` flag option like this:
298
+ If the output displays warnings or error messages, check the output and make adjustments.
299
+
300
+ After a successful deployment, complete these tasks as necessary:
301
+
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:
279
309
 
280
310
  ```term
281
- $ heroku logs --tail
311
+ $ heroku run rake db:migrate
282
312
  ```
283
313
 
284
- ## Dyno sleeping and scaling
314
+ To use an interactive shell session instead, you can execute `heroku run bash`.
285
315
 
286
- 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).
316
+ ## Scale and Access the Application
287
317
 
288
- 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.
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:
289
319
 
290
- ## Run the Rails console
320
+ ```term
321
+ :::>- $ heroku ps:scale web=1
322
+ ```
291
323
 
292
- 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:
324
+ Use the Heroku CLI’s `ps` command to display the state of all app dynos in the terminal:
293
325
 
294
326
  ```term
295
- $ heroku run rails console
296
- irb(main):001:0> puts 1+1
297
- 2
327
+ :::>> $ heroku ps
298
328
  ```
299
329
 
300
- Another useful command for debugging is `$ heroku run bash` which will spin up a new dyno and give you access to a bash session.
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.
301
331
 
302
- ## Run Rake commands
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.
303
333
 
304
- Rake can be run as an attached process exactly like the console:
334
+ To launch the app in the browser, run `heroku open`:
305
335
 
306
336
  ```term
307
- $ heroku run rake db:migrate
337
+ :::>> $ heroku open
308
338
  ```
309
339
 
310
- ## Configure your webserver
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).
311
341
 
312
- 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`:
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).
313
343
 
314
- ```ruby
315
- gem 'puma'
344
+ ## View Application Logs
345
+
346
+ The app logs are a valuable tool if the app is not performing correctly or generating errors.
347
+
348
+ View information about a running app using the Heroku CLI [logging command](logging), `heroku logs`. Here's example output:
349
+
350
+ ```term
351
+ :::>> $ heroku logs
316
352
  ```
317
353
 
318
- Then run
354
+ You can also get the full stream of logs by running the logs command with the `--tail` flag option like this:
319
355
 
320
356
  ```term
321
- :::>- $ bundle install
357
+ $ heroku logs --tail
322
358
  ```
323
359
 
324
- 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).
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.
325
361
 
326
- Finally you will need to tell Heroku how to run your Rails app by creating a `Procfile` in the root of your application directory.
362
+ ## Optional Steps
327
363
 
328
- ### Create a Procfile
364
+ ### Use The Rails Console
329
365
 
330
- Change the command used to launch your web process by creating a file called [Procfile](procfile) and entering this:
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:
331
367
 
368
+ ```term
369
+ $ heroku run rails console
370
+ irb(main):001:0> puts 1+1
371
+ 2
332
372
  ```
333
- :::>> file.write Procfile
334
- web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
335
- ```
336
373
 
337
- > Note: This file must be named `Procfile` exactly.
374
+ ### Run Rake Commands
375
+
376
+ Run `rake` commands, such as `db:migrate`, using the `run` command exactly like the Rails console:
377
+
378
+ ```term
379
+ $ heroku run rake db:migrate
380
+ ```
338
381
 
339
- 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.
382
+ ### Use a Procfile locally
340
383
 
341
- To use the Procfile locally, you can use `heroku local`.
384
+ To use the `Procfile` locally, use the `heroku local` CLI command.
342
385
 
343
- 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.
344
387
 
345
388
  ```term
346
389
  :::>> $ echo "RACK_ENV=development" >>.env
347
390
  :::>> $ echo "PORT=3000" >> .env
348
391
  ```
349
392
 
350
- > 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.
351
395
 
352
- 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.
353
397
 
354
398
  ```term
355
399
  :::>- $ echo ".env" >> .gitignore
@@ -357,55 +401,46 @@ You'll also want to add `.env` to your `.gitignore` since this is for local envi
357
401
  :::>- $ git commit -m "add .env to .gitignore"
358
402
  ```
359
403
 
360
- If you're running Rails 6.0.0 you'll need to create a `tmp/pids` directory:
361
-
362
- ```term
363
- :::>> $ mkdir -p tmp/pids
364
- :::>> $ touch tmp/pids/.gitkeep
365
- ```
366
-
367
- 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`:
368
405
 
369
406
  ```term
370
407
  :::>> background.start("heroku local", name: "local", wait: "Ctrl-C to stop", timeout: 15)
371
408
  :::-- background.stop(name: "local")
372
409
  ```
373
410
 
374
- 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.
375
412
 
376
- ```term
377
- :::>- $ git add .
378
- :::>- $ git commit -m "use puma via procfile"
379
- :::>- $ git push heroku main || git push heroku master
380
- ```
413
+ ## Rails asset pipeline
381
414
 
382
- 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.
383
416
 
384
- ```term
385
- :::>> $ heroku ps
386
- ```
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.
387
418
 
388
- The logs also reflect that we are now using Puma.
419
+ ## Remove Heroku Gems
389
420
 
390
- ```term
391
- $ heroku logs
392
- ```
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:
393
422
 
394
- ## Rails asset pipeline
395
423
 
396
- 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?
397
427
 
398
- 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
+ ```
399
434
 
400
435
  ## Troubleshooting
401
436
 
402
- 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.
403
438
 
404
- ### Runtime dependencies on development/test gems
439
+ ### Runtime Dependencies on Development or Test Gems
405
440
 
406
- 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.
407
442
 
408
- 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:
409
444
 
410
445
  ```term
411
446
  $ heroku run rake -T
@@ -413,7 +448,8 @@ Running `bundle exec rake -T` attached to terminal... up, ps.3
413
448
  rake aborted!
414
449
  no such file to load -- rspec/core/rake_task
415
450
  ```
416
- 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:
417
453
 
418
454
  ```term
419
455
  $ bundle install --without development:test
@@ -423,9 +459,10 @@ rake aborted!
423
459
  no such file to load -- rspec/core/rake_task
424
460
  ```
425
461
 
426
- > 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`.
427
464
 
428
- 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:
429
466
 
430
467
  ```ruby
431
468
  begin
@@ -441,11 +478,38 @@ rescue LoadError
441
478
  end
442
479
  ```
443
480
 
444
- Confirm it works locally, then push to Heroku.
481
+ Confirm it works locally, then push it to Heroku.
445
482
 
446
- ## Next steps
483
+ ## Next Steps
447
484
 
448
- 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:
449
486
 
450
487
  * Visit the [Ruby support category](/categories/ruby-support) to learn more about using Ruby and Rails on Heroku.
451
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>.