variables:
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true -Dmaven.test.skip=true"
  USERNAME: eazytec #hub.eazytec-cloud.com用户名
  TOKEN: Eazytec2023  #hub.eazytec-cloud.com的CLI密码
  REPO: hub.eazytec-cloud.com  #hub.eazytec-cloud.com的地址
  NAMESPACE: yichengstreet        #项目名
  IMAGE: yichengstreet-be         #项目英文名
  OKD: osr.eazytec.intra:8443  #pass平台的地址
  OKDUSER: sunf@eazytec.com #pass平台的用户名
  OKDPASS: P@44w0rd          #pass平台的密码
  PROJECT: yichengstreet #测试环境项目英文名
  IMAGESTREAM: yichengstreet-be #项目英文名
  TAG: $CI_COMMIT_REF_NAME

cache:
  paths:
    - .m2/repository2

stages:
  - package
  - deploy
  - publish


package:
  stage: package
  script:
    - 'mvn $MAVEN_CLI_OPTS package -Dmaven.test.skip=true'
  artifacts:
    paths:
      - ./ruoyi-admin/target/ruoyi-admin.jar
  image: hub.eazytec-cloud.com/devops/maven:3.3.9-jdk-8
  only:
    - main


deploy:
  image: hub.eazytec-cloud.com/devops/docker:18
  services:
    - name: hub.eazytec-cloud.com/devops/docker:18-dind
      command: ["--insecure-registry=https://docker-registry-default.app.eazytec.intra", "--registry-mirror=http://bdex97.eazytec.intra:5000"]
      alias: docker
  before_script:
    - docker info
    - docker login -p "${TOKEN}" -u ${USERNAME} ${REPO}
  stage: deploy
  script:
    - if [ $TAG == "master" ]; then TAG="latest"; fi
    - docker build --pull -t ${REPO}/${NAMESPACE}/${IMAGE}:${TAG} .
    - docker push ${REPO}/${NAMESPACE}/${IMAGE}:${TAG}
  only:
    - main

publish:
  image: hub.eazytec-cloud.com/devops/oc:3.11
  before_script:
    - oc login -p "${OKDPASS}" -u ${OKDUSER} --insecure-skip-tls-verify ${OKD}
    - oc project ${PROJECT}
  stage: publish
  script:
    - if [ $TAG == "master" ]; then TAG="latest"; fi
    - oc import-image ${IMAGESTREAM}:${TAG} --from=${REPO}/${NAMESPACE}/${IMAGE}:${TAG} --confirm
  only:
    - main