stages:
  - dockerbuild
  - kustomize_tag_push

variables:
  REGION_id: cn-shenzhen
  REGISTRY: mmc-registry.cn-shenzhen.cr.aliyuncs.com
  IMAGE: admin
  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_IMAGE: admin
  ACR_EE_TAG: $CI_COMMIT_SHA

  JAVA_VERSION: '8'
  GITLAB_URL: https://oauth2:ZhN6PrYzu9ELfyVq_KE5@git.mmcuav.cn/iuav/csf-admin.git

docker_build_dev:
  stage: dockerbuild
  variables:
    NAMESPACE: sharefly-dev
    ACR_EE_NAMESPACE: sharefly-dev
    PROFILES_ACTIVE: development
  only:
    - develop
  script:
    - echo "dev docker build"
    - echo $ACR_EE_USERNAME
    - echo $ACR_EE_REGISTRY
    - docker login -u $ACR_EE_USERNAME -p 'MMC@2023&ACR' $ACR_EE_REGISTRY
    - docker build --build-arg PROFILES_ACTIVE=$PROFILES_ACTIVE -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
  after_script:
    - chmod a+x ./send-webhook.sh # 给脚本文件添加可执行权限
    - ./send-webhook.sh $ACR_EE_NAMESPACE $PROFILES_ACTIVE # 执行脚本文件

docker_build_prod:
  stage: dockerbuild
  variables:
    NAMESPACE: sharefly
    ACR_EE_NAMESPACE: sharefly
    PROFILES_ACTIVE: production
  only:
    - master
  script:
    - echo "prod docker build"
    - echo $ACR_EE_USERNAME
    - echo $ACR_EE_REGISTRY
    - docker login -u $ACR_EE_USERNAME -p 'MMC@2023&ACR' $ACR_EE_REGISTRY
    - docker build --build-arg PROFILES_ACTIVE=$PROFILES_ACTIVE -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
  after_script:
    - chmod a+x ./send-webhook.sh # 给脚本文件添加可执行权限
    - ./send-webhook.sh $ACR_EE_NAMESPACE $PROFILES_ACTIVE # 执行脚本文件


kustomize_set_image_dev:
  stage: kustomize_tag_push
  variables:
    NAMESPACE: sharefly-dev
    ACR_EE_NAMESPACE: sharefly-dev
  only:
    - develop
  before_script:
    - echo "dev set image"
    - git config --global user.name "bax" #配置本地仓库用户名信息
    - git config --global user.email "baoaxin1999@163.com" #配置本地仓库邮箱信息
  script:
    - git remote -v
    - git checkout -B develop
    - cd kustomization/overlays/dev
    - kustomize edit set image REGISTRY/NAMESPACE/IMAGE:TAG=$REGISTRY/$NAMESPACE/$IMAGE:$TAG
    - cat kustomization.yaml
    - git remote set-url origin "$GITLAB_URL"
    - git commit -am '[skip ci] DEV image update'  #git 本地提交，注意“skip ci”为gitlab流水线文件内置关键字，作用为跳过ci流水线操作，未设置可能导致流水线进入死循环
    - git push --set-upstream origin develop  #重新提交修改镜像版本后的代码



kustomize_set_image_prod:
  stage: kustomize_tag_push
  variables:
    NAMESPACE: sharefly
    ACR_EE_NAMESPACE: sharefly
  only:
    - master
  before_script:
    - echo "prod set image"
    - echo "master"
    - git config --global user.name "bax" #配置本地仓库用户名信息
    - git config --global user.email "baoaxin1999@163.com" #配置本地仓库邮箱信息
  script:
    - git remote -v
    - git checkout -B master
    - cd kustomization/overlays/prod
    - kustomize edit set image REGISTRY/NAMESPACE/IMAGE:TAG=$REGISTRY/$NAMESPACE/$IMAGE:$TAG
    - cat kustomization.yaml
    - git remote set-url origin "$GITLAB_URL"
    - git commit -am '[skip ci] DEV image update'  #git 本地提交，注意“skip ci”为gitlab流水线文件内置关键字，作用为跳过ci流水线操作，未设置可能导致流水线进入死循环
    - git push --set-upstream origin master  #重新提交修改镜像版本后的代码
