name: SYNC Images

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

env:
  REPO_URL: https://github.com/open-source-solution-design/MicroService.git 
  REPO_BRANCH: main
  TZ: Asia/Shanghai
  TAG: 0.1.4 

jobs:
  sync-fluxcd-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 artifact.onwalk.net

    - 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 "ghcr.io/fluxcd/flux-cli:v2.2.0" "artifact.onwalk.net/public/fluxcd/flux-cli:v2.2.0"
        sync_image "ghcr.io/fluxcd/helm-controller:v0.37.0" "artifact.onwalk.net/public/fluxcd/helm-controller:v0.37.0"
        sync_image "ghcr.io/fluxcd/image-automation-controller:v0.37.0" "artifact.onwalk.net/public/fluxcd/image-automation-controller:v0.37.0"
        sync_image "ghcr.io/fluxcd/image-reflector-controller:v0.31.1" "artifact.onwalk.net/public/fluxcd/image-reflector-controller:v0.31.1"
        sync_image "ghcr.io/fluxcd/kustomize-controller:v1.2.0" "artifact.onwalk.net/public/fluxcd/kustomize-controller:v1.2.0"
        sync_image "ghcr.io/fluxcd/notification-controller:v1.2.2" "artifact.onwalk.net/public/fluxcd/notification-controller:v1.2.2"
        sync_image "ghcr.io/fluxcd/source-controller:v1.2.2" "artifact.onwalk.net/public/fluxcd/source-controller:v1.2.2"
  sync-itsm-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 artifact.onwalk.net

    - 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" "artifact.onwalk.net/public/nginx:1.16.0"
        sync_image "busybox:1.28" "artifact.onwalk.net/public/busybox:1.28"
        sync_image "apache/apisix:3.8.0-debian" "artifact.onwalk.net/public/apache/apisix:3.8.0-debian"
        sync_image "apache/apisix-dashboard:3.0.0-alpine" "artifact.onwalk.net/public/apache/apisix-dashboard:3.0.0-alpine"
        sync_image "docker.io/bitnami/etcd:3.5.7-debian-11-r14" "artifact.onwalk.net/public/bitnami/etcd:3.5.7-debian-11-r14"
        sync_image "docker.io/bitnami/postgresql:15.2.0-debian-11-r24" "artifact.onwalk.net/public/bitnami/postgresql:15.2.0-debian-11-r24"
        sync_image "ghcr.io/novuhq/novu/ws:0.22.0" "artifact.onwalk.net/public/novuhq/novu/ws:0.22.0"
        sync_image "ghcr.io/novuhq/novu/api:0.22.0" "artifact.onwalk.net/public/novuhq/novu/api:0.22.0"
        sync_image "ghcr.io/novuhq/novu/web:0.22.0" "artifact.onwalk.net/public/novuhq/novu/web:0.22.0"
        sync_image "ghcr.io/novuhq/novu/worker:0.22.0" "artifact.onwalk.net/public/novuhq/novu/worker:0.22.0"
        sync_image "ghcr.io/windmill-labs/windmill:1.258.4" "artifact.onwalk.net/public/windmill-labs/windmill:1.258.4"
        sync_image "ghcr.io/windmill-labs/windmill-lsp:latest" "artifact.onwalk.net/public/windmill-labs/windmill-lsp:latest"
        sync_image "docker.io/bitnami/etcd:3.5.7-debian-11-r14" "artifact.onwalk.net/public/bitnami/etcd:3.5.7-debian-11-r14"
  sync-mysql-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 artifact.onwalk.net

    - 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 "docker.io/bitnami/mysql:8.0.36-debian-12-r8" "artifact.onwalk.net/public/bitnami/mysql:8.0.36-debian-12-r8"
