Skip to content

Commit

Permalink
Merge branch 'main' into otlp-defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
xperimental committed Oct 18, 2024
2 parents 47c7b93 + 71d1c6b commit 5d6955f
Show file tree
Hide file tree
Showing 50 changed files with 2,315 additions and 1,016 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/helm-release.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: helm-release

on:
workflow_dispatch: # must be invoked manually
workflow_dispatch: # for manual testing
push:
branches:
- main
- k[0-9]+
paths:
- 'production/helm/loki/Chart.yaml'

jobs:
call-update-helm-repo:
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/helm-tagged-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
name: helm-weekly-release-pr
name: Helm tagged release PR

on:
release:
types:
- released

workflow_dispatch: # for manual testing

jobs:
weekly-release-pr:
runs-on: ubuntu-latest
env:
RELEASE_VERSION: "${{ github.event.release.tag_name || 'test' }}"
BUILD_IN_CONTAINER: false
steps:
- uses: actions/checkout@v4
- uses: gabe565/setup-helm-docs-action@v1
with:
version: v1.11.2

- id: "get_github_app_token"
name: "get github app token"
Expand All @@ -21,13 +29,14 @@ jobs:

- name: Update/regenerate files
id: update
run: bash .github/workflows/scripts/helm-tagged-release.sh ${{ github.event.release.tag_name }}
run: |
bash .github/workflows/scripts/helm-tagged-release.sh ${RELEASE_VERSION}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.get_github_app_token.outputs.token }}
title: Release loki Helm chart ${{ steps.update.outputs.new_chart_version }}
title: "chore: release loki helm chart ${{ steps.update.outputs.new_chart_version }}"
body: Automated PR created by [helm-tagged-release-pr.yaml](https://github.com/grafana/loki/blob/main/.github/workflows/helm-tagged-release-pr.yaml)
commit-message: Update loki chart to ${{ steps.update.outputs.new_chart_version }}
branch: helm-chart-tagged-${{ steps.update.outputs.new_chart_version }}
Expand Down
41 changes: 36 additions & 5 deletions .github/workflows/helm-weekly-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
name: helm-weekly-release-pr
name: Helm weekly release PR

on:
schedule:
- cron: '0 10 * * 1-5' # 10 UTC on weekdays; if we miss published images one day, they should align the day after

workflow_dispatch: # for manual testing

permissions:
contents: "read"
id-token: "write"
pull-requests: "write"

jobs:
weekly-release-pr:
runs-on: ubuntu-latest
env:
BUILD_IN_CONTAINER: false
steps:
- uses: actions/checkout@v4
- uses: imjasonh/[email protected]
- uses: gabe565/setup-helm-docs-action@v1
with:
version: v1.11.2

- id: "get_github_app_token"
name: "get github app token"
Expand All @@ -21,15 +30,37 @@ jobs:
owner: "${{ github.repository_owner }}"
private-key: "${{ secrets.APP_PRIVATE_KEY }}"

- name: Update/regenerate files
- name: "Login to DockerHub (from vault)"
uses: "grafana/shared-workflows/actions/dockerhub-login@main"

- uses: imjasonh/[email protected]

- name: Update/regenerate files for k release
id: update-k
run: |
bash .github/workflows/scripts/helm-weekly-release.sh -k
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.get_github_app_token.outputs.token }}
title: "chore: release loki helm chart ${{ steps.update-k.outputs.new_chart_version }}"
body: Automated PR created by [helm-weekly-release-pr.yaml](https://github.com/grafana/loki/blob/main/.github/workflows/helm-weekly-release-pr.yaml)
commit-message: Update loki chart to ${{ steps.update-k.outputs.new_chart_version }}
branch: helm-chart-weekly-${{ steps.update-k.outputs.new_chart_version }}
base: ${{ steps.update-k.outputs.weekly }}
labels: helm

- name: Update/regenerate files for standard release
id: update
run: bash .github/workflows/scripts/helm-weekly-release.sh
run: |
bash .github/workflows/scripts/helm-weekly-release.sh
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.get_github_app_token.outputs.token }}
title: Release loki Helm chart ${{ steps.update.outputs.new_chart_version }}
title: "chore: release loki helm chart ${{ steps.update.outputs.new_chart_version }}"
body: Automated PR created by [helm-weekly-release-pr.yaml](https://github.com/grafana/loki/blob/main/.github/workflows/helm-weekly-release-pr.yaml)
commit-message: Update loki chart to ${{ steps.update.outputs.new_chart_version }}
branch: helm-chart-weekly-${{ steps.update.outputs.new_chart_version }}
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/logql-analyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: LogQL Analyzer

on:
workflow_dispatch:
release:
types:
- released

permissions:
contents: read
id-token: write

jobs:
analyze:
runs-on: ubuntu-latest

env:
BUILD_TIMEOUT: 60
IMAGE_PREFIX: "grafana"
RELEASE_VERSION: "${{ github.event.release.tag_name || 'test' }}"
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
path: loki

- name: prepare
id: prepare
env:
MAJOR_MINOR_VERSION_REGEXP: '([0-9]+\\.[0-9]+)'
RELEASE_TAG_REGEXP: '^([0-9]+\\.[0-9]+\\.[0-9]+)$'
working-directory: loki
run: |
echo "$(./tools/image-tag)" > .tag
if [[ "$RELEASE_VERSION" == "test" ]]; then
echo "RELEASE_VERSION is not set, using image tag"
RELEASE_VERSION="$(cat .tag)"
fi
echo "RELEASE_VERSION: $RELEASE_VERSION"
# if the tag matches the pattern `D.D.D` then RELEASE_NAME="D-D-x", otherwise RELEASE_NAME="next"
RELEASE_NAME=$([[ $RELEASE_VERSION =~ $RELEASE_TAG_REGEXP ]] && echo $RELEASE_TAG | grep -oE $MAJOR_MINOR_VERSION_REGEXP | sed "s/\\./-/g" | sed "s/$/-x/" || echo "next")
echo "RELEASE_NAME: $RELEASE_NAME"
echo "release_version=${RELEASE_VERSION}" >> "$GITHUB_OUTPUT"
echo "release_name=${RELEASE_NAME}" >> "$GITHUB_OUTPUT"
- id: "get-github-app-token"
name: "get github app token"
uses: "actions/create-github-app-token@v1"
with:
app-id: "${{ secrets.APP_ID }}"
owner: "${{ github.repository_owner }}"
private-key: "${{ secrets.APP_PRIVATE_KEY }}"

- name: "Set up QEMU"
uses: "docker/setup-qemu-action@v3"
- name: "set up docker buildx"
uses: "docker/setup-buildx-action@v3"
- name: "Login to DockerHub (from vault)"
uses: "grafana/shared-workflows/actions/dockerhub-login@main"

- name: "Build and push"
timeout-minutes: "${{ fromJSON(env.BUILD_TIMEOUT) }}"
uses: "docker/build-push-action@v6"
with:
build-args: "IMAGE_TAG=${{ steps.prepare.outputs.release_version }}"
context: loki
file: "loki/cmd/logql-analyzer/Dockerfile"
platforms: "linux/amd64"
push: true
tags: "grafana/logql-analyzer:${{ steps.prepare.outputs.release_version }}"

- name: Log in to Google Artifact Registry
uses: grafana/shared-workflows/actions/login-to-gar@main
with:
registry: "us-docker.pkg.dev"
environment: "prod"

- name: Update to latest image
env:
GITHUB_TOKEN: ${{ steps.get-github-app-token.outputs.token }}
RELEASE_NAME: ${{ steps.prepare.outputs.release_name }}
RELEASE_VERSION: ${{ steps.prepare.outputs.release_version }}
run: |
set -e -o pipefail
cat << EOF > config.json
{
"repo_name": "deployment_tools",
"destination_branch": "master",
"git_author_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"git_author_name": "version_bumper[bot]",
"git_committer_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"git_committer_name": "version_bumper[bot]",
"pull_request_branch_prefix": "logql-analyzer/updater",
"pull_request_enabled": true,
"pull_request_existing_strategy": "replace",
"pull_request_title_prefix": "[logql-analyzer updater] ",
"pull_request_message": "Add logql-analyzer version to ${RELEASE_VERSION} to supported versions",
"update_jsonnet_attribute_configs": [
{
"file_path": "ksonnet/environments/logql-analyzer/supported-versions.libsonnet",
"jsonnet_key": "${RELEASE_NAME}",
"jsonnet_value": "grafana/logql-analyzer:${RELEASE_VERSION}-amd64",
"upsert": true
}
]
}
EOF
docker run --rm \
-e GITHUB_TOKEN="$GITHUB_TOKEN" \
-e CONFIG_JSON="$(cat config.json)" us-docker.pkg.dev/grafanalabs-global/docker-deployment-tools-prod/updater |& tee updater-output.log
18 changes: 7 additions & 11 deletions .github/workflows/scripts/common.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,20 @@ get_yaml_node() {
# Increments the part of the semver string
# $1: version itself
# $2: number of part: 0 – major, 1 – minor, 2 – patch
# shellcheck disable=SC2207,SC2046,SC2248,SC2250
increment_semver() {
local delimiter=.
local array=("$(echo "$1" | tr "${delimiter}" '\n')")
array[$2]=$((array[$2] + 1))
echo "$(
local IFS=${delimiter}
echo "${array[*]}"
)"
local array=($(echo "$1" | tr $delimiter '\n'))
array[$2]=$((array[$2]+1))
echo $(local IFS=$delimiter ; echo "${array[*]}")
}

# Sets the patch segment of a semver to 0
# $1: version itself
# shellcheck disable=SC2207,SC2046,SC2248,SC2250
set_semver_patch_to_zero() {
local delimiter=.
local array=("$(echo "$1" | tr "${delimiter}" '\n')")
local array=($(echo "$1" | tr $delimiter '\n'))
array[2]="0"
echo "$(
local IFS=${delimiter}
echo "${array[*]}"
)"
echo $(local IFS=$delimiter ; echo "${array[*]}")
}
3 changes: 2 additions & 1 deletion .github/workflows/scripts/helm-tagged-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ sed --in-place \

make TTY='' helm-docs

echo "::set-output name=new_chart_version::${new_chart_version}"
# shellcheck disable=SC2154,SC2250
echo "new_chart_version=${new_chart_version}" >> "$GITHUB_OUTPUT"
50 changes: 40 additions & 10 deletions .github/workflows/scripts/helm-weekly-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ source "${script_dir}/common.sh"
find_latest_image_tag() {
local docker_hub_repo=$1
local regExp="^(k|weekly-k)\d+-[a-z0-9]+"
crane ls "${docker_hub_repo}" | grep -P "${regExp}" | sed -E "s/([weekly-]*k[[:digit:]]*)-([^-]*).*/\1-\2/g" | uniq | sort -Vur | head -1
local crane_results
crane_results="$(crane ls "${docker_hub_repo}" | grep -P "${regExp}" | sed -E "s/([weekly-]*k[[:digit:]]*)-([^-]*).*/\1-\2/g" | sort -Vur)"
set +o pipefail
echo "${crane_results}" | head -1
set -o pipefail
}

# takes k197-abcdef and returns r197, k197-abcdef-arm64 and returns k197, weekly-k197-abcdef and returns k197
Expand All @@ -22,6 +26,7 @@ extract_k_version() {
calculate_next_chart_version() {
local current_chart_version=$1
local latest_image_tag=$2
local k_release=$3

local current_chart_semver
current_chart_semver=$(echo "${current_chart_version}" | grep -P -o '^(\d+.){2}\d+')
Expand All @@ -35,7 +40,12 @@ calculate_next_chart_version() {
# Also reset the patch release number to 0.
new_chart_semver=$(set_semver_patch_to_zero "${new_chart_semver}")
fi
echo "${new_chart_semver}-weekly.${new_chart_weekly}"

if ${k_release}; then
echo "${new_chart_semver}-weekly.${new_chart_weekly}"
else
echo "${new_chart_semver}"
fi
}

validate_version_update() {
Expand All @@ -60,25 +70,45 @@ validate_version_update() {
fi
}

k_release=false
if [[ "$1" == "-k" ]]; then
k_release=true
shift
fi

values_file=production/helm/loki/values.yaml
chart_file=production/helm/loki/Chart.yaml

latest_loki_tag=$(find_latest_image_tag grafana/loki)
latest_gel_tag=$(find_latest_image_tag grafana/enterprise-logs)
current_chart_version=$(get_yaml_node "${chart_file}" .version)
new_chart_version=$(calculate_next_chart_version "${current_chart_version}" "${latest_loki_tag}")
new_chart_version=$(calculate_next_chart_version "${current_chart_version}" "${latest_loki_tag}" "${k_release}")

validate_version_update "${new_chart_version}" "${current_chart_version}" "${latest_gel_tag}" "${latest_loki_tag}"

update_yaml_node "${values_file}" .loki.image.tag "${latest_loki_tag}"
update_yaml_node "${values_file}" .enterprise.image.tag "${latest_gel_tag}"
update_yaml_node "${chart_file}" .appVersion "$(extract_k_version "${latest_loki_tag}")"
if ${k_release}; then
update_yaml_node "${values_file}" .loki.image.tag "${latest_loki_tag}"
update_yaml_node "${values_file}" .enterprise.image.tag "${latest_gel_tag}"
update_yaml_node "${chart_file}" .appVersion "$(extract_k_version "${latest_loki_tag}")"
fi

update_yaml_node "${chart_file}" .version "${new_chart_version}"

sed --in-place \
--regexp-extended \
"s/(.*\<AUTOMATED_UPDATES_LOCATOR\>.*)/\1\n\n## ${new_chart_version}\n\n- \[CHANGE\] Changed version of Grafana Loki to ${latest_loki_tag}\n- \[CHANGE\] Changed version of Grafana Enterprise Logs to ${latest_gel_tag}/g" production/helm/loki/CHANGELOG.md
if ${k_release}; then
sed --in-place \
--regexp-extended \
"s/(.*\<AUTOMATED_UPDATES_LOCATOR\>.*)/\1\n\n## ${new_chart_version}\n\n- \[CHANGE\] Changed version of Grafana Loki to ${latest_loki_tag}\n- \[CHANGE\] Changed version of Grafana Enterprise Logs to ${latest_gel_tag}/g" production/helm/loki/CHANGELOG.md
else
sed --in-place \
--regexp-extended \
"s/(.*\<AUTOMATED_UPDATES_LOCATOR\>.*)/\1\n\n## ${new_chart_version}/g" production/helm/loki/CHANGELOG.md
fi

make TTY='' helm-docs

echo "::set-output name=new_chart_version::${new_chart_version}"
# shellcheck disable=SC2154,SC2250
echo "new_chart_version=${new_chart_version}" >> "$GITHUB_OUTPUT"
if ${k_release}; then
# shellcheck disable=SC2154,SC2250
echo "weekly=$(extract_k_version "${latest_loki_tag}")" >> "$GITHUB_OUTPUT"
fi
5 changes: 5 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ ifeq ($(BUILD_IN_CONTAINER),true)
-c /helm-docs/production/helm/ \
-t reference.md.gotmpl \
-o reference.md
$(PODMAN) run --rm --volume "$(realpath ..):/helm-docs" -u "$$(id -u)" "docker.io/jnorwood/helm-docs:v1.11.0" \
-c /helm-docs/production/helm/ \
-t README.md.gotmpl \
-o README.md
else
helm-docs -c ../production/helm/ -t reference.md.gotmpl -o reference.md
helm-docs -c ../production/helm/ -t README.md.gotmpl -o README.md
endif
mv "$(basename $<)" "$@"
Loading

0 comments on commit 5d6955f

Please sign in to comment.