logo

Compose with Rails

This quick start guide shows how to run Hoop in a local docker-compose environment.

Requirements


  • Signup at hoop.dev for a new organization
  • Open a terminal and login using the Hoop command line
shell
hoop login
press enter when prompt appears for the API_URL address
Export the key in your local machine
shell
export HOOP_KEY=$(hoop admin get orgkeys)
Clone the getting started guide and start
shell
git clone git@github.com:hoophq/hoop-getting-started.git cd hoop-getting-started/ruby docker compose -f docker-compose.yml up
It will start a ruby on rails application at http://127.0.0.1:3000 and create a connection resource on Hoop with the name railsc-demo

Rails Console Access

Start the rails console connected to the main application
shell
hoop connect railsc-demo
markdown
connection: railsc-demo | session: b78183a8-9b25-4d58-ac52-777691d36bb6 Running via Spring preloader in process 66 Loading development environment (Rails 5.2.8.1) irb(main):001:0>
Type ENV["CONTENT"] and then hit enter, it will show the content redacted
plain text
irb(main):001:0> ENV["CONTENT"] => "the sensitive content (*****mail@domain.tld) will be redacted"

Ad Hoc Executions

The example below demonstrates how to establish a connection for performing ad-hoc executions. First, stop the Docker Compose command, then execute the given example.
This example will create a connection with the name rails-adhoc-demo
shell
docker compose -f docker-compose-adhoc.yml up
Perform ad-hoc executions
shell
hoop exec rails-adhoc-demo -i 'puts "Hello World"'
💡
The web app provides an improved experience for these executions. Visit the webapp and select this connection to interact with it.

Embedded Process

The later examples run the agent (hoop run) as a standalone process. This one demonstrates how it can be run embedded within your application.
The command below illustrates how this can be accomplished. Everything after the -- delimiter represents the main application command, which will run in the foreground, while the agent runs in the background.
shell
hoop run --name railsc-embedded-demo \ --data-masking EMAIL_ADDRESS,URL \ --command 'rails console' \ -- bundle exec rails s -p 3000 -b '0.0.0.0'
command present at docker-compose-embedded.yml
💡
The streams stdout and stderr are linked to your main application, as well as the agent.
This example will create a connection with the name railsc-embedded-demo
shell
docker compose -f docker-compose-embedded.yml up
Connect via rails console
shell
hoop connect railsc-embedded-demo

Powered by Notaku