name: Sync docker images of minikube to Alibaba Cloud
on:
  workflow_dispatch:
  schedule:
    # every day at 7am & 7pm pacific
    - cron: "0 2,14 * * *"
env:
  GOPROXY: https://proxy.golang.org
  GO_VERSION: '1.19.1'
permissions:
  contents: read

jobs:
  sync-images:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./image-syncer
    steps:
    - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
      with:
        repository: denverdino/image-syncer
        path: ./image-syncer

    - name: Set up Go
      uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
      with:
        go-version: ${{env.GO_VERSION}}

    - name: Build
      run: make

    - name: Synchronize images to Alibaba Cloud Container Registry Service
      env: 
        ACR_USER: ${{ secrets.ALIBABA_CLOUD_ACR_USER }}
        ACR_PASSWORD: ${{ secrets.ALIBABA_CLOUD_ACR_PASSWORD }}
        DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
        DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}

      run: ./image-syncer --auth=auth.json --images=images.json --days=2 --proc=2
