Metadata-Version: 2.4
Name: lennybot
Version: 1.0.35
Summary: Automatic Updates for Kustomize Resources
Home-page: http://github.com/raynigon/lennybot
Author: Simon Schneider
Author-email: dev@raynigon.com
Project-URL: Bug Reports, https://github.com/raynigon/lennybot/issues
Project-URL: Source, https://github.com/raynigon/lennybot/
Keywords: kustomize
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6, <4
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml
Requires-Dist: yamlpath
Requires-Dist: requests
Requires-Dist: GitPython
Requires-Dist: PyGithub
Requires-Dist: jsonpath-ng
Provides-Extra: dev
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: wheel; extra == "dev"
Requires-Dist: black; extra == "dev"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Requires-Dist: pytest; extra == "test"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license-file
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

[![PyPI](https://badge.fury.io/py/lennybot.svg)](https://pypi.org/project/lennybot/)
# lennybot

## Usage

### GitHub Actions
```
- uses: raynigon/lennybot@v1.0.0
  env:
    LB_CONFIG_FILE: ".github/lennybot.yaml"
    LB_GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
```

### ACR Token
Getting the login credentials from the [azure container registry](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli#use-az-acr-login-without-docker-daemon):
```
az login
az acr login --name <acrname> --expose-token
```
`username: 000000-0000--0000-0000-000000000000`

### CLI
Install package with `pip install lennybot`.
To start the application run the `lennybot` command.
You can specify the Action which should be executed.
This action can be "ci", "plan" or "apply".
The CI CLI action executed apply and handles git operations such as, commit and branch creation.
The plan action allows to plan updates and save the plan for later.
The apply action can either execute an existing plan, or create a new plan and apply it immediately.

### Docker
To run the lennybot as docker image execute:

```docker run --rm -v "$(pwd):/workspace/ raynigon/lennybot```

## How it works

The lennybot allows to define multiple applications.
Each application has to have a version source, which can be queried to determine the latest version.
If a newer version is available, the lennybot executes multiple pre defined actions per application.
E.g. Update Docker Image Tags.
Sometimes there are conditions which need to be fulfilled before the action can be executed.
These conditions can be specified as checks.
E.g. Check if the docker image is available in the registry, because sometimes a new version of an applications gets released, but the docker image is not available yet.

![A graph showing the process of updating applications by the lennybot](./docs/LennyBot-Execution.drawio.png)

The applications, sources, checks and actions can be configured in the `config.yml` file.
For more information see below.

## Configuration
The lennybot can be configured via the `config.yml` file and environment variables.

If the `config.yml` file is not in the root of the current working directory, the `LB_CONFIG_FILE`environment variable can be used to pass the location of the configuration file to the lennybot.

The configuration file has multiple top level objects.
Each section represents a configuration object.

### State

| Path       | Description                                                           |
| ---------- | --------------------------------------------------------------------- |
| state.file | The state file which is used to store the version of each application |

### GitHub

| Path                  | Description                                                            |
| --------------------- | ---------------------------------------------------------------------- |
| state.pr.enabled      | Toggle PR creation in CI mode. Has to be either true or false          |
| state.pr.repository   | The name of the repository in github on which the PR should be created |
| state.pr.branchPrefix | Prefix for the branch name which should be used to create the PRs      |

### Applications

| Property                                   | Description                                                                                                                              |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| applications[*].name                       | The name of the application which should be updated                                                                                      |
| applications[*].source                     | The configuration for the source of the latest version. This is specific to the type of source, see below for the diffrent source types. |
| applications[\*].actions[\*].type          | The action has to be one of these types "image-tag-update", "download-resources" or "update-yaml". See below for details.                |
| applications[\*].actions[\*].url           |                                                                                                                                          |
| applications[\*].actions[\*].target        |                                                                                                                                          |
| applications[\*].actions[\*].image         |                                                                                                                                          |
| applications[\*].actions[\*].kustomizePath |                                                                                                                                          |
| applications[\*].actions[\*].tagPattern    |                                                                                                                                          |
| applications[\*].actions[\*].targetFile    |                                                                                                                                          |
| applications[\*].actions[\*].yamlPath      |                                                                                                                                          |
| applications[\*].actions[\*].valuePattern  |                                                                                                                                          |

### Sources

Each application has one `source`, which LennyBot queries to find its latest version.
The source type determines where versions are read from:

| `source.type`           | Version source                  | Required configuration                                  |
| ----------------------- | ------------------------------- | ------------------------------------------------------- |
| `github`                | Latest GitHub release           | `repository` (`owner/repo`) and `regex`                 |
| `github-query`          | Git tags from GitHub            | `repository` (`owner/repo`) and `regex`                 |
| `docker-registry-query` | Tags from a Docker/OCI registry | `repository` (image reference without tag) and `regex`  |
| `nodejs-version`        | Node.js release index           | Optional `ltsOnly`                                      |

Every source returns a dotted numeric version (e.g. `1.2.3`).
Versions are compared component by component, so `2.10.0` is newer than `2.9.5`.

#### GitHub Source

Uses the tag name of the latest GitHub release of the repository.
The regex has to match the whole tag name, the first capture group is used as version.

| Property    | Description                                                                                         |
| ----------- | --------------------------------------------------------------------------------------------------- |
| .type       | `github`                                                                                            |
| .repository | The GitHub repository (`owner/name`) which should be used to determine the latest version           |
| .regex      | The regex pattern which is used to extract the version from the tag name, e.g. `v([0-9]+\.[0-9]+\.[0-9]+)` |

```yaml
source:
  type: "github"
  repository: "argoproj/argo-cd"
  regex: "v([0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,})"
```

#### GitHub Query Source

Uses all tags of the GitHub repository instead of only the latest release.
Every tag which matches the regex is a candidate, the highest version wins.
Use this source if the repository has no releases or publishes releases for multiple components.

| Property    | Description                                                                                         |
| ----------- | --------------------------------------------------------------------------------------------------- |
| .type       | `github-query`                                                                                      |
| .repository | The GitHub repository (`owner/name`) which should be used to determine the latest version           |
| .regex      | The regex pattern which is used to extract the version from the tag name, e.g. `v([0-9]+\.[0-9]+\.[0-9]+)` |

```yaml
source:
  type: "github-query"
  repository: "grafana/grafana"
  regex: "v([0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,})"
```

#### Docker Registry Query Source

Uses the tags of a container image directly from an OCI registry (`GET /v2/<name>/tags/list`).
Use this source if the image has no public GitHub repository, or if the image tags differ from the GitHub tags.
Every tag which matches the regex is a candidate, the highest version wins.
Paginated tag lists are followed until the last page.

The registry is called anonymously by default.
If the registry is listed under `container.registries`, its username and password are used for the token request
(the same credentials as for the `docker-image-available` check).

| Property    | Description                                                                                                         |
| ----------- | ------------------------------------------------------------------------------------------------------------------- |
| .type       | `docker-registry-query`                                                                                             |
| .repository | The image reference without tag, e.g. `quay.io/argoproj/argocd`. Images without registry host resolve to Docker Hub |
| .regex      | The regex pattern which has to match the whole tag, the first capture group is used as version                     |

Example: read `wiz-broker` versions directly from Wiz's public registry.
The regex only matches fine-grained build tags and ignores floating tags like `3.0` or `3.0-rc`:

```yaml
applications:
  - name: wiz-broker
    source:
      type: "docker-registry-query"
      repository: "public-registry.wiz.io/wiz-app/wiz-broker"
      regex: "([0-9]+\\.[0-9]+\\.[0-9]+)"
    checks:
      - type: "docker-image-available"
        imagePattern: "public-registry.wiz.io/wiz-app/wiz-broker:{{version}}"
    actions:
      - type: "update-dockerfile"
        targetFile: "images/public-registry-wiz-io/wiz-app/wiz-broker/Dockerfile"
        image: "public-registry.wiz.io/wiz-app/wiz-broker"
        valuePattern: "{{version}}"
```

For a registry that requires credentials, define it under the top-level `container.registries` section.
Credentials can be supplied through `LB_CONTAINER_REGISTRY_<REGISTRY>_USERNAME` and `LB_CONTAINER_REGISTRY_<REGISTRY>_PASSWORD`,
where `<REGISTRY>` is the registry key configured below.
Public registries that allow anonymous token exchange do not need credentials.

```yaml
container:
  registries:
    registry.example.com:
      username: "<username>"
      password: "<password>"
```

#### Node.js Version Source

Uses the Node.js release index (`https://nodejs.org/dist/index.json`).
Set `ltsOnly: true` to select the latest LTS release; otherwise the latest release is used.

```yaml
source:
  type: "nodejs-version"
  ltsOnly: true
```


### Checks

<TODO>


### Actions

#### Image Tag Update Action
<TODO>

| Property       | Description                                                                                                               |
| -------------- | ------------------------------------------------------------------------------------------------------------------------- |
| .type          | The action has to be one of these types "image-tag-update", "download-resources" or "update-yaml". See below for details. |
| .url           |                                                                                                                           |
| .target        |                                                                                                                           |
| .image         |                                                                                                                           |
| .kustomizePath |                                                                                                                           |
| .tagPattern    |                                                                                                                           |
| .targetFile    |                                                                                                                           |
| .yamlPath      |                                                                                                                           |
| .valuePattern  |                                                                                                                           |

#### Download Resource Action
<TODO>

#### Update YAML Action
<TODO>

#### Update JSON Action
<TODO>

#### Update Dockerfile Action
<TODO>

## Origin
Once upon time a colleague (Lenny) left my team.
Besides being an Apache Solr genius, one of the tasks he really liked doing,
was the updating of the dependencies in our applications.
Since everyone else in the team didnt like this job, we needed some automation for this.
The lennybot was born to replace our colleague.
Since then the lennybot evolved and finally got replaced by the dependabot.
Some years later i needed a solution to upgrade components managed with kustomize.
This lead to the creation of a new lennybot which is able to automatically search for updates
and upgrades the resources with their latest versions.
