Skip to content

Instantly share code, notes, and snippets.

@mrkagelui
Last active January 13, 2022 03:35
Show Gist options
  • Save mrkagelui/0417b47df7089a21358a69fb02fe0849 to your computer and use it in GitHub Desktop.
Save mrkagelui/0417b47df7089a21358a69fb02fe0849 to your computer and use it in GitHub Desktop.
using turbolift to update helm chart version defined in buddy.works pipeline definitions
# Turbolift recipe to update helm template versions
#
# prerequisites:
# 1. https://github.com/Skyscanner/turbolift#installation
# 2. https://github.com/mikefarah/yq#install
#
# assumptions:
# 1. you have all buddy pipeline definitions under `/.buddy` directory of each repo and they all have `.yaml` or `.yml` extension
# 2. you define the helm chart version in an action of type `HELM` which has a list of `execute_commands`, and the version is passed in like `--version $version`. In other words, there's an action that looks like:
# - action: Render k8s manifest from Helm chart
# type: HELM
# trigger_condition: ALWAYS
# helm_repository_region: ap-southeast-1
# helm_repository_integration:
# hash_id: 5e85761fc5f225000f97dd99
# setup_commands:
# - helm plugin install https://github.com/hypnoglow/helm-s3.git --version 0.10.0
# execute_commands:
# - bash .buddy/scripts/apply_helm.sh --version 1.13.2
# kubectl_version: v1.18.2
# helm_version: v3.2.1
BRANCH_NAME=chore-update-helm
TARGET_HELM_VERSION=^1.13.3
# Initialize
turbolift init -n $BRANCH_NAME
cd $BRANCH_NAME
# Add list of repositories, alternatively, use gh-search to generate the list
# if this is the first time you use this, it's recommended that you add one repo to this to test it out before rolling out to all repos
cat <<EOF > repos.txt
xendit/xendit-fraud-detection-service
xendit/xendit-fraud-rule-manager
xendit/fraud-feature-manager
xendit/xendit-fraud-static-data-provider
xendit/xendit-key-aggregator
xendit/chargeback-service
xendit/fraud-channel-decision-manager
xendit/fingerprint-service
EOF
# Edit PR title and description
cat <<EOF > README.md
# chore: update helm chart version
Update helm chart version
EOF
cat <<EOF > update.sh
#!/bin/sh
shopt -s nullglob
for FILE in .buddy/*.{yaml,yml}; do
yq e --inplace '.[].actions[] |= select(.type == "HELM") .execute_commands[] |= sub("--version \d+\.\d+\.\d+", "--version '"$TARGET_HELM_VERSION"'")' \$FILE;
done
EOF
turbolift clone --no-fork
turbolift foreach sh $PWD/update.sh
turbolift commit --message "chore: update helm version"
turbolift foreach git push -u origin $BRANCH_NAME
turbolift create-prs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment