-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add aliases to Kamal #912
Add aliases to Kamal #912
Conversation
validate_type! value, Hash | ||
when "labels" | ||
validate_hash_of! value, example_value.first[1].class | ||
validate_type! validation_config, example.class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously all second level config items were expected to be hashes, but for aliases they are strings, so we need to expand the config validation to handle that.
Aliases are defined in the configuration file under the `aliases` key. The configuration is a map of alias name to command. When we run the command the we just do a literal replacement of the alias with the string. So if we have: ```yaml aliases: console: app exec -r console -i --reuse "rails console" ``` Then running `kamal console -r workers` will run the command ```sh $ kamal app exec -r console -i --reuse "rails console" -r workers ``` Because of the order Thor parses the arguments, this allows us to override the role from the alias command. There might be cases where we need to munge the command a bit more but that would involve getting into Thor command parsing internals, which are complicated and possibly subject to change. There's a chance that your aliases could conflict with future built-in commands, but there's not likely to be many of those and if it happens you'll get a validation error when you upgrade. Thanks to @dhnaranjo for the idea!
If you can have an alias like: ``` aliases: rails: app exec -p rails ``` Then `kamal rails db:migrate:status` will execute `kamal app exec -p rails db:migrate:status`. So this works, we'll allow multiple arguments `app exec` and `server exec` to accept multiple arguments. The arguments are combined by simply joining them with a space. This means that these are equivalent: ``` kamal app exec -p rails db:migrate:status kamal app exec -p "rails db:migrate:status" ``` If you want to pass an argument with spaces, you'll need to quote it: ``` kamal app exec -p "git commit -am \"My comment\"" kamal app exec -p git commit -am "\"My comment\"" ```
I've added 579e169, so that commands can be combined for This means we can have an alias like |
This is going to be so nice. We should define a few of the stock ones we use for Rails, like console, in the Rails' default config/deploy.yml file when this is released 👌 |
Aliases are defined in the configuration file under the
aliases
key.The configuration is a map of alias name to command. When we run the command the we just do a literal replacement of the alias with the string.
So if we have:
Then running
kamal console -r workers
will run the commandBecause of the order Thor parses the arguments, this allows us to override the role from the alias command.
There might be cases where we need to munge the command a bit more but that would involve getting into Thor command parsing internals, which are complicated and possibly subject to change.
There's a chance that your aliases could conflict with future built-in commands, but there's not likely to be many of those and if it happens you'll get a validation error when you upgrade.
Thanks to @dhnaranjo for the idea!