Skip to content

Commit

Permalink
feat: add backend option to action (#23)
Browse files Browse the repository at this point in the history
* feat: bump docker layer grafana/cortex-tools to v0.11.0

* feat: add BACKEND settings in the entrypoint.sh
  • Loading branch information
rasta-rocket authored Feb 22, 2024
1 parent 242fe39 commit c703e29
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM grafana/cortex-tools:v0.10.6
FROM grafana/cortex-tools:v0.11.0

COPY entrypoint.sh /entrypoint.sh

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ This action is used to lint, prepare, verify, diff, and sync rules to a [Cortex]
This action is configured using environment variables defined in the workflow. The following variables can be configured.

| Name | Description | Required | Default |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- |
| `CORTEX_ADDRESS` | URL address for the target Cortex cluster | `false` | N/A |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ------- |
| `CORTEX_ADDRESS` | URL address for the target Cortex cluster | `false` | N/A |
| `CORTEX_TENANT_ID` | ID for the desired tenant in the target Cortex cluster. Used as the username under HTTP Basic authentication. | `false` | N/A |
| `CORTEX_API_KEY` | Optional password that is required for password-protected Cortex clusters. An encrypted [github secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets ) is recommended. Used as the password under HTTP Basic authentication. | `false` | N/A |
| `ACTION` | Which action to take. One of `lint`, `prepare`, `check`, `diff` or `sync` | `true` | N/A |
| `RULES_DIR` | Comma-separated list of directories to walk in order to source rules files | `false` | `./` |
| `LABEL_EXCLUDED_RULE_GROUPS` | Comma separated list of rule group names to exclude when including the configured label to aggregations. This option is supported only by the `prepare` action. | `false` | N/A |
| `NAMESPACES` | Comma-separated list of namespaces to use | `false` | N/A |
| `ACTION` | Which action to take. One of `lint`, `prepare`, `check`, `diff` or `sync` | `true` | N/A |
| `RULES_DIR` | Comma-separated list of directories to walk in order to source rules files | `false` | `./` |
| `LABEL_EXCLUDED_RULE_GROUPS` | Comma separated list of rule group names to exclude when including the configured label to aggregations. This option is supported only by the `prepare` action. | `false` | N/A |
| `NAMESPACES` | Comma-separated list of namespaces to use | `false` | N/A |
| `BACKEND` | Backend type to interact with: cortex, loki | `false` | `cortex` |

## Authentication

Expand Down
17 changes: 11 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ SYNC_CMD=sync
DIFF_CMD="diff"
PRINT_CMD=print

if [ -z "${BACKEND}" ]; then
echo "BACKEND not set, using 'cortex' as a default."
BACKEND="cortex"
fi

if [ -z "${RULES_DIR}" ]; then
echo "RULES_DIR not set, using './' as a default."
RULES_DIR="./"
Expand All @@ -41,28 +46,28 @@ fi
case "${ACTION}" in
"$SYNC_CMD")
verifyTenantAndAddress
OUTPUT=$(/usr/bin/cortextool rules sync --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@")
OUTPUT=$(/usr/bin/cortextool rules sync --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} "$@")
STATUS=$?
;;
"$DIFF_CMD")
verifyTenantAndAddress
OUTPUT=$(/usr/bin/cortextool rules diff --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@")
OUTPUT=$(/usr/bin/cortextool rules diff --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" ${NAMESPACES:+ --namespaces=${NAMESPACES}} --disable-color "$@")
STATUS=$?
;;
"$LINT_CMD")
OUTPUT=$(/usr/bin/cortextool rules lint --rule-dirs="${RULES_DIR}" "$@")
OUTPUT=$(/usr/bin/cortextool rules lint --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" "$@")
STATUS=$?
;;
"$PREPARE_CMD")
OUTPUT=$(/usr/bin/cortextool rules prepare -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@")
OUTPUT=$(/usr/bin/cortextool rules prepare --backend="${BACKEND}" -i --rule-dirs="${RULES_DIR}" --label-excluded-rule-groups="${LABEL_EXCLUDED_RULE_GROUPS}" "$@")
STATUS=$?
;;
"$CHECK_CMD")
OUTPUT=$(/usr/bin/cortextool rules check --rule-dirs="${RULES_DIR}" "$@")
OUTPUT=$(/usr/bin/cortextool rules check --backend="${BACKEND}" --rule-dirs="${RULES_DIR}" "$@")
STATUS=$?
;;
"$PRINT_CMD")
OUTPUT=$(/usr/bin/cortextool rules print --disable-color "$@")
OUTPUT=$(/usr/bin/cortextool rules print --backend="${BACKEND}" --disable-color "$@")
STATUS=$?
;;
*)
Expand Down

0 comments on commit c703e29

Please sign in to comment.