This is a simple helper gem to connect your Kamal hooks(pre-build, pre-build, pre-deploy, post-deploy) to Shipyrd.
Shipyrd is the deployment dashboard for your team.
Install the gem and add to the application's Gemfile by executing:
$ bundle add shipyrd
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install shipyrd
Please see the main Shipyrd app(https://github.com/shipyrd/shipyrd) for setup and usage instructions.
You can run a dockerized version of shipyrd-gem by adding the following function to your ~/.bashrc or similar:
shipyrd() {
docker run --rm -v "${PWD}:/workdir" --env-file <(env | grep -E '^(KAMAL_|SHIPYRD_)') ghcr.io/shipyrd/shipyrd-gem /shipyrd/bin/"$@"
}Then within a specific Kamal hook (e.g. pre-connect), you can call shipyrd like this:
#!/usr/bin/env bash
shipyrd pre-connectThis gem currently sends the following deploy details to record a deploy. Each deploy variable can be set with either a SHIPYRD_ or KAMAL_ prefix — SHIPYRD_ takes precedence. The KAMAL_ variants are set automatically by Kamal when the hooks are called.
ENV["SHIPYRD_COMMAND"]/ENV["KAMAL_COMMAND"],ENV["SHIPYRD_DESTINATION"]/ENV["KAMAL_DESTINATION"],ENV["SHIPYRD_HOSTS"]/ENV["KAMAL_HOSTS"],ENV["SHIPYRD_PERFORMER"]/ENV["KAMAL_PERFORMER"]-gh config get -h github.com usernameis preferred if set.ENV["SHIPYRD_RECORDED_AT"]/ENV["KAMAL_RECORDED_AT"],ENV["SHIPYRD_ROLE"]/ENV["KAMAL_ROLE"],ENV["SHIPYRD_RUNTIME"]/ENV["KAMAL_RUNTIME"],ENV["SHIPYRD_SERVICE_VERSION"]/ENV["KAMAL_SERVICE_VERSION"],ENV["SHIPYRD_SUBCOMMAND"]/ENV["KAMAL_SUBCOMMAND"],ENV["SHIPYRD_VERSION"]/ENV["KAMAL_VERSION"],ENV["SHIPYRD_API_KEY"],ENV["SHIPYRD_HOST"],- Commit message - The first 90 characters of your commit message
git show -s --format=%s.
Create one client with a Shipyrd user's API token, not an application's
SHIPYRD_API_KEY, because a lock is attributed to the person, and call helpers
on it, as with twilio-ruby:
client = Shipyrd::Client.new(host: "https://api.shipyrd.io", api_key: user_api_token)
client.lock_destination("production", application: "shipyrd-web")
client.unlock_destination("production", application: "shipyrd-web")- The first argument is the destination's name.
nilor""mean the destination with a blank name. applicationis the application's slug, or its id.organization_idis only needed when the slug exists in more than one of your organizations.
Both return the destination's state as a Hash. Locking a destination someone
else holds is refused; unlocking works whoever holds the lock. Locking your own
lock again, or unlocking a destination that isn't locked, changes nothing.
Unlike trigger, they raise on failure, and every error is a
Shipyrd::Client::Error, with #status and the JSON #body:
| Error | When |
|---|---|
Shipyrd::Destination::LockHeld |
Locking a destination someone else holds. #locked_by and #locked_at say who and since when. Nothing changed. |
Shipyrd::Destination::NotFound |
No such application or destination. #destinations lists the real ones when it was the destination, and is nil when it was the application. |
Shipyrd::Destination::AmbiguousApplication |
The slug is in several of your organizations. #organizations lists them; pass organization_id. |
Shipyrd::Client::Unauthorized |
Missing, unknown, or an application token. |
Shipyrd::Client::RateLimited |
Too many requests. |
Shipyrd::Client::Unavailable |
A 5xx, a timeout, or no connection. |
Shipyrd::Client::UnexpectedResponse |
Anything else. |
The first three are subclasses of Shipyrd::Client::Conflict,
Shipyrd::Client::NotFound and Shipyrd::Client::UnprocessableEntity, so
rescuing the general error still catches them. Shipyrd::Client#request is the
same request for any other API endpoint. The helpers delegate to
Shipyrd::Destination, which you can also use directly.
client.applications
# => [{"slug" => "shipyrd-web", "organization" => {"id", "name"}, "destination_states" => [...]}, ...]
client.applications(organization_id: 7)
client.destination("production", application: "shipyrd-web")
# => {"name", "locked", "locked_by", "locked_at", "branch", "on_deck_url", "latest_deploy" => {...}, ...}applications lists every application in your organizations, or in one with
organization_id, each with its destinations' lock state and latest deploy.
destination takes the same arguments as lock_destination and raises the same
Shipyrd::Destination::NotFound and AmbiguousApplication.
client.create_application(name: "Billing", organization_id: 7, repository_url: "https://github.com/acme/billing")
# => {"id", "slug", "name", "organization" => {"id", "name"}, "destinations" => [], "setup_url", ...}
client.create_destination("staging", application: "billing", branch: "develop")
# => {"name", "branch", "locked", ...}
client.create_destination(nil, application: "billing") # the default destinationcreate_application needs the organization_id to create it in; client.me
lists your organizations. An organization you are not in raises
Shipyrd::Client::NotFound. The answer never includes the application's deploy
token: setup_url is the page that shows it. Destinations are created
separately, with create_destination.
create_destination takes the same arguments as destination, plus branch and
url. A nil, blank or "default" name creates the default destination.
Anything Shipyrd will not save, such as a taken slug or a name the application
already has, raises Shipyrd::Client::Invalid. Its #errors is Shipyrd's
answer by attribute, e.g. {"slug" => ["has already been taken"]}, and its
message puts that in a sentence.
Neither is retried. If an answer is lost, check client.applications before
trying again: retrying create_application without a slug creates a second
application (billing-2), and retrying with a slug or a destination name raises
Invalid for something that was in fact created.
client = Shipyrd::Client.new(host: "https://api.shipyrd.io", api_key: user_api_token)
client.me
# => {"user" => {...}, "organizations" => [{"id", "name", "active_subscription", "admin"}], "billing_url" => "..."}GET /me as JSON: the token's user, their organizations, each with whether it
has an active subscription, and where to subscribe. Like Shipyrd::Destination
it needs a user's API token, and raises the same Shipyrd::Client errors.
After checking out the repo, run bin/setup to install dependencies. Then, run bin/test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
bin/ci is the full suite — lint, tests and coverage on changed lines — and is what CI runs too, so run it before opening a pull request. Lint is vanilla RuboCop with rubocop-performance; coverage on changed lines is undercover.
bin/ci
To install this gem onto your local machine, run bundle exec rake install. To release a new version, run bin/release x.y.z, which will run tests, change the version in version.rb, commit the version change, create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/shipyrd/shipyrd-gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The bin/release command will bump the version in the version.rb file, tag it, push it up to GitHub and RubyGems, and create the GitHub release for the tag with notes generated from the merged pull requests. It needs the gh CLI, signed in.
bin/release 0.3.1
Everyone interacting in the Shipyrd project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.