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
4 changes: 4 additions & 0 deletions app-rails/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ RUN bundle config set --local without production && \
bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git

# Install system-wide gems for development
# This version must match Gemfile.lock. Otherwise, `rdbg` will fail.
RUN gem install debug -v 1.9.2

# Copy application code
COPY . .

Expand Down
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"]

rocketnova marked this conversation as resolved.
Show resolved Hide resolved
# 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 @@ -124,11 +124,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:

SammySteiner marked this conversation as resolved.
Show resolved Hide resolved
- 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 -A`.
- 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 -A`, where `app-rails` is the name of the service in `docker compose`
Loading