stages:
  - build
  - build2
  - deploy
variables:
  GIT_DEPTH: "1"

before_script:
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

.build-image:
  stage: build
  tags:
    - docker
  script:
    - docker build --pull -t $TARGET_IMAGE .
    - docker push $TARGET_IMAGE

build-base:
  extends: .build-image
  variables:
    TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG

.build-xformers:
  extends: .build-image
  stage: build2
  script:
    - docker build --pull --build-arg BASE=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG --build-arg=GRAPHIC_VERSION=$GRAPHIC_VERSION -f Dockerfile.xformers -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-xformers-$GRAPHIC_VERSION .
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-xformers-$GRAPHIC_VERSION

build-xformers-7.5:
  extends: .build-xformers
  variables: 
    GRAPHIC_VERSION: '7.5' # Quadro or 20xx

build-xformers-8.6:
  extends: .build-xformers
  variables: 
    GRAPHIC_VERSION: '8.6' # 30xx or A4000 A5000

#build-xformers-8.9:
#  extends: .build-xformers
#  variables: 
#    GRAPHIC_VERSION: '8.9' # 40xx

build-xformers-6.1:
  extends: .build-xformers
  variables: 
    GRAPHIC_VERSION: '6.1' # 10xx

.deploy:
  stage: deploy
  tags:
    - docker
  script:
    - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG $TARGET_IMAGE
    - docker push $TARGET_IMAGE

deploy_latest:
  extends: .deploy
  variables:
    TARGET_IMAGE: $CI_REGISTRY_IMAGE:latest
  only:
    - master

.deploy-xformers:
  extends: .deploy
  variables:
    TARGET_IMAGE: $CI_REGISTRY_IMAGE:latest
  only:
    - master
  script:
    - docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-xformers-$GRAPHIC_VERSION
    - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-xformers-$GRAPHIC_VERSION $CI_REGISTRY_IMAGE:xformers-$GRAPHIC_VERSION
    - docker push $CI_REGISTRY_IMAGE:xformers-$GRAPHIC_VERSION

deploy-xformers-7.5:
  extends: .deploy-xformers
  variables: 
    GRAPHIC_VERSION: '7.5'

deploy-xformers-8.6:
  extends: .deploy-xformers
  variables: 
    GRAPHIC_VERSION: '8.6'

#deploy-xformers-8.9:
#  extends: .deploy-xformers
#  variables: 
#    GRAPHIC_VERSION: '8.9'

deploy-xformers-6.1:
  extends: .deploy-xformers
  variables: 
    GRAPHIC_VERSION: '6.1'
