CLI References
humctl
is the command line interface for Humanitec
Quick Start
Installation
Visit
CLI
for instructions how to install the humctl
.
Basic usage
humctl
follows a standard command structure. The basic usage is:
humctl COMMAND TYPE [arguments...]
Different commands accept different types. Types are types of Humanitec objects such as defined in the API such as apps
, envs
or sets
. Arguments are usually IDs, values or switches. Switches are available in a long form (e.g. --message
) or short form (e.g. -m
.) Short form switches cannot be combined into a single switch.
The commands supported by the CLI so far include:
Command | Types | Description |
---|---|---|
api |
n/a | Make raw authenticated API requests to the Humanitec API. |
apply |
n/a | Creates or updates an object based on a Humanitec Manifest . |
completion |
n/a | Generate the autocompletion script for the specified shell. |
config |
n/a | Show the value of a particular config key. |
create |
app , delta , env |
Creates a new object. |
delete |
all kinds | Deletes an object. |
deploy |
delta , deploy , set , env |
Starts a new deployment to an environment. |
diff |
sets |
Returns a delta of the difference between 2 deployment sets. |
get |
all kinds | Fetches the requested object. |
help |
n/a | Get help on a command. (e.g. humctl help deploy ) |
login |
n/a | Login to the CLI with the help of a web browser. |
resources |
n/a | Commands to manage your resources. |
score |
n/a | Commands to operate on Score files. |
update |
delta |
Makes a change to an object. |
version |
n/a | Get the current version of the tool. |
Run humctl help COMMAND
for details of a specific command.
Output
--output
to specify another output format.Errors are written to stderr
and fatal errors will result in a non-zero exit code.
Configuration
humctl
will read from a config file located by default at .humctl
in the users home directory. These configurations can be overridden using Environment Variables.
Environment Variables
humctl
understands the following optional environment variables:
Environment Variable | Description |
---|---|
HUMANITEC_TOKEN |
A Humanitec static or session token. |
HUMANITEC_ORG |
The Organization in which to run commands. |
HUMANITEC_APP |
The Application in which to run commands. |
HUMANITEC_ENV |
The Environment in which to run commands. |
HUMANITEC_API_PREFIX |
The Humanitec API to use. (Defaults to https://api.humanitec.io ) |
HUMANITEC_OUTPUT |
One of yaml , json or text . (Defaults to text ) |
HUMANITEC_CONFIG |
Path to the config file described below. (Defaults to ~/.humctl ) |
Config File
The humctl
config file is a YAML file with the following properties:
Property | type | Description |
---|---|---|
api_prefix |
string | The Humanitec API to use. (Defaults to https://api.humanitec.io ) |
org |
string | The Organization in which to run commands. |
app |
string | The Application in which to run commands. |
env |
string | The Environment in which to run commands. |
output |
string | One of yaml , json or text . (Defaults to text ) |
token |
string | A Humanitec static or session token |
All properties are optional.
IDs, Context and Expansions
Objects in Humanitec exist in a hiearchy. For example, an Environment always belongs to a single Application and an Application always belongs to a single Organization. The fully qualified ID for an object in Humanitec is equivelant to its path in the
Humanitec API
. For example, the fully qualified ID for an environment called my-env
in an application called my-app
in organization my-org
is:
/orgs/my-org/apps/my-app/envs/my-env
Expansions using Current Context
As most users spend their time working with just one or two environments in a single Application, humctl
allows users to define a context which can be used to figure out the full ID from just a fragment. For example, if the context was --org my-org --app my-app --env my-env
, then the following expansions could happen:
Type | Short ID | Fully Qualified ID |
---|---|---|
apps |
my-other-app |
/orgs/my-org/apps/my-other-app |
envs |
second-env |
/orgs/my-org/apps/my-app/envs/second-env |
envs |
--app my-other-app --env other-apps-env |
/orgs/my-org/apps/my-other-app/envs/other-apps-env |
This also works for other objects that are scoped within an Application or Enviornment:
Type | Short ID | Fully Qualified ID |
---|---|---|
sets |
dRZxTxhPImjJ2JIWXj-ZGiu_4-ov5UfWxK-eUNt6zvh |
/orgs/my-org/apps/my-app/sets/dRZxTxhPImjJ2JIWXj-ZGiu_4-ov5UfWxK-eUNt6zvh |
deltas |
18e8fd691c3be9c023f5dc41d0cb2181d524fd01 |
/orgs/my-org/apps/my-app/deltas/18e8fd691c3be9c023f5dc41d0cb2181d524fd01 |
Current Context and Active objects
As a further shortcut, the current context value can be used directly by using .
in place of the ID alltogether:
Type | Short ID | Fully Qualified ID |
---|---|---|
apps |
. |
/orgs/my-org/apps/my-app |
envs |
. |
/orgs/my-org/apps/my-app/envs/my-env |
This also works with other objects that can have be active. The last delta created will be remembered by humctl
and will be inserted if you use .
in place of a delta. The last Deployment in an Environment counts as the “active” Deployment, so if you use .
in place of a deployment, you will get the active deployment of the current Environment in the context.
For example, assuming the most recently created deltas has ID 18e8fd691c3be9c023f5dc41d0cb2181d524fd01
and the last deployment an ID of 166a15b85e58dcee
:
Type | Short ID | Fully Qualified ID |
---|---|---|
deltas |
. |
/orgs/my-org/apps/my-app/deltas/18e8fd691c3be9c023f5dc41d0cb2181d524fd01 |
deploys |
. |
/orgs/my-org/apps/my-app/envs/my-env/deploys/166a15b85e58dcee |
Sequential objects
A final shortcut applies to objects that have order. This currently only applies to Deployments. Deployments in an Environment have an order as they occur on after eachother in an environment. The sequential shortcut is a +
followed by the offset down the list and is used in place of an ID. In this case +0
would get the current item and +2
would get the item next-but-one in the list. For example:
Type | Short ID | Fully Qualified ID |
---|---|---|
deploys |
. |
/orgs/my-org/apps/my-app/envs/my-env/deploys/166a15b85e58dcee |
deploys |
+0 |
/orgs/my-org/apps/my-app/envs/my-env/deploys/166a15b85e58dcee |
deploys |
+2 |
/orgs/my-org/apps/my-app/envs/my-env/deploys/964f2eae8b51a661 |
The sequential shortcut can also be used in combination with a partial or fully qualified ID:
Type | Short ID | Fully Qualified ID |
---|---|---|
deploys |
--env second-env deploys/+2 |
/orgs/my-org/apps/my-app/envs/second-env/deploys/eaaa4a64e8b51df0 |
deploys |
--org my-org --app my-other-app --env different-env deploys/+1 |
/orgs/my-org/apps/my-other-app/envs/different-env/deploys/411f9bbe01e4dc62 |
Humanitec Manifests
Humanitec uses a similar YAML structure to Kubernetes when defining its YAML files. The structure has the following basic format:
apiVersion: entity.humanitec.io/v1b1
kind: Environment
metadata:
id: dev-2
entity: # modifiable properties
name: Secondary Dev
type: development
status: # read-only properties
created_at: "2020-06-12T07:49:12.720677Z"
The manifests can be used with the apply
command to provide an “as code” approach to using Humanitec.
Score integration
With humctl
, you can easily operate and deploy your Score files. Currently, the score command supports the following subcommands:
Command | Description | |
---|---|---|
available-resource-types | List available resource types. | |
deploy | Deploy a Score file. | |
init | Initialize the Score file. | |
validate | Validate the specified score file. |
Listing available Resource Types
Depending on your organization, developers might have access to different Resource Types. The humctl
tool provides an easy way for developers to discover what is available to them. Use the following commands:
- List all available resource types:
humanitec score available-resource-types
- Filter the list by a specific Resource Type:
humctl score available-resource-types --filter-type TYPE
- Ensure you are using the correct Resource Types in your Score files:
humctl score validate
The latter validation step can prevent errors and streamline the provisioning process by checking your Score file for any incorrect Resource Types and providing feedback on necessary corrections.
For the best developer experience, use the VSCode Extension that displays Resource Types and validates your Score file in real-time. This extension integrates seamlessly with your development workflow, providing instant feedback and helping you adhere to best practices.
Deploying Score files
To deploy a single workload, you can simply use humctl score deploy
. It will use the score.yaml
file from the directory where the binary was executed. To modify that path, you can use the --file
flag. Additionally, you can specify extension files using the --extensions
flag and overrides using the --overrides
flag.
Removing Workloads
Add the --remove
flag to the humctl score deploy
command to remove a Workload instead of deploying it, e.g. humctl score deploy -f scoreWithWorkloadToRemove.yaml --remove
.
Configuration
To avoid passing extension and override files each time and to deploy multiple workloads at once, you can define a deploy configuration and specify it via the --deploy-config
flag. This configuration describes where the Score files are located and matches them with their respective extensions and overrides. An example file looks like this:
deploy-config.yaml
(
view on GitHub
)
:
apiVersion: config.humanitec.io/v1b1
kind: ScoreDeployConfig
workloads:
- name: example-service
specFile: ./score.example-service.yaml
extensionsFile: ./score.humanitec.yaml
- name: another-service
specFile: ./score.another-service.yaml
extensionsFile: ./score.humanitec.yaml
Available attributes in your deploy configuration are:
Attribute | Type | Content |
---|---|---|
name |
string |
(optional) Name to identify the workload inside the deploy configuration. The actual workload name will always be taken from the Score file |
specFile |
string |
Path to the workload specification file, i.e. the Score file |
extensionsFile |
string |
(optional) Path to the workload extensions file |
image |
string |
(optional) Image used for the image: . notation in the Score file |
overridesFile |
string |
(optional) Path to the workload overrides file |
propertyOverrides |
object |
(optional) Overrides for the workload properties. Is merged with the content of an overridesFile . Properties from propertyOverrides take precedence over identical properties from the overridesFile |
There is no specific order of deployment for the workloads. All the specified changes from the Score files are combined into a single delta and pushed as one deployment.
If an error occurs during the deployment of the combined delta, the entire deployment process fails. The error messages can be found in the pipeline run logs.
Examples
Create a delta to add an environment variable to the main
container in the sample-app
workload:
humctl create delta --name "add variable"
humctl update delta . add modules/sample-app/spec/containers/main/variables/NEW_VAR '"Hello World!"'
Deploy the current delta to the current environment:
humctl deploy delta . . --message "Adding NEW_VAR to sample-app"
Comparing what is currently deployed with what was deployed before:
humctl diff sets deploy/+0 deploy/+1
Compare the current environment to the production environment:
humctl diff sets env/. env/production