Heroku (rproxy)
Deploy the agent in a heroku worker dyno.
- Login and create the runops-agent app
plain text# give an unique name for your agent AGENT_NAME= heroku login heroku container:login heroku apps:create $AGENT_NAME
- Pull the agent version from the dockerhub and push to the heroku registry
plain textdocker pull runops/rproxy docker tag runops/rproxy registry.heroku.com/$AGENT_NAME/worker docker push registry.heroku.com/$AGENT_NAME/worker
- Sign in to runops and configure the agent
The token must be retrieved from the webapp or using the cli
plain textTAG=test heroku config:set --app $AGENT_NAME TOKEN=<RUNOPS_AGENT_TOKEN> heroku config:set --app $AGENT_NAME ENV_CONFIG='{"HEROKU_API_TOKEN": "<API-KEY>"}' heroku config:set --app $AGENT_NAME TAG=$TAG
- Start the agent
plain textheroku container:release --app $AGENT_APP worker heroku ps:scale --app $AGENT_APP worker=1 heroku logs --app $AGENT_APP
- Reference: https://devcenter.heroku.com/articles/container-registry-and-runtime
Interacting with connections
Lastly we need to link the agent to Runops API.
- Download the rproxy and runops command line
plain textnpm install -g runops brew tap runopsio/rproxy https://github.com/runopsio/rproxy brew install rproxy
- Add a interactive bash connection
plain textrunops login # it will open a browser to authenticate CONNECTION_NAME=heroku-apps-bash cat - > /tmp/$CONNECTION_NAME.json <<EOF { "tags": "$TAG", "secret_provider": "env-var", "secret_path": "ENV_CONFIG", "name": "$CONNECTION_NAME", "type": "bash", "custom_command": "heroku run bash" } EOF curl https://api.runops.io/v1/targets \ -H "Authorization: $(cat ~/.runops/config)" \ -H 'content-type: application/json' -d@/tmp/$CONNECTION_NAME.json
Now you’re able to interact with any application, the
custom_command
will be used as prefix to the commands
below:plain text# obtain an interactive shell (bash) to the given app rproxy exec -c $CONNECTION_NAME -- --app <app>
The user could pass additional flags to the heroku run bash prefix command. Important to note that by default the heroku run creates a tty, so it allows the connection to be interactive.
Add a interactive session to
rails console
plain textCONNECTION_NAME=heroku-rails-console cat - > /tmp/$CONNECTION_NAME.json <<EOF { "tags": "$TAG", "secret_provider": "env-var", "secret_path": "ENV_CONFIG", "name": "$CONNECTION_NAME", "type": "bash", "custom_command": "heroku run rails console" } curl https://api.runops.io/v1/targets \ -H "Authorization: $(cat ~/.runops/config)" \ -H 'content-type: application/json' -d@/tmp/$CONNECTION_NAME.json EOF # start interactive rails console for any app rproxy exec -c $CONNECTION_NAME -- --app <app>
To add a non interactive session allowing one-off commands
plain textCONNECTION_NAME=heroku-rails-runner cat - > /tmp/$CONNECTION_NAME.json <<EOF { "tags": "$TAG", "secret_provider": "env-var", "secret_path": "ENV_CONFIG", "name": "$CONNECTION_NAME", "type": "bash", "custom_command": "heroku run --no-tty rails runner -" } EOF curl https://api.runops.io/v1/targets \ -H "Authorization: $(cat ~/.runops/config)" \ -H 'content-type: application/json' -d@/tmp/$CONNECTION_NAME.json
Note that the --no-tty flag which makes a non-interact connection
Now it’s possible to run one-off ruby scripts
plain text# reading content from stdin and executing directly echo 'puts Rails.env' | rproxy exec -c $CONNECTION_NAME -- --app <app> rproxy exec -c $CONNECTION_NAME -- --app <app> <<EOF myvar='hello world from runops' puts myvar EOF