stages:
  - clean
  - dockerbuild
  - deploy
  - push

variables:
  REGION_id: cn-shenzhen
  REGISTRY: mmc-registry.cn-shenzhen.cr.aliyuncs.com
  NAMESPACE: sharefly-dev
  IMAGE: cms
  TAG: $CI_COMMIT_SHA

  ACR_EE_USERNAME: QD--KeBiTeHangKong@1354706964800968
  ACR_EE_PASSWORD: MMC@2023&ACR
  ACR_EE_REGISTRY: mmc-registry.cn-shenzhen.cr.aliyuncs.com
  ACR_EE_INSTANCE_ID: cri-yhk5zgfc2v1sia6l
  ACR_EE_NAMESPACE: sharefly-dev
  ACR_EE_IMAGE: cms-test
  ACR_EE_TAG: $CI_COMMIT_SHA
  JAVA_VERSION: '8'
  GITLAB_URL: https://oauth2:6wsXz1Kq2biuG9P1NQ6G@git.mmcuav.cn/dzl/cms-ci-test.git
  GITLAB_REGISTRY: http://git.mmcuav.cn/dzl/cms-ci-test.git


mvn_clean:
  stage: clean
  before_script:
    - git remote -v
    - git remote set-url origin "$GITLAB_URL"
    - git config --global user.name "bax" #配置本地仓库用户名信息
    - git config --global user.email "bax@example.com" #配置本地仓库邮箱信息
    - git pull origin master
  script:
    - echo "清理中ing.........."
    - mvn clean -B -Dmaven.test.skip=true --settings /usr/local/maven/conf/settings.xml

docker_build:
  stage: dockerbuild
  script:
    - echo $ACR_EE_USERNAME
    - echo $ACR_EE_REGISTRY
    - mvn package -Dmaven.test.skip=true --settings /usr/local/maven/conf/settings.xml
    - docker login -u $ACR_EE_USERNAME -p 'MMC@2023&ACR' $ACR_EE_REGISTRY
    - 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}"
    - docker logout

cms-argocd-deploy:
  stage: deploy
  script:
    - cd kustomization/overlays/dev
    - kustomize edit set image REGISTRY/NAMESPACE/IMAGE:TAG=$REGISTRY/$NAMESPACE/$IMAGE:$TAG
    - cat kustomization.yaml
    - git commit -am '[skip ci] DEV image update'  #git 本地提交，注意“skip ci”为gitlab流水线文件内置关键字，作用为跳过ci流水线操作，未设置可能导致流水线进入死循环
    - git push origin master  #重新提交修改镜像版本后的代码




