name: Rebuild & push prometheus images
on:
  schedule:
    - cron: "0 0 * * *"
  pull_request:
  push:
    paths:
      - 'oci/prometheus/Dockerfile'
  workflow_dispatch:
    branches:
      - main

jobs:
  alpine:
    runs-on: ubuntu-latest
    name: Build prometheus image
    steps:
      - uses: actions/checkout@master

      - name: get /usr/share/zoneinfo/Asia/Shanghai
        run: cp /usr/share/zoneinfo/Asia/Shanghai zoneinfo-Shanghai
        working-directory: oci/prometheus/

      - name: 'Artifact: build && push -> harbor.onwalk.net/base/prometheus'
        uses: aevea/action-kaniko@master
        with:
          registry: harbor.onwalk.net
          username: admin 
          password: ${{ secrets.HELM_REPO_PASSWORD }}
          path: './oci/prometheus/'
          build_file: 'Dockerfile'
          image: base/prometheus/prometheus
          tag: v2.48.1
          cache: true
          cache_registry: cache

  sync-images:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Initialization environment
      shell: bash
      env:
        PASSWORD: ${{ secrets.HELM_REPO_PASSWORD }}
      run: docker login --username=admin --password=${PASSWORD} harbor.onwalk.net

    - name: Sync images
      shell: bash
      run: |
        docker pull quay.io/prometheus-operator/prometheus-config-reloader:v0.70.0
        docker tag  quay.io/prometheus-operator/prometheus-config-reloader:v0.70.0 harbor.onwalk.net/base/prometheus-operator/prometheus-config-reloader:v0.70.0
        docker push harbor.onwalk.net/base/prometheus-operator/prometheus-config-reloader:v0.70.0

        docker pull quay.io/prometheus/node-exporter:v1.7.0 
        docker tag  quay.io/prometheus/node-exporter:v1.7.0 harbor.onwalk.net/base/prometheus/node-exporter:v1.7.0
        docker push harbor.onwalk.net/base/prometheus/node-exporter:v1.7.0

        docker pull quay.io/prometheus-operator/prometheus-operator:v0.70.0 
        docker tag  quay.io/prometheus-operator/prometheus-operator:v0.70.0 harbor.onwalk.net/base/prometheus-operator/prometheus-operator:v0.70.0
        docker push harbor.onwalk.net/base/prometheus-operator/prometheus-operator:v0.70.0

        docker pull registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.10.1 
        docker tag  registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.10.1 harbor.onwalk.net/base/kube-state-metrics/kube-state-metrics:v2.10.1
        docker push harbor.onwalk.net/base/kube-state-metrics/kube-state-metrics:v2.10.1

        docker pull registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20221220-controller-v1.5.1-58-g787ea74b6
        docker tag  registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20221220-controller-v1.5.1-58-g787ea74b6 harbor.onwalk.net/base/ingress-nginx/kube-webhook-certgen:v20221220-controller-v1.5.1-58-g787ea74b6
        docker push harbor.onwalk.net/base/ingress-nginx/kube-webhook-certgen:v20221220-controller-v1.5.1-58-g787ea74b6
