name: Sync Images for Grafana

on:
  schedule:
    - cron: "0 0 * * *"
  pull_request:
    paths:
      - '.github/workflows/sync-images-grafana.yaml'
  workflow_dispatch:
    branches:
      - main

jobs:
  grafana:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Initialize and grafana images
        env:
          USER: ${{ secrets.IMAGES_REPO_USER }}
          PASSWORD: ${{ secrets.IMAGES_REPO_PASSWORD }}
        shell: bash
        run: |
          sudo apt update && sudo apt install -y git
          echo "$PASSWORD" | docker login --username=$USER --password-stdin images.onwalk.net
          docker pull docker.io/grafana/grafana:11.3.0
          docker tag docker.io/grafana/grafana:11.3.0 images.onwalk.net/public/grafana/grafana:11.3.0
          docker push images.onwalk.net/public/grafana/grafana:11.3.0

  grafana-agent:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Initialize and grafana agent images
        env:
          USER: ${{ secrets.IMAGES_REPO_USER }}
          PASSWORD: ${{ secrets.IMAGES_REPO_PASSWORD }}
        shell: bash
        run: |
          sudo apt update && sudo apt install -y git
          echo "$PASSWORD" | docker login --username=$USER --password-stdin images.onwalk.net
          docker pull docker.io/grafana/agent:v0.42.0
          docker tag docker.io/grafana/agent:v0.42.0 images.onwalk.net/public/grafana/agent:v0.42.0
          docker push images.onwalk.net/public/grafana/agent:v0.42.0

  grafana-alloy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Initialize and grafana images
        env:
          USER: ${{ secrets.IMAGES_REPO_USER }}
          PASSWORD: ${{ secrets.IMAGES_REPO_PASSWORD }}
        shell: bash
        run: |
          sudo apt update && sudo apt install -y git
          echo "$PASSWORD" | docker login --username=$USER --password-stdin images.onwalk.net
          docker pull docker.io/grafana/alloy:v1.5.1
          docker tag docker.io/grafana/alloy:v1.5.1 images.onwalk.net/public/grafana/alloy:v1.5.1
          docker push images.onwalk.net/public/grafana/alloy:v1.5.1

  configmap-reload:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Initialize and configmap-reload images
        env:
          USER: ${{ secrets.IMAGES_REPO_USER }}
          PASSWORD: ${{ secrets.IMAGES_REPO_PASSWORD }}
        shell: bash
        run: |
          sudo apt update && sudo apt install -y git
          echo "$PASSWORD" | docker login --username=$USER --password-stdin images.onwalk.net
          docker pull ghcr.io/jimmidyson/configmap-reload:v0.12.0
          docker tag ghcr.io/jimmidyson/configmap-reload:v0.12.0 images.onwalk.net/public/jimmidyson/configmap-reload:v0.12.0
          docker push images.onwalk.net/public/jimmidyson/configmap-reload:v0.12.0
