feat: manage grafana content as code with fast dashboard workflow
This commit is contained in:
91
.gitea/workflows/dashboards.yml
Normal file
91
.gitea/workflows/dashboards.yml
Normal file
@@ -0,0 +1,91 @@
|
||||
name: Deploy Grafana Content
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "ansible/dashboards.yml"
|
||||
- "ansible/roles/observability-content/**"
|
||||
- ".gitea/workflows/dashboards.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
TF_VERSION: "1.7.0"
|
||||
|
||||
jobs:
|
||||
dashboards:
|
||||
name: Grafana Content
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Terraform
|
||||
uses: hashicorp/setup-terraform@v3
|
||||
with:
|
||||
terraform_version: ${{ env.TF_VERSION }}
|
||||
|
||||
- name: Setup SSH Keys
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_ed25519.pub
|
||||
chmod 644 ~/.ssh/id_ed25519.pub
|
||||
|
||||
- name: Terraform Init
|
||||
working-directory: terraform
|
||||
run: |
|
||||
terraform init \
|
||||
-backend-config="endpoint=${{ secrets.S3_ENDPOINT }}" \
|
||||
-backend-config="bucket=${{ secrets.S3_BUCKET }}" \
|
||||
-backend-config="region=auto" \
|
||||
-backend-config="access_key=${{ secrets.S3_ACCESS_KEY }}" \
|
||||
-backend-config="secret_key=${{ secrets.S3_SECRET_KEY }}" \
|
||||
-backend-config="skip_requesting_account_id=true"
|
||||
|
||||
- name: Detect runner egress IP
|
||||
run: |
|
||||
RUNNER_IP=$(curl -fsSL https://api.ipify.org)
|
||||
echo "RUNNER_CIDR=[\"${RUNNER_IP}/32\"]" >> "$GITHUB_ENV"
|
||||
echo "Runner egress IP: ${RUNNER_IP}"
|
||||
|
||||
- name: Open SSH/API for current runner CIDR
|
||||
working-directory: terraform
|
||||
run: |
|
||||
terraform apply \
|
||||
-target=hcloud_firewall.cluster \
|
||||
-var="hcloud_token=${{ secrets.HCLOUD_TOKEN }}" \
|
||||
-var="ssh_public_key=$HOME/.ssh/id_ed25519.pub" \
|
||||
-var="ssh_private_key=$HOME/.ssh/id_ed25519" \
|
||||
-var="allowed_ssh_ips=${RUNNER_CIDR}" \
|
||||
-var="allowed_api_ips=${RUNNER_CIDR}" \
|
||||
-auto-approve
|
||||
|
||||
- name: Install Python Dependencies
|
||||
run: |
|
||||
apt-get update && apt-get install -y python3-pip
|
||||
pip3 install --break-system-packages ansible kubernetes jinja2 pyyaml
|
||||
|
||||
- name: Install Ansible Collections
|
||||
run: ansible-galaxy collection install -r ansible/requirements.yml
|
||||
|
||||
- name: Generate Ansible Inventory
|
||||
working-directory: ansible
|
||||
run: python3 generate_inventory.py
|
||||
|
||||
- name: Apply dashboards and datasources
|
||||
working-directory: ansible
|
||||
run: |
|
||||
ansible-playbook dashboards.yml \
|
||||
-e "cluster_name=k8s-cluster"
|
||||
env:
|
||||
ANSIBLE_HOST_KEY_CHECKING: "False"
|
||||
|
||||
- name: Verify Grafana content resources
|
||||
working-directory: ansible
|
||||
run: |
|
||||
ansible -i inventory.ini 'control_plane[0]' -m command -a "kubectl -n observability get configmap | grep grafana"
|
||||
env:
|
||||
ANSIBLE_HOST_KEY_CHECKING: "False"
|
||||
Reference in New Issue
Block a user