Skip to content
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

Docker Console and Debugger #31

Merged
merged 10 commits into from
Jun 26, 2024
Merged

Conversation

SammySteiner
Copy link
Contributor

@SammySteiner SammySteiner commented Jun 14, 2024

Ticket

Changes

  • Updated web_console config to allow most local IPs to access the console for local development with docker
  • Updated docs to give more specific instructions on how to access the debugger

Questions for reviewers

  1. In the technical-foundation doc, it says to run the app with make rails-console though I think elsewhere it says to use make init-native/container and make start-native/container for local native and local docker development. Should we change it here to be consistent?
  2. We're pulling the ruby:3.3.1-slim image from dockerhub which comes with the debug gem version 1.19.1. However, in our local gemfile.lock we have debug version 1.19.2 installed. Using debug in docker breaks when there is a version mismatch between the server and the client. This will be fixed whenever dockerhub updates their ruby:3.3.1-slim image, but I was only able to get it running locally by locking my debug version in the gemfile to 1.9.1. Is there a best practice to address this?
  3. When setting the IP addresses for permissions, there are some programmatic ways of getting locaL IP addresses, but it seems like those require additional libraries (socket, ipaddr). Is that preferred to the current method or should we go even further by allowing 0.0.0.0?

Testing

  • Add a console statement to a view in the application and confirm that the console shows up in your browser when hitting that page. Test in both native and container modes.
  • Add a debugger statement to a controller and follow the instructions in the technical-foundation.md doc to attach the debugger. Confirm in both native and container modes.

Copy link
Contributor

@rocketnova rocketnova left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Left some thoughts below.

docs/app-rails/technical-foundation.md Show resolved Hide resolved
docs/app-rails/technical-foundation.md Outdated Show resolved Hide resolved
docs/app-rails/technical-foundation.md Outdated Show resolved Hide resolved
docs/app-rails/technical-foundation.md Outdated Show resolved Hide resolved
docs/app-rails/technical-foundation.md Outdated Show resolved Hide resolved
app-rails/config/environments/development.rb Show resolved Hide resolved
@rocketnova
Copy link
Contributor

rocketnova commented Jun 17, 2024

  1. In the technical-foundation doc, it says to run the app with make rails-console though I think elsewhere it says to use make init-native/container and make start-native/container for local native and local docker development. Should we change it here to be consistent?

I addressed this in my inline comments. make init-container and make start-container initialize and start the container. They do not create an interactive rails console. make rails-console does.

  1. We're pulling the ruby:3.3.1-slim image from dockerhub which comes with the debug gem version 1.19.1. However, in our local gemfile.lock we have debug version 1.19.2 installed. Using debug in docker breaks when there is a version mismatch between the server and the client. This will be fixed whenever dockerhub updates their ruby:3.3.1-slim image, but I was only able to get it running locally by locking my debug version in the gemfile to 1.9.1. Is there a best practice to address this?

Can you link me to where the upstream ruby docker hub image includes the debug gem? I'm not seeing that. You said "I was only able to get it running locally". What were you trying to run that was failing with this?

  1. When setting the IP addresses for permissions, there are some programmatic ways of getting locaL IP addresses, but it seems like those require additional libraries (socket, ipaddr). Is that preferred to the current method or should we go even further by allowing 0.0.0.0?

Can you explain what wasn't working before you added this? I'm not sure I'm following.

@SammySteiner
Copy link
Contributor Author

SammySteiner commented Jun 18, 2024

  1. In the technical-foundation doc, it says to run the app with make rails-console though I think elsewhere it says to use make init-native/container and make start-native/container for local native and local docker development. Should we change it here to be consistent?

I addressed this in my inline comments. make init-container and make start-container initialize and start the container. They do not create an interactive rails console. make rails-console does.

Sounds good. Thanks for clarifying.

  1. We're pulling the ruby:3.3.1-slim image from dockerhub which comes with the debug gem version 1.19.1. However, in our local gemfile.lock we have debug version 1.19.2 installed. Using debug in docker breaks when there is a version mismatch between the server and the client. This will be fixed whenever dockerhub updates their ruby:3.3.1-slim image, but I was only able to get it running locally by locking my debug version in the gemfile to 1.9.1. Is there a best practice to address this?

Can you link me to where the upstream ruby docker hub image includes the debug gem? I'm not seeing that. You said "I was only able to get it running locally". What were you trying to run that was failing with this?

The debug gem in the docker ruby 3.3.1-slim image is listed as version 1.9.1, which I was able to confirm on the dockerhub website:
image
The debug version getting installed in our project is listed as 1.9.2 in our gemfile.lock.
When I try to attach a debugger to the docker container with docker exec -i <Container ID> rdbg -An I get the error in my terminal:

app-rails-1  | 14:42:38 web.1  | DEBUGGER: wait for debugger connection...
app-rails-1  | 14:43:25 web.1  | DEBUGGER: Connected.
app-rails-1  | 14:43:25 web.1  | DEBUGGER: GreetingError: out DEBUGGER: Incompatible version (server:1.9.2 and client:1.9.1)
app-rails-1  | 14:43:25 web.1  | DEBUGGER: Disconnected.

However, if I lock my debug gem to version 1.9.1, and re-bundle and create a new containerized app, it works as expected.

I described how I'm running my docker container in the inline comment here, are you doing it differently?

  1. When setting the IP addresses for permissions, there are some programmatic ways of getting locaL IP addresses, but it seems like those require additional libraries (socket, ipaddr). Is that preferred to the current method or should we go even further by allowing 0.0.0.0?

Can you explain what wasn't working before you added this? I'm not sure I'm following.

Responded to your inline comment.

@SammySteiner SammySteiner requested a review from rocketnova June 18, 2024 14:55
@rocketnova
Copy link
Contributor

However, if I lock my debug gem to version 1.9.1, and re-bundle and create a new containerized app, it works as expected.

I described how I'm running my docker container in the inline comment here, are you doing it differently?

Got it! Thanks. I think what we should do is explicitly install a global version of the debug gem inside the docker image that is used for development, by adding this to line 57 of the Dockerfile:

# Install system-wide gems for development
# This version must match Gemfile.lock. Otherwise, `rdbg` will fail.
RUN gem install debug -v 1.9.2
  1. When setting the IP addresses for permissions, there are some programmatic ways of getting locaL IP addresses, but it seems like those require additional libraries (socket, ipaddr). Is that preferred to the current method or should we go even further by allowing 0.0.0.0?

Can you explain what wasn't working before you added this? I'm not sure I'm following.

Responded to your inline comment.

I think your change is good and that we don't need to expand out to 0.0.0.0.

- 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.

@SammySteiner SammySteiner requested a review from rocketnova June 26, 2024 18:45
Copy link
Contributor

@rocketnova rocketnova left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@SammySteiner SammySteiner merged commit 7dfcf4f into main Jun 26, 2024
5 checks passed
@SammySteiner SammySteiner deleted the sammysteiner/12/improve-debugging branch June 26, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve debugging during local development
2 participants