I’m experimenting with creating service plans that can serve as a lightweight place to stash the connection details for a pre-provisioned remote service and provide it to an application through binding just as if it was actually providing the service. The benefits of this approach over that currently recommended in Habitat documentation of making the bind optional and adapting your config to accept connection details via bind or config includes having more of a unified code path for config and being able to run an independent health check on the remote service
Here’s my first stab at it, it uses an infinite sleep loop in place of actually running anything and includes a health_check
equivalent to core/mysql
's: https://github.com/JarvusInnovations/habitat-plans/tree/master/mysql-remote
This could be configured, for example with a /hab/user/mysql-remote/config/user.toml
file like this:
host = "myhost.example.org"
port = "3306"
app_username = "myusername"
app_password = "mypassword"
And then bound to an application in place of core/mysql
:
hab start jarvus/my-app --bind database:mysql-remote.default
The only change you need to then make to the application’s config templates is to accept a manually-configured host before falling back to the bound service’s IP:
$config = [
{{~#eachAlive bind.database.members as |member|~}}
{{~#if @first}}
'database' => [
'host' => '{{#if member.cfg.host}}{{ member.cfg.host }}{{else}}{{ member.sys.ip }}{{/if}}',
'port' => '{{ member.cfg.port }}',
'username' => '{{ member.cfg.username }}',
'password' => '{{ member.cfg.password }}',
'database' => '{{ ../cfg.database.name }}'
]
{{~/if~}}
{{~/eachAlive}}
]