rundoc 1.1.3 → 2.0.1
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 +10 -12
- 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 +92 -30
- data/test/fixtures/rails_5/rundoc.md +69 -10
- data/test/fixtures/rails_6/rundoc.md +226 -165
- 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 +7 -9
- 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 +141 -126
- 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,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
|
-
|
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.
|
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
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
217
|
+
|
218
|
+
## Fix a babel regression
|
205
219
|
|
206
|
-
|
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
|
-
|
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`:
|
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
|
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
|
-
|
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:essential-0
|
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
|
-
|
298
|
+
If the output displays warnings or error messages, check the output and make adjustments.
|
232
299
|
|
233
|
-
|
300
|
+
After a successful deployment, complete these tasks as necessary:
|
234
301
|
|
235
|
-
|
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
|
-
|
242
|
-
|
243
|
-
## Visit your application
|
314
|
+
To use an interactive shell session instead, you can execute `heroku run bash`.
|
244
315
|
|
245
|
-
|
316
|
+
## Scale and Access the Application
|
246
317
|
|
247
|
-
|
318
|
+
Heroku runs application code using defined processes and [process types](procfile). New applications don't have 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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
344
|
+
## View Application Logs
|
272
345
|
|
273
|
-
|
346
|
+
The app logs are a valuable tool if the app is not performing correctly or generating errors.
|
274
347
|
|
275
|
-
|
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
|
-
|
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
|
-
|
362
|
+
## Optional Steps
|
292
363
|
|
293
|
-
|
364
|
+
### Use The Rails Console
|
294
365
|
|
295
|
-
|
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
|
-
|
374
|
+
### Run Rake Commands
|
304
375
|
|
305
|
-
|
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
|
-
|
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
|
-
|
318
|
-
gem 'puma'
|
319
|
-
```
|
384
|
+
To use the `Procfile` locally, use the `heroku local` CLI command.
|
320
385
|
|
321
|
-
|
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
|
-
>
|
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
|
-
|
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
|
-
|
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
|
-
|
411
|
+
Press `Ctrl+C` or `Cmd+C` to exit.
|
378
412
|
|
379
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
419
|
+
## Remove Heroku Gems
|
392
420
|
|
393
|
-
|
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
|
-
|
424
|
+
```ruby
|
425
|
+
# config/environments/production.rb
|
426
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
400
427
|
|
401
|
-
|
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
|
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
|
439
|
+
### Runtime Dependencies on Development or Test Gems
|
408
440
|
|
409
|
-
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.
|
410
442
|
|
411
|
-
|
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
|
-
|
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
|
-
>
|
462
|
+
>note
|
463
|
+
>The `--without` option on `bundler` is persistent. To remove this option, run `bundle config --delete without`.
|
430
464
|
|
431
|
-
|
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
|
483
|
+
## Next Steps
|
450
484
|
|
451
|
-
Congratulations! You
|
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>.
|