External methods

An external-hook registry method allows for invoking an external script, which itself makes use of Bcome’s runtime. The namespace context at which the external hook is called is passed to the script.

This guide demonstrates the configuration of a simple external hook.

Here’s our script -

require 'bcome'
require 'pry'

# Define an orchestrator
orchestrator = ::Bcome::Orchestrator.instance

# Load in the namespace
@node = orchestrator.get(ENV["bcome_context"])

# Work with the namespace

# run a command
command = "echo \"hello world I am `hostname -A`\""
@node.run command

exit 0

Hint

There is a lot you can do with a @node object. See interacting with node.

Let’s save our script as ‘say_hello_server.rb’ at the following location:

.
└── bcome
    └── scripts
        └── say_hello_server.rb

Next we’ll add a registry.yml association for our script, associating it with the ‘production:wbzsite’ namespace in our namespace tree:

---
"production:wbzsite(.+)?":
  - type: external
    description: "Say hello, server"
    console_command: say_hello
    group: salutations
    local_command: ruby scripts/say_hello_server.rb

Now let’s try out our external registry hook:

Note

To replay this Asciicast in your own terminal, install the asciinema package from https://asciinema.org/, and then enter the following in your terminal:

asciinema play https://asciinema.org/a/LW2fZbitYWKyaFnCuWtgyJOIP

Note

See our documentation site for more details on configuring external hooks.