etcd-discovery-ruby v1.2.1
Ruby gem implementing etcd-discovery.
Configure etcd client
Default client does not use SSL and connects to http://localhost:2379.
EtcdDiscovery.configure do |config|
config.use_ssl = true # Default: false
config.cacert = "/etc/ssl/cacert.pem" # nil
config.ssl_key = "/etc/ssl/service/private.key" # nil
config.ssl_cert = "/etc/ssl/service/public.cert" # nil
config.host = "etcd-host" # Default: "localhost"
config.port = 2379 # Default: 2379
config.register_ttl = 5 # Default: 10
config.register_renew = 4 # Default: 8
endGet hosts for a particular service
hosts = EtcdDiscovery.get("service").all
hosts.each do |h|
puts h.to_uri
endGet hosts for a particular shard
hosts = EtcdDiscovery.get("service", shard: "shard-0").all
hosts.each do |h|
puts h.to_uri
endGet the service URI
EtcdDiscovery.get("service").to_uriIf the service is public, this returns the URI stored in /services_infos/<service>.
Otherwise, it returns the URI of one registered host.
Warning
Calling to_s directly on a host or collection does not expose credentials: the password is redacted.
Use to_uri or to_private_uri before calling to_s when you need the full URI with credentials.
| Code | Password Redacted |
|---|---|
EtcdDiscovery.get("app-scheduler").one.to_uri |
No |
EtcdDiscovery.get("app-scheduler").one.to_uri.to_s |
No |
EtcdDiscovery.get("app-scheduler").to_uri |
No |
EtcdDiscovery.get("app-scheduler").one.to_s |
Yes |
EtcdDiscovery.get("app-scheduler").to_s |
Yes |
Get the URI of one shard
EtcdDiscovery.get("service", shard: "shard-0").to_uriGet the URI of one registered node
EtcdDiscovery.get("service").one.to_uriGet the private URI of one registered node
EtcdDiscovery.get("service").one.to_private_uriRegister a service
This returns an EtcdDiscovery::Registrar and starts the registration loop in a background thread.
registration = EtcdDiscovery.register "service", {
'name' => "hostname", # Mandatory: Hostname of where the service is deployed
'ports' => { # Mandatory: Ports opened by the service
'http'=> '80',
'https' => '443'
},
'user' => "testuser", # Optional: If your service use basic auth: the username to access your service
'password' => "secret", # Optional: If your service use basic auth: the password to access your service
'public' => true, # Optional: Is your service accessible via an external network (or via a load balancer). Setting this to true will enable credentials synchronization.
'critical' => true, # Optional: Is your service critical? This is just a tag and have no impact on the registration process
'shard' => 'shard-0', # Optional: The shard this host belongs to
'private_hostname' => 'my-host.internal.com', # Optional: The hostname of the service in the private network
'private_ports' => { # Optional: The ports of the service in the private network
'http' => '8080',
'https' => '80443'
}
}
registration.stopListen to credentials change
When a service is public and has credentials, user and password are synced across all the hosts of the service.
You can fetch the current user and password from the EtcdDiscovery::Registrar returned by register.
registration = EtcdDiscovery.register service, host
registration.user # The current user (it can change at any time)
registration.password # The current password (it can change at any time)Release a New Version
Bump new version number in:
CHANGELOG.mdREADME.md-
etcd-discovery.gemspecCommit, tag and create a new release:
version="1.2.1"
git switch --create release/${version}
git add CHANGELOG.md README.md etcd-discovery.gemspec
git commit -m "Bump v${version}"
git push --set-upstream origin release/${version}
gh pr create --reviewer=leo-scalingo --title "$(git log -1 --pretty=%B)"Once the pull request merged, you can tag the new release.
git tag v${version}
git push origin master v${version}
gh release create v${version}The title of the release should be the version number and the text of the release is the same as the changelog.