|
| 1 | +# gmpctl |
| 2 | + |
| 3 | +`gmpctl` is an interactive CLI for common operations on GMP projects. |
| 4 | + |
| 5 | +It's a starting point for smaller or bigger automation on OSS side (e.g. releasing, syncing or even debugging). |
| 6 | + |
| 7 | +> NOTE: This script is far from perfect, but it's better than doing things manually. Feel free to contribute, |
| 8 | +> fix bugs and add more automation for common tasks! |
| 9 | +
|
| 10 | +## Setup |
| 11 | + |
| 12 | +1. To start using `gmpctl` you need to have a clone of `prometheus-engine` on your machine (you probably have already one! |
| 13 | + to fetch the latest `main` for the best experience (latest scripts). |
| 14 | + |
| 15 | +2. The next this is to obtain NVD API key to avoid rate-limits when querying CVE DB. See https://nvd.nist.gov/developers/request-an-api-key and save this key to `hack/vulnupdatelist/api.text` |
| 16 | + |
| 17 | +3. You can configure different work directory for gmpctl via `-c` flag. By default, `gmpctl` does the work in `hack/gmpctl/.data`) |
| 18 | + |
| 19 | +Enjoy! |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Generally `gmpctl` does not need flags for general usage. It interactively asks you for |
| 24 | +key information and confirmations e.g. |
| 25 | + |
| 26 | +```bash |
| 27 | +./hack/gmpctl.sh release |
| 28 | +┃ What do you want to release? |
| 29 | + ┃ > release/0.17 |
| 30 | + ┃ release/0.15 |
| 31 | + ┃ release/0.14 |
| 32 | + ┃ release/0.12 |
| 33 | + ┃ release-2.45.3-gmp |
| 34 | + ┃ release-2.53.5-gmp |
| 35 | +↑ up • ↓ down • / filter • enter submit |
| 36 | +``` |
| 37 | + |
| 38 | +`gmpctl` maintains 1 git clone for each project and uses `git worktree` for each command and branch. |
| 39 | + |
| 40 | +`gmpctl` commands are aimed to be **idempotent**, meaning you should be able to run it multiple times with the |
| 41 | +same parameters, and it will continue the previous work or at least yield same results. This is crucial when iterating |
| 42 | +on breaking go mod updates for vulnerabilities or fork sync conflicts. |
| 43 | + |
| 44 | +```text mdox-exec="bash hack/gmpctl.sh --help" |
| 45 | +Usage: gmpctl [COMMAND] [FLAGS] |
| 46 | + -c string |
| 47 | + Path to the configuration file. See config.go#Config for the structure. (default ".gmpctl.default.yaml") |
| 48 | + -v Enabled verbose, debug output (e.g. logging os.Exec commands) |
| 49 | + |
| 50 | +--- Commands --- |
| 51 | +[release] Usage of release: |
| 52 | + -b string |
| 53 | + Release branch to work on; Project is auto-detected from this |
| 54 | + -patch |
| 55 | + If true, and --tag is empty, forces a new patch version as a new TAG. |
| 56 | + -t string |
| 57 | + Tag to release. If empty, next TAG version will be auto-detected (double check this!) |
| 58 | + |
| 59 | +[vulnfix] Usage of vulnfix: |
| 60 | + -b string |
| 61 | + Release branch to work on; Project is auto-detected from this |
| 62 | + -pr-branch string |
| 63 | + (default: $USER/BRANCH-vulnfix) Upstream branch to push to (user-confirmed first). |
| 64 | + -sync-dockerfiles-from |
| 65 | + Optional branch name to sync Dockerfiles from. Useful when things changed. |
| 66 | +``` |
| 67 | + |
| 68 | +## `gmpctl` development |
| 69 | + |
| 70 | +Some rules to follow: |
| 71 | + |
| 72 | +* Downstream functions should literally use `panicf` for error handling. This improves readability and enormously help |
| 73 | + with debugging errors. The obvious exception is when code needs to handle this error. Then swap panic with a proper `err error` pattern. |
| 74 | +* Offer choice, be interactive! See `dialog.go` and https://github.com/charmbracelet/huh on what's possible. |
| 75 | + |
| 76 | +## Bash development |
| 77 | + |
| 78 | +While the `gmpctl` is written in Go, you might notice some functionalities are in Bash. |
| 79 | + |
| 80 | +Bash is funky, but sometimes more readable than Go/easier to iterate. |
| 81 | +Eventually, we could rewrite more critical pieces to Go, but you're welcome to add some quick |
| 82 | +pieces in bash to automate some stuff. |
| 83 | + |
| 84 | +It's trivial to call bash function from `gmpctl` e.g.: |
| 85 | + |
| 86 | +```go |
| 87 | +if err := runLibFunction(dir, opts, "release-lib:vulnfix"); err != nil { |
| 88 | + return err |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +Some rules to follow: |
| 93 | +* CI checks bash formatting via https://github.com/mvdan/sh?tab=readme-ov-file#shfmt. You can install this on your IDE for formatting. |
| 94 | +* Write only libraries (functions). The starting point for scripts should be always Go gmpctl CLI. |
| 95 | +* Function names have `release-lib::` prefix to figure out where they come from. |
| 96 | +* Function check their required arguments/envvars; always. |
| 97 | +* Especially for functions that return strings via stdout: |
| 98 | + * Ensure all error messages are redirected to stderr, use log_err func for this. |
| 99 | + * Be careful with pushd/popd which log to stdout, you can redirect those to stderr too. |
| 100 | + |
| 101 | +## TODO |
| 102 | + |
| 103 | +* Ability to configure NVD API key in gmpctl config. |
| 104 | +* Port fork-sync script from the old PR. |
| 105 | +* Generate some on-demand query of vulnerabilities for all releases (aka dashboard.) |
| 106 | +* Fix NPM vulns (although it's rate). |
| 107 | +* Ability to schedule multiple scripts at once and managing that? (lot's of work vs multiple terminals) |
0 commit comments