name: Build and Push to ACR

on:
  push:
    branches: [ "develop" ]

env:
  REGION_ID: cn-shenzhen
  REGISTRY: mmc-registry.cn-shenzhen.cr.aliyuncs.com
<<<<<<< HEAD
<<<<<<< HEAD
  NAMESPACE: sharefly-dev
=======
  NAMESPACE: sharefly
>>>>>>> 39dc22a (Create develop.yml)
=======
  NAMESPACE: sharefly-dev
>>>>>>> 31b1b2a (Update develop.yml)
  IMAGE: ims
  TAG: ${{ github.sha }}

  ACR_EE_REGISTRY: mmc-registry.cn-shenzhen.cr.aliyuncs.com
  ACR_EE_INSTANCE_ID: cri-yhk5zgfc2v1sia6l
<<<<<<< HEAD
<<<<<<< HEAD
  ACR_EE_NAMESPACE: sharefly-dev
=======
  ACR_EE_NAMESPACE: sharefly
>>>>>>> 39dc22a (Create develop.yml)
=======
  ACR_EE_NAMESPACE: sharefly-dev
>>>>>>> 31b1b2a (Update develop.yml)
  ACR_EE_IMAGE: ims
  ACR_EE_TAG: ${{ github.sha }}
  JAVA_VERSION: '8'
  GITLAB_URL: https://oauth2:MjVJKxB7m4tCy7symBzn@git.mmcuav.cn/iuav/ims.git

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    environment: dev

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up JDK 8
        uses: actions/setup-java@v1
        with:
          java-version: ${{env.JAVA_VERSION}}

      - name: Login to ACR EE with the AccessKey pair
        uses: aliyun/acr-login@v1
        with:
          login-server: "https://${{ env.ACR_EE_REGISTRY }}"
          region-id: "${{ env.REGION_ID }}"
          username: "QD--KeBiTeHangKong@1354706964800968"
          password: "MMC@2023&ACR"
          instance-id: "${{ env.ACR_EE_INSTANCE_ID }}"

      - name: Build and push image to ACR EE
        run: |
          mvn clean package
          docker build -t "$ACR_EE_REGISTRY/$ACR_EE_NAMESPACE/$ACR_EE_IMAGE:$TAG" .
          docker push "$ACR_EE_REGISTRY/$ACR_EE_NAMESPACE/$ACR_EE_IMAGE:$TAG"

      - name: Kustomize Set Image
        run: |-
          cd kustomization/overlays/dev
          curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"  | bash /dev/stdin 3.8.6
          ./kustomize edit set image REGISTRY/NAMESPACE/IMAGE:TAG=$REGISTRY/$NAMESPACE/$IMAGE:$TAG

      - name: Commit and Push
        run: |
          git config user.name "Chuck"
          git config user.email "Chuck@users.noreply.github.com"
          git remote set-url origin "$GITLAB_URL"
          git commit -am "Generated Image New Tag"
          git push origin develop