From 2dc6b244e39da942ccff816462b6436512a0175d Mon Sep 17 00:00:00 2001 From: alexanderturinske Date: Sun, 17 Nov 2019 15:25:18 -0700 Subject: [PATCH 1/2] Allow access to rails tools from terminal - previously, one had to ssh into the docker container to track byebug or run the rails console - create a psudoterminal to the api docker container and allow input for it - update readme to explain how to run the rails console and byebug - https://stackoverflow.com/questions/31669226/rails-byebug-did-not-stop-application/32690885#32690885 - https://medium.com/@ddomachine/docker-and-ruby-on-rails-448ab8255f97 --- README.md | 14 ++++++++++++++ docker-compose.yml | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 50e4497c..6d7f9404 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,20 @@ $ docker-compose run --rm api rake db:create db:schema:load linksf:import $ docker-compose run -e STAGING_DB_PASSWORD=<...> --rm api rake db:setup db:import_staging ``` +### Running tools from the terminal +Due to the DB and API being contained inside Docker containers, running ruby/rails specific tools without having to ssh into the containers involves specific steps +#### Running the rails console from the terminal +```sh +# Start both the DB and API +$ cd PATH/TO/askdarcel-api +$ docker-compose run --rm api rails console +``` + +#### Running byebug from the terminal +```sh +# Start both the DB and API +$ docker attach $(docker ps -aqf "name=askdarcel-api_api") +``` ## macOS-based Development Environment Not Using Docker diff --git a/docker-compose.yml b/docker-compose.yml index 3a881bc0..a04b2e06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,10 @@ services: command: rails server --port=3000 --binding=0.0.0.0 ports: - "3000:3000" + # Creates a psuedoterminal that connects a user's "terminal" with the stdin and stdout stream + tty: true + # Opens the docker container to input from the terminal + stdin_open: true postman: build: From 5172ef3e5de7ce5d114ceca368697b33bf6d72f7 Mon Sep 17 00:00:00 2001 From: alexanderturinske Date: Sun, 1 Dec 2019 18:53:32 -0700 Subject: [PATCH 2/2] Update Readme to better describe the dev tools --- README.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6d7f9404..e7f8d2b4 100644 --- a/README.md +++ b/README.md @@ -80,20 +80,32 @@ $ docker-compose run --rm api rake db:create db:schema:load linksf:import $ docker-compose run -e STAGING_DB_PASSWORD=<...> --rm api rake db:setup db:import_staging ``` -### Running tools from the terminal -Due to the DB and API being contained inside Docker containers, running ruby/rails specific tools without having to ssh into the containers involves specific steps -#### Running the rails console from the terminal +### Developer Tools +#### Rails console +The [Rails console](https://guides.rubyonrails.org/command_line.html#rails-console) gives the developer access to the Rails application + +Steps: +1. Navigate to the `askdarcel-api` directory +2. Start both the DB and API +3. Start the Rails console using the following command ```sh -# Start both the DB and API -$ cd PATH/TO/askdarcel-api $ docker-compose run --rm api rails console ``` - -#### Running byebug from the terminal -```sh -# Start both the DB and API -$ docker attach $(docker ps -aqf "name=askdarcel-api_api") -``` +4. Use the rails console + +#### Byebug +[Byebug](https://github.com/deivid-rodriguez/byebug) allows for easy Ruby debugging + +Steps: +1. Navigate to the `askdarcel-api` directory +2. Place `byebug` on a new line in the code you want to debug +2. Start both the DB and API +3. Attach a listener to the askdarcel-api docker container using the following command + ```sh + $ docker attach $(docker ps -aqf "name=askdarcel-api_api") + ``` +4. Use the app or postman to call the code of interest. The listener should pause the execution at the `byebug` statement +5. [Debug with byebug](https://www.sitepoint.com/the-ins-and-outs-of-debugging-ruby-with-byebug/) ## macOS-based Development Environment Not Using Docker