name: sync images

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

jobs:
  sync-images:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Initialization environment
      env:
        PASSWORD: ${{ secrets.HELM_REPO_PASSWORD }}
      shell: bash
      run: |
        sudo apt update
        sudo apt install git -y
        echo "$PASSWORD" | docker login --username=admin --password-stdin images.svc.plus

    - name: sync images
      shell: bash
      run: |
        function sync_image()
        {
          local src_image=$1
          local dest_image=$2
          docker pull $src_image
          docker tag  $src_image $dest_image
          docker push $dest_image
        }
        sync_image "nginx:1.16.0" "images.svc.plus/public/nginx:1.16.0"
        sync_image "busybox:1.28" "images.svc.plus/public/busybox:1.28"
        sync_image "bpatrik/pigallery2:latest" "images.svc.plus/public/pigallery2:latest"
        sync_image "nginx/nginx-ingress:2.4.0" "images.svc.plus/public/nginx/nginx-ingress:2.4.0"
        sync_image "hashicorp/vault:1.17.2" "images.svc.plus/public/hashicorp/vault:1.17.2"
        sync_image "hashicorp/vault-k8s:1.4.2" "images.svc.plus/public/hashicorp/vault-k8s:1.4.2"
        sync_image "ghcr.io/open-webui/open-webui:latest" "images.svc.plus/public/open-webui/open-webui:latest"
        sync_image "rancher/local-path-provisioner:v0.0.27" "images.svc.plus/public/rancher/local-path-provisioner:v0.0.27"
        sync_image "rancher/mirrored-pause:3.6" "images.svc.plus/public/rancher/mirrored-pause:3.6"
        sync_image "rancher/mirrored-metrics-server:v0.7.0" "images.svc.plus/public/rancher/mirrored-metrics-server:v0.7.0"
        sync_image "rancher/mirrored-library-busybox:1.36.1" "images.svc.plus/public/rancher/mirrored-library-busybox:1.36.1"
        sync_image "rancher/mirrored-coredns-coredns:1.10.1" "images.svc.plus/public/rancher/mirrored-coredns-coredns:1.10.1"
        sync_image "bitnami/external-dns:0.14.0-debian-11-r4" "images.svc.plus/public/bitnami/external-dns:0.14.0-debian-11-r4"
        sync_image "bitnami/harbor-core:2.8.2-debian-11-r6"   "images.svc.plus/public/bitnami/harbor-core:2.8.2-debian-11-r6"
        sync_image "bitnami/harbor-jobservice:2.8.2-debian-11-r5" "images.svc.plus/public/bitnami/harbor-jobservice:2.8.2-debian-11-r5"
        sync_image "bitnami/harbor-portal:2.8.2-debian-11-r5" "images.svc.plus/public/bitnami/harbor-portal:2.8.2-debian-11-r5"
        sync_image "bitnami/harbor-registry:2.8.2-debian-11-r5" "images.svc.plus/public/bitnami/harbor-registry:2.8.2-debian-11-r5"
        sync_image "bitnami/harbor-registryctl:2.8.2-debian-11-r5" "images.svc.plus/public/bitnami/harbor-registryctl:2.8.2-debian-11-r5"
        sync_image "bitnami/redis:7.2.5-debian-12-r4" "images.svc.plus/public/bitnami/redis:7.2.5-debian-12-r4"
        sync_image "bitnami/postgresql:15.2.0-debian-11-r11" "images.svc.plus/public/bitnami/postgresql:15.2.0-debian-11-r11"
