rundoc 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check_changelog.yml +16 -7
- data/.github/workflows/ci.yml +48 -0
- data/.standard.yml +6 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +1 -1
- data/README.md +98 -5
- data/Rakefile +9 -10
- data/lib/rundoc/cli.rb +15 -17
- data/lib/rundoc/code_command/background/log/clear.rb +1 -1
- data/lib/rundoc/code_command/background/log/read.rb +1 -1
- data/lib/rundoc/code_command/background/process_spawn.rb +8 -9
- data/lib/rundoc/code_command/background/start.rb +7 -7
- data/lib/rundoc/code_command/background/stop.rb +1 -1
- data/lib/rundoc/code_command/background/wait.rb +2 -2
- data/lib/rundoc/code_command/background.rb +6 -6
- data/lib/rundoc/code_command/bash/cd.rb +6 -7
- data/lib/rundoc/code_command/bash.rb +12 -13
- data/lib/rundoc/code_command/file_command/append.rb +12 -16
- data/lib/rundoc/code_command/file_command/remove.rb +6 -9
- data/lib/rundoc/code_command/no_such_command.rb +0 -1
- data/lib/rundoc/code_command/pipe.rb +2 -5
- data/lib/rundoc/code_command/print/erb.rb +48 -0
- data/lib/rundoc/code_command/print/text.rb +33 -0
- data/lib/rundoc/code_command/raw.rb +1 -1
- data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -1
- data/lib/rundoc/code_command/rundoc/require.rb +2 -3
- data/lib/rundoc/code_command/rundoc_command.rb +3 -4
- data/lib/rundoc/code_command/website/driver.rb +17 -17
- data/lib/rundoc/code_command/website/navigate.rb +2 -2
- data/lib/rundoc/code_command/website/screenshot.rb +1 -1
- data/lib/rundoc/code_command/website/visit.rb +4 -5
- data/lib/rundoc/code_command/website.rb +4 -4
- data/lib/rundoc/code_command/write.rb +10 -11
- data/lib/rundoc/code_command.rb +28 -17
- data/lib/rundoc/code_section.rb +42 -25
- data/lib/rundoc/parser.rb +17 -19
- data/lib/rundoc/peg_parser.rb +57 -59
- data/lib/rundoc/version.rb +1 -1
- data/lib/rundoc.rb +10 -14
- data/rundoc.gemspec +19 -21
- data/test/fixtures/rails_4/rundoc.md +100 -33
- data/test/fixtures/rails_5/rundoc.md +77 -14
- data/test/fixtures/rails_6/rundoc.md +231 -167
- data/test/fixtures/rails_7/rundoc.md +477 -0
- data/test/integration/print_test.rb +194 -0
- data/test/rundoc/code_commands/append_file_test.rb +5 -8
- data/test/rundoc/code_commands/background_test.rb +3 -6
- data/test/rundoc/code_commands/bash_test.rb +12 -7
- data/test/rundoc/code_commands/pipe_test.rb +9 -9
- data/test/rundoc/code_commands/print_test.rb +94 -0
- data/test/rundoc/code_commands/remove_contents_test.rb +4 -5
- data/test/rundoc/code_section_test.rb +50 -56
- data/test/rundoc/parser_test.rb +28 -61
- data/test/rundoc/peg_parser_test.rb +49 -53
- data/test/rundoc/regex_test.rb +120 -127
- data/test/rundoc/test_parse_java.rb +1 -3
- data/test/test_helper.rb +4 -6
- metadata +39 -42
- data/.travis.yml +0 -8
- 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/
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
36
|
+
```
|
37
|
+
:::-- $ ruby -e "exit 1 unless RUBY_VERSION == '3.0.6'"
|
38
|
+
```
|
34
39
|
|
35
|
-
|
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:
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
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
|
58
|
+
## Create a New or Upgrade an Existing Rails App
|
51
59
|
|
52
|
-
|
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
|
-
|
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
|
-
|
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
|
79
|
+
Create a local database:
|
71
80
|
|
72
81
|
```
|
73
82
|
:::>> $ bin/rails db:create
|
74
83
|
```
|
75
84
|
|
76
|
-
## Add the pg
|
85
|
+
## Add the pg Gem
|
77
86
|
|
78
|
-
|
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
|
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
|
-
|
104
|
+
With the `Gemfile` updated, reinstall the dependencies:
|
93
105
|
|
94
106
|
```ruby
|
95
107
|
$ bundle install
|
96
108
|
```
|
97
109
|
|
98
|
-
|
110
|
+
The installation also updates `Gemfile.lock` with the changes.
|
99
111
|
|
100
|
-
In addition to
|
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
|
118
|
+
Be careful here. If the value of `adapter` is `postgres` and not `postgresql`, the application won’t work.
|
107
119
|
|
108
|
-
## Create a
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
149
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
177
|
+
>note
|
178
|
+
>The `Procfile` filename is case sensitive. There is no file extension.
|
170
179
|
|
171
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
210
|
+
Verify everything committed correctly with `git status`:
|
199
211
|
|
200
212
|
```term
|
201
213
|
:::>> $ git status
|
202
214
|
```
|
203
215
|
|
204
|
-
|
216
|
+
With the application committed to Git, it's ready to deploy to Heroku.
|
205
217
|
|
206
|
-
##
|
218
|
+
## Fix a babel regression
|
207
219
|
|
208
|
-
|
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
|
-
:::>> $
|
225
|
+
:::>> $ rake webpacker:clobber webpacker:compile 2>&1 | grep "Cannot find package '@babel/plugin-proposal-private-methods'"
|
212
226
|
```
|
213
227
|
|
214
|
-
|
228
|
+
To fix this issue modify `babel.config.js`, replace `plugin-proposal-private-methods` with `plugin-transform-private-methods`:
|
215
229
|
|
216
|
-
```
|
217
|
-
|
230
|
+
```diff
|
231
|
+
- '@babel/plugin-plugin-private-methods',
|
232
|
+
+ '@babel/plugin-transform-private-methods',
|
218
233
|
```
|
219
234
|
|
220
|
-
|
235
|
+
```ruby
|
236
|
+
:::-- $ sed -i'' -e 's/plugin-proposal-private-methods/plugin-transform-private-methods/' ./babel.config.js
|
237
|
+
```
|
221
238
|
|
222
|
-
|
239
|
+
Verify that it works correctly:
|
223
240
|
|
224
241
|
```term
|
225
|
-
|
242
|
+
:::>- $ rake webpacker:clobber webpacker:compile
|
226
243
|
```
|
227
244
|
|
228
|
-
|
245
|
+
Commit the fix to git:
|
229
246
|
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
-
|
239
|
-
|
240
|
-
## Visit your application
|
252
|
+
## Create a Heroku App
|
241
253
|
|
242
|
-
|
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
|
-
|
257
|
+
To create an app on Heroku, use the Heroku CLI Inside the Rails app’s root directory:
|
245
258
|
|
246
259
|
```term
|
247
|
-
|
260
|
+
:::>> $ heroku create --stack heroku-20
|
248
261
|
```
|
249
262
|
|
250
|
-
|
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
|
266
|
+
:::>> $ git config --list --local | grep heroku
|
254
267
|
```
|
255
268
|
|
256
|
-
|
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
|
-
|
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
|
282
|
+
:::>> $ heroku addons:create heroku-postgresql:mini
|
262
283
|
```
|
263
284
|
|
264
|
-
|
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
|
-
##
|
287
|
+
## Deploy the App to Heroku
|
269
288
|
|
270
|
-
|
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
|
-
|
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
|
295
|
+
:::>> $ git push heroku main
|
276
296
|
```
|
277
297
|
|
278
|
-
|
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
|
311
|
+
$ heroku run rake db:migrate
|
282
312
|
```
|
283
313
|
|
284
|
-
|
314
|
+
To use an interactive shell session instead, you can execute `heroku run bash`.
|
285
315
|
|
286
|
-
|
316
|
+
## Scale and Access the Application
|
287
317
|
|
288
|
-
|
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
|
-
|
320
|
+
```term
|
321
|
+
:::>- $ heroku ps:scale web=1
|
322
|
+
```
|
291
323
|
|
292
|
-
|
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
|
296
|
-
irb(main):001:0> puts 1+1
|
297
|
-
2
|
327
|
+
:::>> $ heroku ps
|
298
328
|
```
|
299
329
|
|
300
|
-
|
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
|
-
|
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
|
-
|
334
|
+
To launch the app in the browser, run `heroku open`:
|
305
335
|
|
306
336
|
```term
|
307
|
-
$ heroku
|
337
|
+
:::>> $ heroku open
|
308
338
|
```
|
309
339
|
|
310
|
-
|
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
|
-
|
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
|
-
|
315
|
-
|
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
|
-
|
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
|
-
|
357
|
+
$ heroku logs --tail
|
322
358
|
```
|
323
359
|
|
324
|
-
|
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
|
-
|
362
|
+
## Optional Steps
|
327
363
|
|
328
|
-
###
|
364
|
+
### Use The Rails Console
|
329
365
|
|
330
|
-
|
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
|
-
|
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
|
-
|
382
|
+
### Use a Procfile locally
|
340
383
|
|
341
|
-
To use the Procfile locally,
|
384
|
+
To use the `Procfile` locally, use the `heroku local` CLI command.
|
342
385
|
|
343
|
-
In addition to running commands 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
|
-
>
|
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
|
-
|
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
|
-
|
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
|
-
|
411
|
+
Press `Ctrl+C` or `Cmd+C` to exit.
|
375
412
|
|
376
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
419
|
+
## Remove Heroku Gems
|
389
420
|
|
390
|
-
|
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
|
-
|
424
|
+
```ruby
|
425
|
+
# config/environments/production.rb
|
426
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
397
427
|
|
398
|
-
|
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
|
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
|
439
|
+
### Runtime Dependencies on Development or Test Gems
|
405
440
|
|
406
|
-
If
|
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
|
-
|
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
|
-
|
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
|
-
>
|
462
|
+
>note
|
463
|
+
>The `--without` option on `bundler` is persistent. To remove this option, run `bundle config --delete without`.
|
427
464
|
|
428
|
-
|
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
|
483
|
+
## Next Steps
|
447
484
|
|
448
|
-
Congratulations! You
|
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>.
|