feat!: deploy flux with helm #129
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
name: "Helm Repository Sync" | |
on: | |
workflow_dispatch: | |
inputs: | |
clusterName: | |
description: Cluster Name | |
default: main | |
required: true | |
helmRepoNamespace: | |
description: Helm Repository Namespace | |
default: flux-system | |
required: true | |
helmRepoName: | |
description: Helm Repository Name | |
required: true | |
pull_request: | |
branches: ["main"] | |
paths: ["kubernetes/**/helmrelease.yaml"] | |
jobs: | |
sync: | |
name: Helm Repository Sync | |
runs-on: ["gha-runner-scale-set"] | |
steps: | |
- name: Configure 1password | |
uses: 1password/load-secrets-action/configure@v2 | |
with: | |
service-account-token: ${{ secrets.ONEPASS_SA_TOKEN }} | |
- name: Get Secrets | |
uses: 1password/load-secrets-action@v2 | |
with: | |
export-env: true | |
env: | |
BOT_APP_ID: op://Kubernetes/github-bot/BOT_APP_ID | |
BOT_APP_PRIVATE_KEY: op://Kubernetes/github-bot/BOT_APP_PRIVATE_KEY | |
KUBECONFIG_BASE64: op://Kubernetes/kubernetes/KUBECONFIG_BASE64 | |
- name: Generate Token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ env.BOT_APP_ID }} | |
private-key: ${{ env.BOT_APP_PRIVATE_KEY }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
- name: Setup Homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Setup Workflow Tools | |
run: brew install fluxcd/tap/flux | |
- name: Write kubeconfig | |
id: kubeconfig | |
uses: timheuer/base64-to-file@v1 | |
with: | |
encodedString: ${{ env.KUBECONFIG_BASE64 }} | |
fileName: kubeconfig | |
- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }} | |
name: Get Changed Files | |
id: changed-files | |
uses: tj-actions/changed-files@v45 | |
with: | |
files: kubernetes/**/helmrelease.yaml | |
safe_output: false | |
- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }} | |
name: List All Changed Files | |
run: echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }} | |
- if: ${{ github.event.inputs.clusterName == '' && github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }} | |
name: Sync Helm Repository | |
env: | |
KUBECONFIG: ${{ steps.kubeconfig.outputs.filePath }} | |
shell: bash | |
run: | | |
declare -a repos=() | |
for f in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do | |
cluster_name=$(echo "${f}" | awk -F'/' '{print $2}') | |
repo_namespace="$(yq -r '.spec.chart.spec.sourceRef.namespace' "${f}")" | |
repo_name="$(yq -r '.spec.chart.spec.sourceRef.name' "${f}")" | |
repos+=("${cluster_name}:${repo_namespace}:${repo_name}") | |
done | |
mapfile -t repos < <(printf "%s\n" "${repos[@]}" | sort -u) | |
for r in "${repos[@]}"; do | |
IFS=':' read -r cluster_name repo_namespace repo_name <<< "${r}" | |
flux \ | |
--context ${cluster_name} \ | |
--namespace ${repo_namespace} \ | |
reconcile source helm ${repo_name} || true | |
done | |
- if: ${{ github.event.inputs.clusterName != '' && github.event.inputs.helmRepoNamespace != '' && github.event.inputs.helmRepoName != '' }} | |
name: Sync Helm Repository | |
env: | |
KUBECONFIG: ${{ steps.kubeconfig.outputs.filePath }} | |
shell: bash | |
run: | | |
flux \ | |
--context ${{ github.event.inputs.clusterName }} \ | |
--namespace ${{ github.event.inputs.helmRepoNamespace }} \ | |
reconcile source helm ${{ github.event.inputs.helmRepoName }} || true |