Skip to content

Docker Console and Debugger #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 26, 2024
3 changes: 3 additions & 0 deletions app-rails/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
# Suppress logger output for asset requests.
config.assets.quiet = true

# Allow web_console to render when triggered from the rails app running locally in a docker container.
config.web_console.permissions = ["192.168.0.0/16", "172.16.0.0/16", "10.0.0.0/8"]

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true

Expand Down
15 changes: 11 additions & 4 deletions docs/app-rails/technical-foundation.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,18 @@ make rails-generate GENERATE_COMMAND="model Foo --primary-key-type=uuid"

### 🐛 Debugging

Rails has some useful [built-in debugging tools](https://guides.rubyonrails.org/debugging_rails_applications.html).
Rails has some useful [built-in debugging tools](https://guides.rubyonrails.org/debugging_rails_applications.html). Here are a few different options:

- Start the rails console: `make rails-console`
- Start the [rails console](https://guides.rubyonrails.org/command_line.html#bin-rails-console): `make rails-console`
- Run a console in the browser:
- Add a `console` line and an interactive console, similar to the rails console, will appear in the bottom half of your browser window
- Add `<% console %>` to an `.erb` file and an interactive console, similar to the rails console, will appear in the bottom half of your browser window.
- Note: If the console doesn't appear when running in a docker container, check to see if your IP address is added to the permissions list in [development.rb](app-rails/config/environments/development.rb) in `config.web_console.permissions`. The list is currently set to allow most internal IPs. You would also see an error in your terminal that looks something like: `Cannot render console from <your.IP.address.here>! Allowed networks: 127.0.0.0/127.255.255.255, ::1`
- Run the debugger:
- Add a `debugger` line and the rails server will pause and start the debugger
- Note: this is not yet configured for this application when doing local development in a container
- If you're running the app natively, such as with `make start-native`:
- You must connect to the debugger from another terminal session because of our [Procfile.dev](app-rails/Procfile.dev) configuration.
- From another terminal tab, run `rdbg -An`.
- If you have multiple Rails applications with debuggers running, you'll have to specify the port to attach the debugger to. For more information, see the [Rails debug gem documentation](https://github.com/ruby/debug?tab=readme-ov-file#remote-debugging).
- If you're running the app in a container, such as with `make start-container`:
- `rdbg` in the terminal on your host machine will not be able to see the port in the container to connect to the debugger.
- Instead, run `rdbg` inside the container: `docker compose exec app-rails rdbg -An`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running rdbg -An gave me this:

DEBUGGER (client): Connected. PID:10, $0:bin/rails
DEBUGGER (client): Type `Ctrl-C` to enter the debug console.

And I needed to hit Ctrl-C to enter the debug console. Whereas rdbg -A allowed me to skip hitting Ctrl-C. Any reason we need -n? I didn't see anything in particular in the docs.

Copy link
Contributor

@rocketnova rocketnova Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, running rdbg (both natively and in the container), I got this:

DEBUGGER (client): Connected. PID:10, $0:bin/rails

# No sourcefile available for /usr/local/bundle/ruby/3.3.0/gems/puma-6.4.2/lib/puma/single.rb
=>#0	[C] Thread#join at /usr/local/bundle/ruby/3.3.0/gems/puma-6.4.2/lib/puma/single.rb:63
  #1	Puma::Single#run at /usr/local/bundle/ruby/3.3.0/gems/puma-6.4.2/lib/puma/single.rb:63
  # and 20 frames (use `bt' command for all frames)

Stop by SIGURG
(rdbg:remote) 

This issue is the only reference I found about this. I was able to hit c to continue past it, but it was persistent. Did you run into this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! i removed the n from the guidance, however that enables the --nonstop flag which is used to tell rdbg to not stop at the beginning of the script. I saw a bunch of troubleshooting tips that advised adding it, but it's not necessary in all cases.

I was only able to reproduce what you were seeing by connecting the debugger before the application hit the debug statement. But once the debug statement was hit by the user action, then the debugger terminal updated properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see! Thanks.

Loading