Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/try-leverage/local-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Leverage-based projects are better managed via the [Leverage CLI](/user-guide/le
In order to install the CLI you should have the following installed in your system:

- [X] [Git](https://git-scm.com/)
- [X] [Python 3](https://www.python.org/) `version 3.8 and up`
- [X] [Docker](https://docs.docker.com/engine/install/)
- [X] [Python 3](https://www.python.org/) `version 3.9 and up`

## Install [Leverage CLI](/user-guide/leverage-cli/overview/)
Leverage CLI is distributed as a python package that you can install it via `pip` as follows:
Expand All @@ -20,7 +19,7 @@ pip install leverage
Verify that your Leverage CLI installation was successful by running the following command:
``` bash
$ leverage --version
leverage, version 1.9.2
leverage, version 3.0.0
```

!!! info "It is generally recommended to install the latest stable version of the CLI"
Expand Down
100 changes: 7 additions & 93 deletions docs/user-guide/leverage-cli/basic-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,105 +13,19 @@ Options:
--help Show this message and exit.

Commands:
aws Run AWS CLI commands in a custom containerized environment.
aws Run AWS CLI commands in the context of the current project.
credentials Manage AWS cli credentials.
kc Run Kubectl commands in a custom containerized environment.
kubectl Run Kubectl commands in a custom containerized environment.
kc Run Kubectl commands in the context of the current project.
kubectl Run Kubectl commands in the context of the current project.
project Manage a Leverage project.
run Perform specified task(s) and all of its dependencies.
shell Run a shell in a generic container.
tofu Run OpenTofu commands in a custom containerized...
tf Run OpenTofu commands in a custom containerized...
terraform Run Terraform commands in a custom containerized...
tfautomv Run TFAutomv commands in a custom containerized...
terraform Run Terraform commands in the context of the current project.
tf Run OpenTofu commands in the context of the current project.
tfautomv Run TFAutomv commands in the context of the current project.`
Comment thread
angelofenoglio marked this conversation as resolved.
tofu Run OpenTofu commands in the context of the current project.
```

Similarly, subcommands provide further information by means of the `--help` flag. For example `leverage tf --help`.

## Global options
* `-v` | `--verbose`: Increases output verbosity.
When running a command in a container, the tool provides a description of the container's configuration before the execution.
This is specially useful if the user were to to have the need of recreating Leverage's behavior by themselves.
``` bash
$ leverage -v tf plan
[20:27:44.758] DEBUG Found config file /home/user/binbash/le-tf-infra-aws/build.env
[20:27:44.812] DEBUG Container configuration:
{
"image": "binbash/leverage-toolbox:1.5.0-0.2.3-1000-1000", #(1)!
"command": "",
"stdin_open": true,
"environment": { #(2)!
"COMMON_CONFIG_FILE": "/binbash/config/common.tfvars",
"ACCOUNT_CONFIG_FILE": "/binbash/apps-devstg/config/account.tfvars",
"BACKEND_CONFIG_FILE": "/binbash/apps-devstg/config/backend.tfvars",
"AWS_SHARED_CREDENTIALS_FILE": "/home/leverage/tmp/bb/credentials",
"AWS_CONFIG_FILE": "/home/leverage/tmp/bb/config",
"SRC_AWS_SHARED_CREDENTIALS_FILE": "/home/leverage/tmp/bb/credentials",
"SRC_AWS_CONFIG_FILE": "/home/leverage/tmp/bb/config",
"AWS_CACHE_DIR": "/home/leverage/tmp/bb/cache",
"SSO_CACHE_DIR": "/home/leverage/tmp/bb/sso/cache",
"SCRIPT_LOG_LEVEL": 3,
"MFA_SCRIPT_LOG_LEVEL": 3,
"SSH_AUTH_SOCK": "/ssh-agent"
},
"entrypoint": "/bin/tofu",
"working_dir": "/binbash/apps-devstg/us-east-1/k8s-eks/identities",
"host_config": {
"NetworkMode": "default",
"SecurityOpt": [
"label=disable"
],
"Mounts": [ #(3)!
{
"Target": "/binbash",
"Source": "/home/user/binbash/le-tf-infra-aws",
"Type": "bind",
"ReadOnly": false
},
{
"Target": "/home/leverage/tmp/bb",
"Source": "/home/user/.aws/bb",
"Type": "bind",
"ReadOnly": false
},
{
"Target": "/etc/gitconfig",
"Source": "/home/user/.gitconfig",
"Type": "bind",
"ReadOnly": false
},
{
"Target": "/ssh-agent",
"Source": "/run/user/1000/keyring/ssh",
"Type": "bind",
"ReadOnly": false
}
]
}
}
[20:27:44.825] INFO Checking for local docker image, tag: 1.5.0-0.2.3-1000-1000...
[20:27:44.851] INFO ✔ OK

[20:27:44.853] DEBUG Checking for layer /home/user/binbash/le-tf-infra-aws/apps-devstg/us-east-1/k8s-eks/identities...
[20:27:44.875] DEBUG Checking layer /home/user/binbash/le-tf-infra-aws/apps-devstg/us-east-1/k8s-eks/identities...
[20:27:44.876] DEBUG Running command: sh -c 'cat $SSO_CACHE_DIR/token'
[20:27:47.469] INFO Attempting to get temporary credentials for shared account.
[20:27:47.471] DEBUG Token expiration time: 1740094585.0
DEBUG Token renewal time: 1740182267.470991
[20:27:47.472] DEBUG Retrieving role credentials for DevOps...
[20:27:48.558] INFO Writing binbash-shared-devops profile
[20:27:48.564] INFO Credentials for shared account written successfully.
[20:27:48.567] INFO Attempting to get temporary credentials for apps-devstg account.
[20:27:48.570] DEBUG Token expiration time: 1740094584.0
[20:27:48.571] DEBUG Token renewal time: 1740182268.5704691
[20:27:48.572] DEBUG Retrieving role credentials for DevOps...
[20:27:49.171] INFO Writing binbash-apps-devstg-devops profile
[20:27:49.177] INFO Credentials for apps-devstg account written successfully.
[20:27:49.182] DEBUG Running command: plan -var-file=/binbash/config/common.tfvars -var-file=/binbash/apps-devstg/config/account.tfvars -var-file=/binbash/apps-devstg/config/backend.tfvars #(4)!
...
```

1. :simple-docker: Docker image being used
2. Environment variables available in the container
3. Mapping of the host (`Source`) directories and files into the container (`Target`)
4. Command being executed (useful when trying to replicate Leverage's behavior by yourself)
15 changes: 2 additions & 13 deletions docs/user-guide/leverage-cli/extending-leverage/build.env.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ By utilizing the [`build.env` capability](https://github.com/binbashar/leverage/
easily change some default behaviors of the CLI. In the **binbash Leverage™ Ref
Architecture** you will find the following
[`build.env` example](https://github.com/binbashar/le-tf-infra-aws/blob/master/build.env) as an example.
This allows you to specify several configurations for the CLI, such as the
[Leverage-Toolbox-Image](https://hub.docker.com/repository/docker/binbash/leverage-toolbox/general) you want to
use, ensuring that you are using the latest version or a specific version that you prefer based on your [compatibility
requirements](https://leverage.binbash.com.ar/work-with-us/releases/versions-compatibility-matrix/#compatibility-matrix).
This helps you avoid compatibility issues and ensures that your infrastructure deployments go smoothly.
This allows you to specify several configurations for the CLI, such as the project short name that is injected throughout the codebase.

### `build.env` file format
The `build.env` file format and supported parameters are the following:
Expand All @@ -20,16 +16,9 @@ PROJECT=bb
MFA_ENABLED=false

# OpenTofu
TF_IMAGE_TAG=1.2.7-0.1.4
TF_BINARY=./@bin/tofu
```

!!! info "Customizing or extending the leverage-toolbox docker image"
You can locally copy and edit the [Dockerfile](https://github.com/binbashar/le-docker-leverage-toolbox/blob/master/Dockerfile)
in order to rebuild it based on your needs, eg for a `Dockerfile` placed in the current working directory:
`$ docker build -t binbash/leverage-toolbox:1.2.7-0.1.4 --build-arg TOFU_VERSION='1.2.7' .`
In case you like this changes to be permanent please consider
[creating and submitting a PR](https://github.com/binbashar/leverage/pulls).

### Working principle & multiple `build.env` precedence

The `leverage CLI` has an environmental variable loading utility that will load all `.env` files with the given name in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
## Override defaults via `build.env` file
By utilizing the [`build.env` capability](https://github.com/binbashar/leverage/blob/master/leverage/conf.py), you can
easily change some default behaviors of the CLI. This allows you to specify several configurations for the CLI,
such as the
[Leverage-Toolbox-Image](https://hub.docker.com/repository/docker/binbash/leverage-toolbox/general) that you want to
use, ensuring that you are using the latest version or a specific version that you prefer based on your [compatibility
requirements](https://leverage.binbash.com.ar/work-with-us/releases/versions-compatibility-matrix/#compatibility-matrix).
This helps you avoid compatibility issues and ensures that your infrastructure deployments go smoothly.
such as the OpenTofu/Terraform binary location, if it were to be found in a non standard location.

!!! info "Read More about `build.env`"
In order to further understand this mechanism and how to use it please visit the dedicated
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/leverage-cli/extending-leverage/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Tasks in build file `build.py`:

copy_file Copy src file to dst

Powered by Leverage 1.0.10
Powered by Leverage 3.0.0
Comment thread
angelofenoglio marked this conversation as resolved.
```

Any argument that the task may receive are to be given when [running the task](d). The syntax for passing arguments is similar to that of Rake.
Expand Down
58 changes: 46 additions & 12 deletions docs/user-guide/leverage-cli/installation.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Installation

To use Leverage CLI you need to install it from the Python Package Index (Pypi). Currently, only Linux and Mac OS are supported operative systems.
To use Leverage CLI you need to install it from the Python Package Index (Pypi). Currently, only Linux and Mac OS are officially supported operative systems.
Comment thread
angelofenoglio marked this conversation as resolved.

!!! done "Requirements"
* [x] **Python** `>= 3.9`
* [x] **Git** `>= 2.25`
* [x] **Docker engine** `>= 20.x.y`

!!! warning "Having issues with the CLI?"
Check out [the troubleshooting section](/user-guide/troubleshooting/general) to find more help.
Expand Down Expand Up @@ -47,7 +46,7 @@ $ pip3 install leverage

Upgrade to a specific [version](https://github.com/binbashar/leverage/releases).
``` bash
$ pip3 install -Iv leverage==1.9.1
$ pip3 install -Iv leverage==2.2.0
```

Upgrade to the latest stable version
Expand All @@ -70,22 +69,57 @@ Options:
--help Show this message and exit.

Commands:
aws Run AWS CLI commands in a custom containerized environment.
aws Run AWS CLI commands in the context of the current project.
credentials Manage AWS cli credentials.
kc Run Kubectl commands in a custom containerized environment.
kubectl Run Kubectl commands in a custom containerized environment.
kc Run Kubectl commands in the context of the current project.
kubectl Run Kubectl commands in the context of the current project.
project Manage a Leverage project.
run Perform specified task(s) and all of its dependencies.
shell Run a shell in a generic container.
tofu Run OpenTofu commands in a custom containerized...
tf Run OpenTofu commands in a custom containerized...
terraform Run Terraform commands in a custom containerized...
tfautomv Run TFAutomv commands in a custom containerized...
terraform Run Terraform commands in the context of the current project.
tf Run OpenTofu commands in the context of the current project.
tfautomv Run TFAutomv commands in the context of the current project.`
Comment thread
angelofenoglio marked this conversation as resolved.
tofu Run OpenTofu commands in the context of the current project.
```
Comment thread
angelofenoglio marked this conversation as resolved.

##Installation in an isolated environment
Comment thread
angelofenoglio marked this conversation as resolved.

If you prefer not to install the Leverage package globally and would like to limit its influence to only the directory of your project, we recommend using tools like [Pipenv](https://pipenv.pypa.io/en/latest/) or [Poetry](https://python-poetry.org/). These tools are commonly used when working with python applications and help manage common issues that may result from installing and using such applications globally.
If you prefer not to install the Leverage package globally and would like to limit its influence to only the directory of your project, we recommend using tools like [uv](https://docs.astral.sh/uv/) or [Poetry](https://python-poetry.org/). These tools are commonly used when working with python applications and help manage common issues that may result from installing and using such applications globally.

### Installation using uv

#### Install uv

Follow the instructions laid out in the [official `uv` installation guide](https://docs.astral.sh/uv/getting-started/installation/).

#### Local python version

You can choose to have a python installation exclusive to the local project.
``` bash
uv python install 3.13
uv python pin 3.13
```

#### Initialize the project and install `leverage`
``` bash
uv init
uv add leverage
```

#### Activate the virtual environment
Once the project is initialized and Leverage CLI is installed you can run commands as
``` bash
uv run leverage tofu plan
```
However a simpler approach is to activate the virtual environment in the current shell, running
``` bash
source .venv/bin/activate
```
Now all Leverage CLI commands can be executed directly
``` bash
leverage tofu plan
```

###
Comment thread
angelofenoglio marked this conversation as resolved.

##Shell completion

Expand Down
4 changes: 3 additions & 1 deletion docs/user-guide/leverage-cli/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
## Overview
Leverage CLI is the tool used to manage and interact with any Leverage project.

It transparently handles the most complex and error prone tasks that arise from working with a state-of-the-art infrastructure definition like our Leverage Reference Architecture. Leverage CLI uses a dockerized approach to encapsulate the tools needed to perform such tasks and to free the user from having to deal with the configuration and management of said tools.
It transparently handles the most complex and error-prone tasks that arise from working with a state-of-the-art infrastructure definition like our Leverage Reference Architecture. It understands the structure of the Leverage Reference Architecture and assists the user in their day-to-day operation.

Leverage CLI orchestrates a set of tools used to operate in a Leverage project. Usually this means OpenTofu/Terraform, but also aws-cli, kubectl and more.

## Repositories
- [x] [Source Code (Github)](https://github.com/binbashar/leverage)
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/leverage-cli/reference/aws.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Command: `aws`

The `aws` command is a wrapper for a containerized installation of AWS CLI 2.0. All commands are passed directly to the AWS CLI and you should expect the same behavior from all of them, except for the few exceptions listed below.
Run AWS CLI commands with the proper credentials for the project. All commands are passed directly to the AWS CLI and you should expect the standard behavior from all of them, except for the few specific cases listed below.

---
## `configure sso`
Expand Down
17 changes: 3 additions & 14 deletions docs/user-guide/leverage-cli/reference/kubectl.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Command: `kubectl`

!!! info "Regarding Leverage Toolbox versions"
To have this feature available, Leverage Toolbox versions `1.2.7-0.1.7` and up, or `1.3.5-0.1.7` and up must be used.

The `kubectl` command is a wrapper for a containerized installation of [kubectl](https://kubernetes.io/docs/reference/kubectl/). It provides the kubectl executable with specific configuration values required by Leverage.
The `kubectl` command provides the [kubectl](https://kubernetes.io/docs/reference/kubectl/) executable with the proper credentials and specific configuration values required by Leverage.

It transparently handles authentication, whether it is Multi-Factor or via Single Sign-On, on behalf of the user in the commands that require it. SSO Authentication takes precedence over MFA when both are active.

Expand All @@ -18,6 +15,8 @@ The command can also be invoked via its shortened version `kc`.
!!! info "Discovering clusters"
You can now run the `discover` command from the root of the project to find and configure all the involved clusters.

If the binary is not installed in the system, the CLI will prompt the user to do so.

---
## `run`

Expand All @@ -36,16 +35,6 @@ All arguments given are passed as received to kubectl.
leverage kubectl get pods --namespace monitoring
```

---
## `shell`

### Usage
``` bash
leverage kubectl shell
```

Open a shell into the Kubectl container in the current directory.

---
## `configure`

Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/leverage-cli/reference/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ leverage run task1 task2[arg1,arg2] task3[arg1,kwarg1=val1,kwarg2=val2]
start_server [Default] Start the server
stop_server

Powered by Leverage 1.13.0
Powered by Leverage 3.0.0
```
Loading
Loading