variables:
  REPO: "harbor.dvgd.rzd"
  PROD_NAME_API: "parr/parr-api"
  PROD_NAME_AIHIT_LOADER: "parr/parr-aihit-loader"
  PROD_NAME_AIHIT_SYNCER: "parr/parr-aihit-syncer"
  PROD_NAME_AIHIT_RELATIONSHIPS_SYNCER: "parr/parr-aihit-relationships-syncer"
  PROD_NAME_ESPP_TEMPLATE: "parr/parr-espp-template-sync"
  PROD_NAME_ESPP_SCHEDULE: "parr/parr-espp-schedule-sync"
  PROD_NAME_GENERATOR_TEMPLATES: "parr/parr-generator-templates"
  PROD_NAME_ESPP_ORDER_LOADER: "parr/parr-espp-order-loader"
  PROD_NAME_ESPP_ORDER_MANAGER: "parr/parr-espp-order-manager"
  PROD_NAME_MASTER: "parr/parr-master"
  PROD_NAME_NEXT_RUN: "parr/parr-next-run"
  PROD_TEMPLATE_DISTRIBOTOR: "parr/parr-template-distributor"
  PROD_TEMPLATE_ACTIVATOR: "parr/parr-template-activator"
  PROD_TEMPLATE_GENERATOR: "parr/parr-template-generator"
  PROD_TEMPLATE_TASK_GENERATOR: "parr/parr-template-task-generator"
  PROD_JOB_AUTO_CONTROL: "parr/parr-job-auto-control"
  PROD_TEMPLATE_MATCHER: "parr/parr-template-matcher"
  PROD_TEMPLATE_UPDATER: "parr/parr-template-updater"
  PROD_WORKLOAD_BUILDER: "parr/parr-workload-builder"
  PROD_TASK_RECONCILIATION: "parr/parr-task-reconciliation"


stages:
  - build
  - deploy


### API PROD ###
prod_build:
  stage: build
  only:
    - /^v[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
          "--insecure-registry=10.99.253.167:8090",
          "--registry-mirror=http://10.99.253.167:8090",
          "--insecure-registry=10.99.253.167:8088",
          "--registry-mirror=http://10.99.253.167:8088",
          "--insecure-registry=harbor.dvgd.rzd",
          "--tls=false"
      ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | tr -d v)
    - docker build -t $REPO/$PROD_NAME_API:$CI_COMMIT_TAG -t $REPO/$PROD_NAME_API:latest -t $PROD_NAME_API:$CI_COMMIT_TAG -t $PROD_NAME_API:latest --build-arg app_version=$IMAGE_VERSION -f PARR.API/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_API
  tags:
    - docker


prod_deploy:
  stage: deploy
  environment:
    name: prod
    url: http://10.99.253.216:8082/api/v1/version
  only:
    - /^v[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO
    #- tag=$CI_COMMIT_TAG docker compose up -d
    - tag=$CI_COMMIT_TAG docker stack deploy -c docker-compose.yml parr-api --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
      #- RUNNER: shell-1
  tags:
    - ${RUNNER}


### AIHIT LOADER PROD ###
prod_aihit_loader_build:
  stage: build
  only:
    - /^al[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=10.99.253.167:8088",
        "--registry-mirror=http://10.99.253.167:8088",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d al)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/al/v/g')
    - docker build -t $REPO/$PROD_NAME_AIHIT_LOADER:$IMAGE_VERSION -t $REPO/$PROD_NAME_AIHIT_LOADER:latest -t $PROD_NAME_AIHIT_LOADER:$IMAGE_VERSION -t $PROD_NAME_AIHIT_LOADER:latest --build-arg app_version=$APP_VERSION -f PARR.AIHITLoaderWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_AIHIT_LOADER
  tags:
    - docker


prod_aihit_loader_deploy:
  stage: deploy
  environment:
    name: parr-aihit-loader
  only:
    - /^al[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/al/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO
    - tag=$IMAGE_VERSION docker compose -f docker-compose.aihit-loader.yml up -d
  parallel:
    matrix:
      - RUNNER: shell-as-1
  tags:
    - ${RUNNER}



### AIHIT SYNCER PROD ###
prod_aihit_syncer_build:
  stage: build
  only:
    - /^as[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=10.99.253.167:8088",
        "--registry-mirror=http://10.99.253.167:8088",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d as)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/as/v/g')
    - docker build -t $REPO/$PROD_NAME_AIHIT_SYNCER:$IMAGE_VERSION -t $REPO/$PROD_NAME_AIHIT_SYNCER:latest -t $PROD_NAME_AIHIT_SYNCER:$IMAGE_VERSION -t $PROD_NAME_AIHIT_SYNCER:latest --build-arg app_version=$APP_VERSION -f PARR.AIHITSyncerWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_AIHIT_SYNCER
  tags:
    - docker


prod_aihit_syncer_deploy:
  stage: deploy
  environment:
    name: parr-aihit-syncer
  only:
    - /^as[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/as/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.aihit-syncer.yml parr-aihit-syncer --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}

### AIHIT RELATIONSHPS SYNCER PROD ###
prod_aihit_relationships_syncer_build:
  stage: build
  only:
    - /^ars[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://c:8090",
        "--insecure-registry=10.99.253.167:8088",
        "--registry-mirror=http://10.99.253.167:8088",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d ars)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ars/v/g')
    - docker build -t $REPO/$PROD_NAME_AIHIT_RELATIONSHIPS_SYNCER:$IMAGE_VERSION -t $REPO/$PROD_NAME_AIHIT_RELATIONSHIPS_SYNCER:latest -t $PROD_NAME_AIHIT_RELATIONSHIPS_SYNCER:$IMAGE_VERSION -t $PROD_NAME_AIHIT_RELATIONSHIPS_SYNCER:latest --build-arg app_version=$APP_VERSION -f PARR.AIHITRelationshipsSyncerWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_AIHIT_RELATIONSHIPS_SYNCER
  tags:
    - docker


prod_aihit_relationships_syncer_deploy:
  stage: deploy
  environment:
    name: parr-aihit-relationships-syncer
  only:
    - /^ars[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ars/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO
    - tag=$IMAGE_VERSION docker compose -f docker-compose.aihit-relationships-syncer.yml up -d
  parallel:
    matrix:
      - RUNNER: shell-as-1
  tags:
    - ${RUNNER}


### ESPP TEMPLATE PROD ###
prod_espp-template_build:
  stage: build
  only:
    - /^et[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=10.99.253.167:8088",
        "--registry-mirror=http://10.99.253.167:8088",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d et)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/et/v/g')
    - docker build -t $REPO/$PROD_NAME_ESPP_TEMPLATE:$IMAGE_VERSION -t $REPO/$PROD_NAME_ESPP_TEMPLATE:latest -t $PROD_NAME_ESPP_TEMPLATE:$IMAGE_VERSION -t $PROD_NAME_ESPP_TEMPLATE:latest --build-arg app_version=$APP_VERSION -f PARR.EsppTemplateSyncWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_ESPP_TEMPLATE
  tags:
    - docker-et


prod_espp-template_deploy:
  stage: deploy
  environment:
    name: parr-espp-template-sync
  only:
    - /^et[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/et/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    #- tag=$IMAGE_VERSION docker compose -f docker-compose.espp-template-sync.yml up -d
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.espp-template-sync.yml parr-espp --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
      #- RUNNER: shell-et-1
  tags:
    - ${RUNNER}


### GENERATOR TEMPLATES PROD ###
prod_generator_templates_build:
  stage: build
  only:
    - /^gt[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d gt)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/gt/v/g')
    - docker build -t $REPO/$PROD_NAME_GENERATOR_TEMPLATES:$IMAGE_VERSION -t $REPO/$PROD_NAME_GENERATOR_TEMPLATES:latest -t $PROD_NAME_GENERATOR_TEMPLATES:$IMAGE_VERSION -t $PROD_NAME_GENERATOR_TEMPLATES:latest --build-arg app_version=$APP_VERSION -f PARR.GeneratorTemplatesWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_GENERATOR_TEMPLATES
  tags:
    - docker


prod_generator_templates_deploy:
  stage: deploy
  environment:
    name: parr-generator-templates-sync
  only:
    - /^gt[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/gt/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.generator-templates.yml parr-generator-templates --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### ESPP ORDER LOADER PROD ###
prod_espp_order_loader_build:
  stage: build
  only:
    - /^ol[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d ol)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ol/v/g')
    - docker build -t $REPO/$PROD_NAME_ESPP_ORDER_LOADER:$IMAGE_VERSION -t $REPO/$PROD_NAME_ESPP_ORDER_LOADER:latest -t $PROD_NAME_ESPP_ORDER_LOADER:$IMAGE_VERSION -t $PROD_NAME_ESPP_ORDER_LOADER:latest --build-arg app_version=$APP_VERSION -f PARR.EsppOrderLoaderWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_ESPP_ORDER_LOADER
  tags:
    - docker


prod_espp_order_loader_deploy:
  stage: deploy
  environment:
    name: parr-espp-order-loader
  only:
    - /^ol[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ol/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.espp-order-loader.yml parr-espp-order-loader --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}
 

### ESPP ORDER MANAGER PROD ###
prod_espp_order_manager_build:
  stage: build
  only:
    - /^om[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d om)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/om/v/g')
    - docker build -t $REPO/$PROD_NAME_ESPP_ORDER_MANAGER:$IMAGE_VERSION -t $REPO/$PROD_NAME_ESPP_ORDER_MANAGER:latest -t $PROD_NAME_ESPP_ORDER_MANAGER:$IMAGE_VERSION -t $PROD_NAME_ESPP_ORDER_MANAGER:latest --build-arg app_version=$APP_VERSION -f PARR.EsppOrderManagerWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_ESPP_ORDER_MANAGER
  tags:
    - docker


prod_espp_order_manager_deploy:
  stage: deploy
  environment:
    name: parr-espp-order-manager
  only:
    - /^om[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/om/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.espp-order-manager.yml parr-espp-order-manager --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### MASTER PROD ###
prod_master_build:
  stage: build
  only:
    - /^m[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d m)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/m/v/g')
    - docker build -t $REPO/$PROD_NAME_MASTER:$IMAGE_VERSION -t $REPO/$PROD_NAME_MASTER:latest -t $PROD_NAME_MASTER:$IMAGE_VERSION -t $PROD_NAME_MASTER:latest --build-arg app_version=$APP_VERSION -f PARR.MasterWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_MASTER
  tags:
    - docker


prod_master_deploy:
  stage: deploy
  environment:
    name: parr-master
  only:
    - /^m[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/m/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.master.yml parr-master --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### ESPP SCHEDULE SYNC PROD ###
prod_espp_schedule_build:
  stage: build
  only:
    - /^es[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d es)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/es/v/g')
    - docker build -t $REPO/$PROD_NAME_ESPP_SCHEDULE:$IMAGE_VERSION -t $REPO/$PROD_NAME_ESPP_SCHEDULE:latest -t $PROD_NAME_ESPP_SCHEDULE:$IMAGE_VERSION -t $PROD_NAME_ESPP_SCHEDULE:latest --build-arg app_version=$APP_VERSION -f PARR.EsppScheduleSyncWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_ESPP_SCHEDULE
  tags:
    - docker


prod_espp_schedule_deploy:
  stage: deploy
  environment:
    name: parr-espp-schedule-sync
  only:
    - /^es[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/es/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.espp-schedule-sync.yml parr-espp-schedule-sync --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}



### NEXT RUN PROD ###
prod_next_run_build:
  stage: build
  only:
    - /^nr[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d nr)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/nr/v/g')
    - docker build -t $REPO/$PROD_NAME_NEXT_RUN:$IMAGE_VERSION -t $REPO/$PROD_NAME_NEXT_RUN:latest -t $PROD_NAME_NEXT_RUN:$IMAGE_VERSION -t $PROD_NAME_NEXT_RUN:latest --build-arg app_version=$APP_VERSION -f PARR.NextRunWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_NAME_NEXT_RUN
  tags:
    - docker


prod_next_run_deploy:
  stage: deploy
  environment:
    name: parr-next-run
  only:
    - /^nr[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/nr/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.next-run.yml parr-next-run --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}



### TEMPLATE DISTRIBUTOR PROD ###
prod_template_distributor_build:
  stage: build
  only:
    - /^td[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d td)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/td/v/g')
    - docker build -t $REPO/$PROD_TEMPLATE_DISTRIBOTOR:$IMAGE_VERSION -t $REPO/$PROD_TEMPLATE_DISTRIBOTOR:latest -t $PROD_TEMPLATE_DISTRIBOTOR:$IMAGE_VERSION -t $PROD_TEMPLATE_DISTRIBOTOR:latest --build-arg app_version=$APP_VERSION -f PARR.TemplateDistributorWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TEMPLATE_DISTRIBOTOR
  tags:
    - docker


prod_template_distributor_deploy:
  stage: deploy
  environment:
    name: parr-template-distributor
  only:
    - /^td[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/td/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.template-distributor.yml parr-template-distributor --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### TEMPLATE ACTIVATOR PROD ###
prod_template_activator_build:
  stage: build
  only:
    - /^ta[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d ta)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ta/v/g')
    - docker build -t $REPO/$PROD_TEMPLATE_ACTIVATOR:$IMAGE_VERSION -t $REPO/$PROD_TEMPLATE_ACTIVATOR:latest -t $PROD_TEMPLATE_ACTIVATOR:$IMAGE_VERSION -t $PROD_TEMPLATE_ACTIVATOR:latest --build-arg app_version=$APP_VERSION -f PARR.TemplateActivatorWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TEMPLATE_ACTIVATOR
  tags:
    - docker


prod_template_activator_deploy:
  stage: deploy
  environment:
    name: parr-template-activator
  only:
    - /^ta[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ta/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.template-activator.yml parr-template-activator --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### TEMPLATE GENERATOR PROD ###
prod_template_generator_build:
  stage: build
  only:
    - /^tg[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d tg)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tg/v/g')
    - docker build -t $REPO/$PROD_TEMPLATE_GENERATOR:$IMAGE_VERSION -t $REPO/$PROD_TEMPLATE_GENERATOR:latest -t $PROD_TEMPLATE_GENERATOR:$IMAGE_VERSION -t $PROD_TEMPLATE_GENERATOR:latest --build-arg app_version=$APP_VERSION -f PARR.TemplateGeneratorWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TEMPLATE_GENERATOR
  tags:
    - docker

prod_template_generator_deploy:
  stage: deploy
  environment:
    name: parr-template-generator
  only:
    - /^tg[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tg/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.template-generator.yml parr-template-generator --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### TEMPLATE TASK GENERATOR PROD ###
prod_template_task_generator_build:
  stage: build
  only:
    - /^ttg[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d ttg)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ttg/v/g')
    - docker build -t $REPO/$PROD_TEMPLATE_TASK_GENERATOR:$IMAGE_VERSION -t $REPO/$PROD_TEMPLATE_TASK_GENERATOR:latest -t $PROD_TEMPLATE_TASK_GENERATOR:$IMAGE_VERSION -t $PROD_TEMPLATE_TASK_GENERATOR:latest --build-arg app_version=$APP_VERSION -f PARR.TemplateTaskGeneratorWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TEMPLATE_TASK_GENERATOR
  tags:
    - docker

prod_template_task_generator_deploy:
  stage: deploy
  environment:
    name: parr-template-task-generator
  only:
    - /^ttg[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/ttg/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.template-task-generator.yml parr-template-task-generator --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### JOB AUTO CONTROL PROD ###
prod_job_auto_control_build:
  stage: build
  only:
    - /^jac[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d jac)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/jac/v/g')
    - docker build -t $REPO/$PROD_JOB_AUTO_CONTROL:$IMAGE_VERSION -t $REPO/$PROD_JOB_AUTO_CONTROL:latest -t $PROD_JOB_AUTO_CONTROL:$IMAGE_VERSION -t $PROD_JOB_AUTO_CONTROL:latest --build-arg app_version=$APP_VERSION -f PARR.JobAutoControlWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_JOB_AUTO_CONTROL
  tags:
    - docker


prod_job_auto_control_deploy:
  stage: deploy
  environment:
    name: parr-job-auto-control
  only:
    - /^jac[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/jac/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.job-auto-control.yml parr-job-auto-control --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}



### TEMPLATE MATCHER PROD ###
prod_template_matcher_build:
  stage: build
  only:
    - /^tm[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d tm)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tm/v/g')
    - docker build -t $REPO/$PROD_TEMPLATE_MATCHER:$IMAGE_VERSION -t $REPO/$PROD_TEMPLATE_MATCHER:latest -t $PROD_TEMPLATE_MATCHER:$IMAGE_VERSION -t $PROD_TEMPLATE_MATCHER:latest --build-arg app_version=$APP_VERSION -f PARR.TemplateMatcherWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TEMPLATE_MATCHER
  tags:
    - docker


prod_template_matcher_deploy:
  stage: deploy
  environment:
    name: parr-template-matcher
  only:
    - /^tm[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tm/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.template-matcher.yml parr-template-matcher --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}



### TEMPLATE UPDATER PROD ###
prod_template_updater_build:
  stage: build
  only:
    - /^tu[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d tu)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tu/v/g')
    - docker build -t $REPO/$PROD_TEMPLATE_UPDATER:$IMAGE_VERSION -t $REPO/$PROD_TEMPLATE_UPDATER:latest -t $PROD_TEMPLATE_UPDATER:$IMAGE_VERSION -t $PROD_TEMPLATE_UPDATER:latest --build-arg app_version=$APP_VERSION -f PARR.TemplateUpdaterWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TEMPLATE_UPDATER
  tags:
    - docker


prod_template_updater_deploy:
  stage: deploy
  environment:
    name: parr-template-updater
  only:
    - /^tu[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tu/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.template-updater.yml parr-template-updater --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}



### WORKLOAD BUILDER PROD ###
prod_workload_builder_build:
  stage: build
  only:
    - /^wb[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d wb)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/wb/v/g')
    - docker build -t $REPO/$PROD_WORKLOAD_BUILDER:$IMAGE_VERSION -t $REPO/$PROD_WORKLOAD_BUILDER:latest -t $PROD_WORKLOAD_BUILDER:$IMAGE_VERSION -t $PROD_WORKLOAD_BUILDER:latest --build-arg app_version=$APP_VERSION -f PARR.WorkloadBuilderWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_WORKLOAD_BUILDER
  tags:
    - docker


prod_workload_builder_deploy:
  stage: deploy
  environment:
    name: parr-workload-builder
  only:
    - /^wb[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/wb/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.workload-builder.yml parr-workload-builder --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}


### TASK RECONCILIATION PROD ###
prod_task_reconciliation_build:
  stage: build
  only:
    - /^tr[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  services:
    - name: docker:20.10.21-dind
      command: [
        "--insecure-registry=10.99.253.167:8090",
        "--registry-mirror=http://10.99.253.167:8090",
        "--insecure-registry=harbor.dvgd.rzd",
        "--tls=false"
        ]
  variables:
    DOCKER_HOST: tcp://docker:2375
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  script:
    - APP_VERSION=$(echo $CI_COMMIT_TAG | tr -d tr)
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tr/v/g')
    - docker build -t $REPO/$PROD_TASK_RECONCILIATION:$IMAGE_VERSION -t $REPO/$PROD_TASK_RECONCILIATION:latest -t $PROD_TASK_RECONCILIATION:$IMAGE_VERSION -t $PROD_TASK_RECONCILIATION:latest --build-arg app_version=$APP_VERSION -f PARR.TaskReconciliationWorker/Dockerfile .
    - docker login -u $HARBOR_PUSH_USER -p $HARBOR_PUSH_PASS $REPO
    - docker push --all-tags $REPO/$PROD_TASK_RECONCILIATION
  tags:
    - docker


prod_task_reconciliation_deploy:
  stage: deploy
  environment:
    name: parr-task-reconciliation
  only:
    - /^tr[0-9]+\.[0-9]+\.[0-9]+$/
  except:
    - branches
  script:
    - IMAGE_VERSION=$(echo $CI_COMMIT_TAG | sed 's/tr/v/g')
    - docker login -u $HARBOR_PULL_USER -p $HARBOR_PULL_PASS $REPO 
    - tag=$IMAGE_VERSION docker stack deploy -c docker-compose.task-reconciliation.yml parr-task-reconciliation  --with-registry-auth
  parallel:
    matrix:
      - RUNNER: shell-api-swarm-01
  tags:
    - ${RUNNER}