stages:
    - build
    - deploy_nightly
    - test
    - deploy
    - publish


before_script:
  - export GNOW=$(date +"%Y%m%d")
  - export NOW=$(date +"%Y%m%d-%H%M%S")
  - export TAR_NAME_POSTFIX=$NOW
  - export NIGHTLY_NAME=chaos_distrib-$CI_JOB_NAME-$GNOW.tar.gz
  - export MERGE_COMMENT="non-regression-$NOW-$CI_COMMIT_REF_NAME-${CI_PIPELINE_ID}"
  - export SYS=`uname -s`
  - if [ "$SYS" == "Linux" ];then export NPROC=`nproc`;else export NPROC=4;fi
  - if [ -z "$TEST_BRANCH" ]; then export TEST_BRANCH=$CI_COMMIT_REF_NAME;fi
  - if [ "$SKIP_TEST" == "true" ];then REVNAME="UNTESTED"; else REVNAME=$(basename $TEST_BRANCH); fi
  - echo "[$CI_RUNNER_DESCRIPTION] $SYS $CI_JOB_NAME Working directory:$PWD tag $CI_COMMIT_REF_NAME CPUS:$NPROC framework in branch $TEST_BRANCH"
  - export ARCH=`uname -m`
  - eval export `cat /etc/*-release|grep -e "^VERSION_ID="|tr -d "\" "`
  - eval export `cat /etc/*-release|grep -e "^ID="|tr -d "\" "`
  - export REV_POSTFIX=$REVNAME-$ID-$VERSION_ID-$ARCH
  - export DISTRIB_NAME=chaos-distrib-$REV_POSTFIX
  - export DISTRIB_PREFIX=/usr/local/chaos/chaos-distrib
  - export INSTALL_DIR=$DISTRIB_PREFIX
  - export CHAOS_MDS=localhost:5000
  - export CHAOS_INTERFACE=lo
  - export CHAOS_LIVE_SERVERS=couchbase
  - export CHAOS_LOG_SERVERS=influxdb:8086  
  - export CHAOS_DB_SERVERS=mongo
  - export PATH=/usr/local/chaos/qt-56/bin:$PATH
  - echo "Running on $ID $VERSION_ID $ARCH (distrib name '$DISTRIB_NAME') $REVNAME"
  - git config --global user.email andrea.michelotti@lnf.infn.it
  - git config --global user.name amichelo
  - git config --global color.ui true
  - rm -rf chaosframework
  - mkdir -p $INSTALL_DIR
  
# macosx_x86_64:
#    tags:
#      - macosx
#    stage: build
#    services:
#    - name: couchbase/server:community-5.0.1
#      alias: couchbase
#    - name: mongo:3.6
#      alias: mongo

#    script:
#      - export CHAOS_LIVE_SERVERS=localhost
#      - export CHAOS_DB_SERVERS=localhost
#      - curl http://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
#      - chmod +x ~/bin/repo
#      -  ~/bin/repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#      - mkdir chaos-osx10-distrib
#      - ~/bin/repo sync
#      - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi
#      - ./tools/dbinit.sh localhost localhost;sleep 5;./tools/dbinit.sh localhost localhost;sleep 5
#      - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
#      - cd html/chaos_dashboard/;./tag.sh $CI_COMMIT_REF_NAME;cd -
#      - cmake -DCHAOS_ARCHITECTURE_TEST=ON -DCHAOS_VME=OFF -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DCHAOS_WAN=ON . -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCMAKE_INSTALL_PREFIX=$PWD/chaos-osx10-distrib
#      - make -j 8 install
#      - export CHAOS_LIVE_SERVERS=localhost;export CHAOS_DB_SERVERS=localhost
#      - cd $PWD/chaos-osx10-distrib
#      - source chaos_env.sh
#      - ./tools/dbinit.sh localhost localhost;sleep 5;./tools/dbinit.sh localhost localhost
#      - ./tools/chaos_test.sh -k .
#      - ./tools/chaos_services.sh stop
#      - tar cfz chaos-osx10-distrib.tar.gz chaos-osx10-distrib
     
     
#    allow_failure: true
#    artifacts:
#          name: "chaos-osx10-distrib.tar.gz"
#          paths:
#             - ./*.tar.gz
#          expire_in: 1 day
#          when: always
#    only:
#      variables:
#        - $BUILD_DISTRIBUTION == "macosx_x86_64"
#        - $BUILD_DISTRIBUTION == null

build_i686_static_linux26:
  stage: build
  retry: 2
  tags:  
    - shared
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:cross
  script:
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - repo sync
    - mv CACHE chaosframework/config
    - export DISTRIB_NAME=chaos-distrib-$REVNAME-$CI_JOB_NAME
    - export PATH=/usr/local/chaos/i686-nptl-linux-gnu/bin/:$PATH
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cmake -DKAFKA_RDK_ENABLE=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="CI_JOB_STAGE.$CI_COMMIT_SHA" . -DCHAOS_STATIC=ON -DCHAOS_BUILD_ID=${CI_PIPELINE_ID}  -DCHAOS_TARGET=i686-linux26 -DCHAOS_CDS=OFF -DCHAOS_MDS=OFF -DCHAOS_AGENT=OFF  -DCHAOS_WAN=OFF -DCHAOS_EXAMPLES=OFF -DCHAOS_ENABLE_C11=OFF -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR |& tee $INSTALL_DIR/bundle.configuration.log
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - if [ $CI_COMMIT_REF_NAME == "master" ];then i686-nptl-linux-gnu-strip `find $INSTALL_DIR/bin/ -type f`;fi
    - i686-nptl-linux-gnu-strip `find $INSTALL_DIR/lib/ -name "*.a" -type f`
    - tar cfz $DISTRIB_NAME.tar.gz -C $INSTALL_DIR/..  chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/i686/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/i686/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "i686_static_linux26"
      - $BUILD_DISTRIBUTION == null

build_i686_dynamic_linux26:
  stage: build
  tags:  
    - shared
  retry: 2
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:cross
  script:
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - export DISTRIB_NAME=chaos-distrib-$REVNAME-$CI_JOB_NAME
    - repo sync
    - mv CACHE chaosframework/config    
    - export PATH=/usr/local/chaos/i686-nptl-linux-gnu/bin/:$PATH
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi    
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cmake . -DKAFKA_RDK_ENABLE=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="CI_JOB_STAGE.$CI_COMMIT_SHA" -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 -DCHAOS_TARGET=i686-linux26 -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCHAOS_CDS=OFF -DCHAOS_MDS=OFF -DCHAOS_AGENT=OFF -DCHAOS_WAN=OFF -DCHAOS_EXAMPLES=OFF -DCHAOS_ENABLE_C11=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR |& tee $INSTALL_DIR/bundle.configuration.log
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - cp /usr/local/chaos/i686-nptl-linux-gnu/i686-nptl-linux-gnu/sysroot/lib/libstdc++.so.6 $INSTALL_DIR/lib
    - tar cfz $DISTRIB_NAME.tar.gz -C $INSTALL_DIR/..  /usr/local/chaos chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/i686/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/i686/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/i686/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "i686_dynamic_linux26"
      - $BUILD_DISTRIBUTION == null

build_armhf_dynamic:
  stage: build
  tags:  
    - shared
  retry: 2
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:cross
  script:
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - export DISTRIB_NAME=chaos-distrib-$REVNAME-$CI_JOB_NAME
    - repo sync
    - mv CACHE chaosframework/config    
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cmake . -DKAFKA_RDK_ENABLE=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="CI_JOB_STAGE.$CI_COMMIT_SHA" -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 -DCHAOS_TARGET=armhf -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCHAOS_CDS=OFF -DCHAOS_MDS=OFF -DCHAOS_AGENT=OFF -DCHAOS_WAN=OFF -DCHAOS_EXAMPLES=OFF -DCHAOS_ENABLE_C11=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR |& tee $INSTALL_DIR/bundle.configuration.log
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - tar cfz $DISTRIB_NAME.tar.gz -C $INSTALL_DIR/..  /usr/local/chaos chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/arm/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/arm/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "armhf_dynamic"
      - $BUILD_DISTRIBUTION == null

build_armhf_static:
  stage: build
  tags:  
    - shared
  retry: 2
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:cross
  script:
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - export DISTRIB_NAME=chaos-distrib-$REVNAME-$CI_JOB_NAME
    - repo sync
    - mv CACHE chaosframework/config    
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi    
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cmake . -DKAFKA_RDK_ENABLE=ON -DCHAOS_STATIC=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="CI_JOB_STAGE.$CI_COMMIT_SHA" -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 -DCHAOS_TARGET=armhf -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCHAOS_CDS=OFF -DCHAOS_MDS=OFF -DCHAOS_AGENT=OFF -DCHAOS_WAN=OFF -DCHAOS_EXAMPLES=OFF -DCHAOS_ENABLE_C11=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR |& tee $INSTALL_DIR/bundle.configuration.log
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - tar cfz $DISTRIB_NAME.tar.gz -C $INSTALL_DIR/..  /usr/local/chaos chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/arm/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/arm/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "armhf_dynamic"
      - $BUILD_DISTRIBUTION == null

# ubuntu1604_x86_64:
#   stage: build
#   retry: 2
#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1604
#   script:
#     - repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#     - repo sync
#     - ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH    
#     - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
#     - cd html/chaos_dashboard/;./tag.sh $CI_COMMIT_REF_NAME;cd -    
#     - if ! cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCHAOS_ARCHITECTURE_TEST=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DCHAOS_WAN=ON -DOPENCV=$INSTALL_DIR -DCAEN2527=ON -DIDS=ON -DBASLER=ON -DENABLE_MEMCACHE=ON -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCERN_ROOT=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR . |& tee $DISTRIB_PREFIX/bundle.configuration.log;then cat /tmp/cmake.log;fi
#     - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz $INSTALL_DIR/bundle.compilation.log;exit 1;fi
#     - git clone git@baltig.infn.it:chaos-lnf-control/luminometer.git
#     - cd luminometer ;git checkout $CI_COMMIT_REF_NAME
#     - cd chaos/src;cmake -DCMAKE_MODULE_PATH=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .
#     - make -j 4 install
#     - cd ../../../
#     - scripts/strip_symbols.sh $INSTALL_DIR
#     - tar cfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos chaos-distrib
#   artifacts:
#     name: "$DISTRIB_NAME.tar.gz"
#     paths:
#       - ./*.tar.gz
#     expire_in: 2 day
#     when: always
#   only:
#     variables:
#       - $BUILD_DISTRIBUTION == "ubuntu1604_x86_64"
#       - $BUILD_DISTRIBUTION == null

ubuntu1804_x86_64:
  stage: build
  tags:  
    - shared
  retry: 2
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1804
  script:
    - npm install -g jchaos
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - repo sync
    - mv CACHE chaosframework/config   
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi    
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cd html/chaos_dashboard/;./tag.sh $CI_COMMIT_REF_NAME;cd -    
    - if ! cmake -DKAFKA_RDK_ENABLE=ON -DCHAOS_ARCHITECTURE_TEST=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DCHAOS_WAN=ON -DOPENCV=$INSTALL_DIR -DIDS=ON -DBASLER=ON -DCAEN2527=ON -DENABLE_MEMCACHE=ON -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCERN_ROOT=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR . |& tee $DISTRIB_PREFIX/bundle.configuration.log;then cat /tmp/cmake.log;fi
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - git clone git@baltig.infn.it:chaos-lnf-control/luminometer.git
    - cd luminometer ;git checkout $CI_COMMIT_REF_NAME
    - cd chaos/src;cmake -DKAFKA_RDK_ENABLE=ON -DCMAKE_MODULE_PATH=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .
    - make -j 4 install
    - cd ../../../
    - scripts/strip_symbols.sh $INSTALL_DIR
    - tar cfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/latest.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/latest.tar.gz.md5"


  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "ubuntu1804_x86_64"
      - $BUILD_DISTRIBUTION == null

ubuntu1804_profile_x86_64:
  stage: build
  tags:  
    - shared
  retry: 2
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1804
  script:
    - npm install -g jchaos
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME  
    - repo sync
    - mv CACHE chaosframework/config    
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cd html/chaos_dashboard/;./tag.sh $CI_COMMIT_REF_NAME;cd -    
    - if ! cmake -DKAFKA_RDK_ENABLE=ON -DCHAOS_ARCHITECTURE_TEST=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DCHAOS_WAN=ON -DOPENCV=$INSTALL_DIR -DIDS=ON -DCAEN2527=ON -DBASLER=ON -DENABLE_MEMCACHE=ON -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCERN_ROOT=$INSTALL_DIR -DCMAKE_BUILD_TYPE=PROFILE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR . |& tee $DISTRIB_PREFIX/bundle.configuration.log;then cat /tmp/cmake.log;fi
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - git clone git@baltig.infn.it:chaos-lnf-control/luminometer.git
    - cd luminometer ;git checkout $CI_COMMIT_REF_NAME
    - cd chaos/src;cmake -DKAFKA_RDK_ENABLE=ON -DCMAKE_BUILD_TYPE=PROFILE -DCMAKE_MODULE_PATH=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .
    - make -j 4 install
    - cd ../../../
    - echo "--->$PWD"
    - ls -latr $HOME
    - ls -latr
    - tar cfz $DISTRIB_NAME.tar.gz -C / /usr/local/chaos/chaos-distrib $PWD/build-x86_64-Linux/
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "ubuntu1804_profile_x86_64"
      - $BUILD_DISTRIBUTION == null

centos7_x86_64:
  variables:
    ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9092,INTERNAL://localhost:9093'
    LISTENERS: 'PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093'
    SECURITY_PROTOCOL_MAP: 'PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT'
    LOG_RETENTION_BYTES: 10737418240
    AUTO_CREATE_TOPICS_ENABLE: 'true'
    INTER_BROKER: 'INTERNAL'

  services:
  - name: couchbase/server:community-5.0.1
    alias: couchbase
  - name: mongo:3.6
    alias: mongo
  - name: michelo/kafka:2.6
    alias: kafka    
  - name: influxdb
    alias: influxdb

  stage: build
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:centos7
  
  script:
    - npm install -g jchaos  
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - repo sync
    - mv CACHE chaosframework/config    
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cd html/chaos_dashboard/;./tag.sh $CI_COMMIT_REF_NAME;cd -
    - export CC=/opt/rh/devtoolset-8/root/usr/bin/gcc;export CXX=/opt/rh/devtoolset-8/root/usr/bin/g++ 
    - if ! cmake -DKAFKA_RDK_ENABLE=ON -DCHAOS_PROMETHEUS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=1  -DCHAOS_ARCHITECTURE_TEST=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DCHAOS_WAN=ON -DOPENCV=$INSTALL_DIR -DIDS=ON -DBASLER=ON -DCAEN2527=ON -DENABLE_MEMCACHE=ON  -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCERN_ROOT=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR . |& tee $DISTRIB_PREFIX/bundle.configuration.log;then cat /tmp/cmake.log;fi
    - make  -j 4 install
    - git clone git@baltig.infn.it:chaos-lnf-control/luminometer.git
    - cd luminometer ;git checkout $CI_COMMIT_REF_NAME
    - cd chaos/src;cmake -DKAFKA_RDK_ENABLE=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 -DCHAOS_PROMETHEUS=ON -DCMAKE_MODULE_PATH=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - cd ../../../
    - git clone git@baltig.infn.it:chaos-lnf-control/chaos-common-labview.git
    - cd chaos-common-labview;git checkout $CI_COMMIT_REF_NAME;cd api/linux/;cmake  -DCMAKE_MODULE_PATH=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DLVVER=19 .
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - cd ../../../
    - scripts/strip_symbols.sh $INSTALL_DIR
    - tar cfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/$ARCH/$ID/$VERSION_ID/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "centos7_x86_64"
      - $BUILD_DISTRIBUTION == null
# ubuntu1604_legacy_x86_64:
#   stage: build
#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1604
#   script:
#     - mkdir -p $INSTALL_DIR
#     - repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#     - repo sync
#     - cmake -DKAFKA_RDK_ENABLE=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DCHAOS_BOOST_VERSION=56 -DCHAOS_CC_COMPILER=g++-4.8 -DCHAOS_C_COMPILER=gcc-4.8 -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .
#     - make  -j 4 install |& tee $DISTRIB_PREFIX/bundle.compilation.log
# #    - source $INSTALL_DIR/chaos_env.sh
# #    - cd chaosframework/ccs;qmake;echo "* compiling CCS";make -j 4 >& $DISTRIB_PREFIX/log/ccs.compilation.log ;cp ccs $INSTALL_DIR/bin;
# #    - cd ../../
#     - scripts/strip_symbols.sh $INSTALL_DIR

#     - tar cfz $DISTRIB_NAME.legacy.tar.gz -C /usr/local/chaos chaos-distrib
#   artifacts:
#         name: "$DISTRIB_NAME.legacy.tar.gz"
#         paths:
#           - ./*.tar.gz
#         expire_in: 1 day

# ubuntu1404_x86_64:
#   stage: build
#   retry: 2
#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1404

#   script:
#     - repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#     - repo sync
#     - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi    
#     - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
#     - cd html/chaos_dashboard/;./tag.sh $CI_COMMIT_REF_NAME;cd -    
#     - if ! cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCHAOS_ARCHITECTURE_TEST=ON -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH ($CHAOS_LAST_TAG)" -DCHAOS_VERSION_MINOR="$CI_JOB_STAGE.$CI_COMMIT_SHA" -DOPENCV=$INSTALL_DIR -DIDS=ON -DCAEN2527=ON -DBASLER=ON  -DCHAOS_WAN=ON -DENABLE_MEMCACHE=ON -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCHAOS_CCS=ON -DCERN_ROOT=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR . ;then cat /tmp/cmake.log;fi
#     - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz $INSTALL_DIR/bundle.compilation.log;exit 1;fi
# #    - source $INSTALL_DIR/chaos_env.sh
# #    - cd chaosframework/ccs;qmake;echo "* compiling CCS";
# #    - if make -j 4 >& $DISTRIB_PREFIX/log/ccs.compilation.log;then cp ccs $INSTALL_DIR/bin;else cat $DISTRIB_PREFIX/log/ccs.compilation.log;fi
# #   - cd ../../
#     - git clone git@baltig.infn.it:chaos-lnf-control/luminometer.git
#     - cd luminometer ;git checkout $CI_COMMIT_REF_NAME
#     - cd chaos/src;cmake -DCMAKE_MODULE_PATH=$INSTALL_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .
#     - make -j 4 install
#     - cd ../../../
#     - scripts/strip_symbols.sh $INSTALL_DIR
#     - tar cfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos chaos-distrib
#   artifacts:
#     name: "$DISTRIB_NAME.tar.gz"
#     paths:
#       - ./*.tar.gz
#     expire_in: 1 day
#     when: always
#   only:
#     variables:
#       - $BUILD_DISTRIBUTION == "ubuntu1404_x86_64"
#       - $BUILD_DISTRIBUTION == null

build_arm_linux26:
  stage: build
  tags:  
    - shared
  retry: 2
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:cross

  script:
    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
    - export DISTRIB_NAME=chaos-distrib-$REVNAME-$CI_JOB_NAME
    - repo sync
    - mv CACHE chaosframework/config    
    - if [ "$TEST_BRANCH" != "$CI_COMMIT_REF_NAME" ]; then ./chaosframework/tools/chaos_git.sh -c $TEST_BRANCH;fi    
    - export PATH=/usr/local/chaos/gcc-arm-infn-linux26/bin/:$PATH
    - cd chaosframework;export CHAOS_LIB_HASH=`git log -n 1 --pretty="%h"`;export CHAOS_LAST_TAG=`git describe --abbrev=0`;cd -;
    - cmake -DKAFKA_RDK_ENABLE=ON -DCHAOS_VME=OFF -DCHAOS_VERSION_MAJOR="$CI_COMMIT_REF_NAME.$CHAOS_LIB_HASH.$REVNAME ($CHAOS_LAST_TAG)" -DCMAKE_BUILD_WITH_INSTALL_RPATH=1 -DCHAOS_VERSION_MINOR="CI_JOB_STAGE.$CI_COMMIT_SHA" . -DCHAOS_STATIC=ON -DCHAOS_BUILD_ID=${CI_PIPELINE_ID} -DCHAOS_TARGET=arm-linux-2.6 -DCHAOS_CDS=OFF -DCHAOS_AGENT=OFF -DCHAOS_MDS=OFF -DCHAOS_WAN=OFF -DCHAOS_EXAMPLES=OFF -DCHAOS_ENABLE_C11=OFF -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR
    - if ! make  -j 4 install |& tee $INSTALL_DIR/bundle.compilation.log;then tar cfz compilation.tar.gz `find . -name "*.log"` $INSTALL_DIR/bundle.compilation.log;exit 1;fi
    - arm-infn-linux-gnueabi-strip `find $INSTALL_DIR/bin/ -type f`
    - arm-infn-linux-gnueabi-strip `find $INSTALL_DIR/lib/ -name "*.a" -type f`
    - tar cfz $DISTRIB_NAME.tar.gz -C $INSTALL_DIR/..  chaos-distrib
    - md5sum $DISTRIB_NAME.tar.gz > $DISTRIB_NAME.tar.gz.md5
#     - scp $DISTRIB_NAME.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME.md5
#     - scp $DISTRIB_NAME.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/arm/latest-$CI_JOB_NAME.tar.gz"
#     - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/arm/$NIGHTLY_NAME.md5 /var/www/html/binary/chaos/nightly/arm/latest-$CI_JOB_NAME.tar.gz.md5"

  artifacts:
    name: "$DISTRIB_NAME.tar.gz"
    paths:
      - ./*.tar.gz
    expire_in: 2 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "build_arm_linux26"
      - $BUILD_DISTRIBUTION == null


# test_arm_linux26:
#   stage: test
#   dependencies:
#     - build_arm_linux26
#   tags:
#     - lnf
#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:lite
#   script:
#     - scp chaos-distrib-$CI_COMMIT_REF_NAME-build_arm_linux26.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$CI_COMMIT_REF_NAME/arm/stage_chaos-distrib-$CI_COMMIT_REF_NAME-build_arm_linux26.tar.gz
#     - tar xvfz chaos-distrib-$CI_COMMIT_REF_NAME-build_arm_linux26.tar.gz chaos-distrib-$CI_COMMIT_REF_NAME-build_arm_linux26/bin/daqLiberaServer
#     - scp chaos-distrib-$CI_COMMIT_REF_NAME-build_arm_linux26/bin/daqLiberaServer michelo@192.168.143.252:/export/chaos-libera/old/daqLiberaServer-test
#     - ssh root@libera01 "/mnt/chaos/old/daqLiberaServer-test --help"

# test_i686_static_linux26:
#   dependencies:
#     - build_i686_static_linux26
#   tags:
#     - lnf
#   stage: test
#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:lite
#   allow_failure: true
#   script:
#     - scp chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$CI_COMMIT_REF_NAME/i686/stage_chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_static_linux26.tar.gz chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_static_linux26.tar.gz
#     - tar xfz chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_static_linux26.tar.gz chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_static_linux26/bin/UnitServer
#     - scp chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_static_linux26/bin/UnitServer root@dante073:UnitServer-test
#     - ssh root@dante073 "./UnitServer-test --help"
#     - ssh root@dante073 "rm ./UnitServer-test"


# test_i686_dynamic_linux26:
#   dependencies:
#     - build_i686_dynamic_linux26
#   tags:
#     - lnf
#   stage: test
#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:lite
#   allow_failure: true
#   script:
#     - scp chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_dynamic_linux26.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$CI_COMMIT_REF_NAME/i686/stage_chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_dynamic_linux26.tar.gz
#     - tar xfz chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_dynamic_linux26.tar.gz chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_dynamic_linux26/bin/daqLiberaServer chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_dynamic_linux26/lib
#     - mv chaos-distrib-$CI_COMMIT_REF_NAME-build_i686_dynamic_linux26/ test
#     - ssh michelo@192.168.143.252 "rm -rf /export/chaos-libera/new/test"
#     - scp -r test michelo@192.168.143.252:/export/chaos-libera/new
#     - ssh root@libera12 "LD_LIBRARY_PATH=/mnt/chaos/new/test/lib /mnt/chaos/new/test/bin/daqLiberaServer --help"
#     - ssh michelo@192.168.143.252 "rm -rf /export/chaos-libera/new/test"


# ubuntu1604_test_x86_64:
#   stage: test
#   retry: 2  
#   tags:
#     - run  
#   dependencies:
#     - ubuntu1604_x86_64
#   services:
#   - name: couchbase/server:community-5.0.1
#     alias: couchbase
#   - name: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation/mongo:3.4
#     alias: mongo

#   image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1604
#   script:
#     - tar xfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos/
#     - $INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5;$INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5;
#     - repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#     - repo sync
#     - cp -r tools $INSTALL_DIR
#     - cp -r common/test/js $INSTALL_DIR/tools/test
#     - export PPROF_PATH=$INSTALL_DIR/bin/pprof;
#     - source $INSTALL_DIR/chaos_env.sh
#     - if [ -n "$USE_MDS_CONFIG" ];then echo "* Using $USE_MDS_CONFIG" ; cp $USE_MDS_CONFIG $INSTALL_DIR/etc/mds.cfg;fi
#     - if ! $INSTALL_DIR/bin/TestFramework;then export HEAPCHECK=strict; echo "*retrying with heap check"; $INSTALL_DIR/bin/TestFramework; exit 1;fi
#     - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log;echo "* retrying test in debug mode";$INSTALL_DIR/tools/dbinit.sh couchbase mongo;export CHAOS_DEBUG_CMD_TOOL="gdb";if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-debug.tar.gz -C /usr/local/chaos/chaos-distrib log;exit 1;fi;fi
#     - $INSTALL_DIR/tools/chaos_services.sh stop
#     - tar cfz $DISTRIB_NAME-log-ok.tar.gz -C /usr/local/chaos/chaos-distrib log
#   artifacts:
#     name: "log.tar.gz"
#     paths:
#     - ./*-log*.tar.gz
#     expire_in: 3 day
#     when: always
#   only:
#     variables:
#       - $BUILD_DISTRIBUTION == "ubuntu1604_x86_64"
#       - $BUILD_DISTRIBUTION == null

ubuntu1804_test_x86_64:
  stage: test
  retry: 2  
  tags:      
   - shared
  dependencies:
    - ubuntu1804_x86_64

  variables:
    ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9092,INTERNAL://localhost:9093'
    LISTENERS: 'PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093'
    SECURITY_PROTOCOL_MAP: 'PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT'
    LOG_RETENTION_BYTES: 10737418240
    AUTO_CREATE_TOPICS_ENABLE: 'true'
    INTER_BROKER: 'INTERNAL'

  services:
  - name: couchbase/server:community-5.0.1
    alias: couchbase
  - name: mongo:3.6
    alias: mongo
  - name: michelo/kafka:2.6
    alias: kafka
  - name: influxdb
    alias: influxdb

  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1804
  script:
    - npm install -g jchaos  
    - rm -rf /usr/local/chaos/chaos-distrib  
    - tar xfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos/
    - $INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5;$INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5
#    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#    - repo sync
#    - mv CACHE chaosframework/config    
#    - cp -r tools $INSTALL_DIR
#    - cp -r common/test/js $INSTALL_DIR/tools/test
    - if [ -n "$USE_MDS_CONFIG" ];then echo "* Using $USE_MDS_CONFIG" ; cp $USE_MDS_CONFIG $INSTALL_DIR/etc/mds.cfg;fi    
    - source $INSTALL_DIR/chaos_env.sh
#    - $INSTALL_DIR/bin/TestFramework
    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;echo "* retrying test in debug mode";$INSTALL_DIR/tools/dbinit.sh couchbase mongo;export CHAOS_DEBUG_CMD_TOOL="gdb";if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-debug.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;echo "* retrying test in sanitize mode";if ! CHAOS_SERVICE_ENV="LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.5" $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-sanitize.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;exit 1;fi;fi;fi
#    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files; test 1 == 2;fi
    - $INSTALL_DIR/tools/chaos_services.sh stop
    - tar cfz $DISTRIB_NAME-log-ok.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files
  artifacts:
    name: "log.tar.gz"
    paths:
    - ./*-log*.tar.gz
    expire_in: 3 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "ubuntu1804_x86_64"
      - $BUILD_DISTRIBUTION == null
  except:
    variables:
      - $SKIP_TEST

ubuntu1804_test_profile_x86_64:
  stage: test  
  tags:
    - shared    
  dependencies:
    - ubuntu1804_profile_x86_64
  variables:
    ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9092,INTERNAL://localhost:9093'
    LISTENERS: 'PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093'
    SECURITY_PROTOCOL_MAP: 'PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT'
    LOG_RETENTION_BYTES: 10737418240
    AUTO_CREATE_TOPICS_ENABLE: 'true'
    INTER_BROKER: 'INTERNAL'

  services:
  - name: couchbase/server:community-5.0.1
    alias: couchbase
  - name: mongo:3.6
    alias: mongo
  - name: michelo/kafka:2.6
    alias: kafka    
  - name: influxdb
    alias: influxdb

  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1804
  script:
    - npm install -g jchaos  
    - rm -rf /usr/local/chaos/chaos-distrib  
    - tar xfz $DISTRIB_NAME.tar.gz -C /
    - $INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5;$INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5
#    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#    - repo sync
#    - cp -r tools $INSTALL_DIR
#    - cp -r common/test/js $INSTALL_DIR/tools/test/
    - export PPROF_PATH=$INSTALL_DIR/bin/pprof;
    - source $INSTALL_DIR/chaos_env.sh
    - if [ -n "$USE_MDS_CONFIG" ];then echo "* Using $USE_MDS_CONFIG" ; cp $USE_MDS_CONFIG $INSTALL_DIR/etc/mds.cfg;fi    
#    - HEAPCHECK=normal; LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc.so $INSTALL_DIR/bin/TestFramework;
#    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files ;exit 1;fi
    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files; test 1 == 2;fi
    - $INSTALL_DIR/tools/chaos_services.sh stop
    - mkdir -p $INSTALL_DIR/log/html
    - gcovr -r . --html --html-details -o $INSTALL_DIR/log/html/coverage.html -v > $INSTALL_DIR/log/gcovr.log
    - tar cfz $DISTRIB_NAME-profile-log-ok.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files
  allow_failure: true
  artifacts:
    name: "log.tar.gz"
    paths:
    - ./*-log*.tar.gz
    expire_in: 3 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "ubuntu1804_profile_x86_64"
      - $BUILD_DISTRIBUTION == null
  except:
    variables:
      - $SKIP_TEST


centos7_test_x86_64:
  stage: test
  retry: 2  
  tags:
    - shared
#    - run  
  dependencies:
    - centos7_x86_64
  
  variables:
    ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9092,INTERNAL://localhost:9093'
    LISTENERS: 'PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093'
    SECURITY_PROTOCOL_MAP: 'PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT'
    LOG_RETENTION_BYTES: 10737418240
    AUTO_CREATE_TOPICS_ENABLE: 'true'
    INTER_BROKER: 'INTERNAL'

  services:
  - name: couchbase/server:community-5.0.1
    alias: couchbase
  - name: mongo:3.6
    alias: mongo
  - name: michelo/kafka:2.6
    alias: kafka    
  - name: influxdb
    alias: influxdb

  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:centos7
  script:
    - npm install -g jchaos  
    - rm -rf /usr/local/chaos/chaos-distrib
    - tar xfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos/
    - scl enable devtoolset-8 bash
    - $INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5;$INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5
#    - repo init -q --no-clone-bundle -u https://amichelo:$KBS_SECRET_GITREAD@baltig.infn.it/chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
#    - repo sync
#    - export PPROF_PATH=$INSTALL_DIR/bin/pprof
#    - cp -r tools $INSTALL_DIR
#    - cp -r common/test/js $INSTALL_DIR/tools/test
    - source $INSTALL_DIR/chaos_env.sh
    - if [ -n "$USE_MDS_CONFIG" ];then echo "* Using $USE_MDS_CONFIG" ; cp $USE_MDS_CONFIG $INSTALL_DIR/etc/mds.cfg;fi    
#    - if ! $INSTALL_DIR/bin/TestFramework;then export HEAPCHECK=strict; echo "*retrying with heap check"; $INSTALL_DIR/bin/TestFramework; exit 1;fi
    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then export HEAPCHECK=normal; tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;echo "* retrying test in debug mode";$INSTALL_DIR/tools/dbinit.sh couchbase mongo;export CHAOS_DEBUG_CMD_TOOL="gdb";if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-debug.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;exit 1;fi;fi
#    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files; test 1 == 2;fi
    - $INSTALL_DIR/tools/chaos_services.sh stop
    - tar cfz $DISTRIB_NAME-log-ok.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files
  artifacts:
    name: "log.tar.gz"
    paths:
    - ./*-log*.tar.gz
    expire_in: 3 day
    when: always
  only:
    variables:
      - $BUILD_DISTRIBUTION == "centos7_x86_64"
      - $BUILD_DISTRIBUTION == null
  except:
    variables:
      - $SKIP_TEST

 # ubuntu1404_test_x86_64:
 #  stage: test
 #  retry: 2  
 #  tags:
 #    - run
 #  dependencies:
 #    - ubuntu1404_x86_64
 #  services:
 #  - name: couchbase/server:community-5.0.1
 #    alias: couchbase
 #  - name: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation/mongo:3.4
 #    alias: mongo

 #  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1404
 #  script:
 #    - rm -rf /usr/local/chaos/chaos-distrib;tar xfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos
 #    - $INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5;$INSTALL_DIR/tools/dbinit.sh couchbase mongo;sleep 5
 #    - repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME
 #    - repo sync
 #    - cp -r tools $INSTALL_DIR
 #    - cp -r common/test/js $INSTALL_DIR/tools/test
 #    - source $INSTALL_DIR/chaos_env.sh
 #    - export PPROF_PATH=$INSTALL_DIR/bin/pprof
 #    - if [ -n "$USE_MDS_CONFIG" ];then echo "* Using $USE_MDS_CONFIG" ; cp $USE_MDS_CONFIG $INSTALL_DIR/etc/mds.cfg;fi    
 #    - if ! $INSTALL_DIR/bin/TestFramework;then export HEAPCHECK=strict; echo "*retrying with heap check"; $INSTALL_DIR/bin/TestFramework; exit 1;fi
 #    - if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then export HEAPCHECK=normal;     tar cfvz $DISTRIB_NAME-log-bad.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;echo "* retrying test in debug mode";$INSTALL_DIR/tools/dbinit.sh couchbase mongo;export CHAOS_DEBUG_CMD_TOOL="gdb";if ! $INSTALL_DIR/tools/chaos_test.sh -k -d $INSTALL_DIR/tools/test;then tar cfvz $DISTRIB_NAME-log-debug.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files;exit 1;fi;fi
 #    - $INSTALL_DIR/tools/chaos_services.sh stop
 #    - tar cfz $DISTRIB_NAME-log-ok.tar.gz -C /usr/local/chaos/chaos-distrib log ini_files

 #  artifacts:
 #    name: "log.tar.gz"
 #    paths:
 #    - ./*-log*.tar.gz
 #    expire_in: 3 day
 #    when: always
 #  only:
 #    variables:
 #      - $BUILD_DISTRIBUTION == "ubuntu1404_test_x86_64"
 #      - $BUILD_DISTRIBUTION == null

deploy_stage:
  tags:
    - lnf
  dependencies:
#    - ubuntu1404_x86_64
#    - ubuntu1604_x86_64
    - ubuntu1804_x86_64
    - centos7_x86_64
    - build_i686_dynamic_linux26
    - build_arm_linux26
    - build_armhf_dynamic
    - build_armhf_static    
    - build_i686_static_linux26
  stage: deploy
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:1804
  script:
#    - scripts/accept_merge_request.sh $CI_COMMIT_REF_NAME
    - OUTPUT_REV_DIR=$CI_COMMIT_REF_NAME
#    - if [ $CI_COMMIT_REF_NAME == "master" ];then OUTPUT_REV_DIR="production";fi
    - if [ -e chaos-osx10-distrib.tar.gz ];then scp chaos-osx10-distrib.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/osx/;fi
#    - scp chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/16.04/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz
#    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/16.04/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/16.04/latest.tar.gz"
    - scp chaos-distrib-$REVNAME-ubuntu-18.04-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/18.04/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz
    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/18.04/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/18.04/latest.tar.gz"
    - scp chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/centos/7/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz
    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/centos/7/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/centos/7/latest.tar.gz"
#    - scp chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/14.04/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz
#    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/14.04/chaos-distrib.$TAR_NAME_POSTFIX.tar.gz /var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/14.04/latest.tar.gz"
    - scp chaos-distrib-$REVNAME-build_arm_linux26.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/arm/chaos-distrib-$REVNAME-build_arm_linux26.tar.gz
    - scp chaos-distrib-$REVNAME-build_armhf_dynamic.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/arm/chaos-distrib-$REVNAME-build_armhf_dynamic.tar.gz
    - scp chaos-distrib-$REVNAME-build_armhf_static.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/arm/chaos-distrib-$REVNAME-build_armhf_static.tar.gz    
    - scp chaos-distrib-$REVNAME-build_i686_dynamic_linux26.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/i686/chaos-distrib-$REVNAME-build_i686_dynamic_linux26.tar.gz
    - scp chaos-distrib-$REVNAME-build_i686_static_linux26.tar.gz  chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/i686/chaos-distrib-$REVNAME-build_i686_static_linux26.tar.gz
        
    - if [ "$DEPLOY_DESTINATION" == "development" ];then echo "deploying in LNF DEVELOPMENT infrastructure"; tar xfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos;cd $DISTRIB_PREFIX;source chaos_env.sh;./tools/chaos_deploy.sh -c tools/config/lnf/test/chaos-infrastructure.txt -i /usr/local/chaos/chaos-distrib;fi
    - if [ "$DEPLOY_DESTINATION" == "production" ];then echo "deploying in LNF MASTER infrastructure"; tar xfz $DISTRIB_NAME.tar.gz -C /usr/local/chaos;cd $DISTRIB_PREFIX;source chaos_env.sh;./tools/chaos_deploy.sh -c tools/config/lnf/production/chaos-infrastructure.txt -i /usr/local/chaos/chaos-distrib;cd tools/config/lnf/production; ./update_luminometer.sh;fi
    - curl -X POST -F token="81913e63e951cc80ebf0095440d432" -F "ref=experimental" -F "variables[DEPLOY_DESTINATION]=$OUTPUT_REV_DIR" https://baltig.infn.it/api/v4/projects/1443/trigger/pipeline
#    - md5sum chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz > chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz.md5
    - md5sum chaos-distrib-$REVNAME-ubuntu-18.04-x86_64.tar.gz > chaos-distrib-$REVNAME-ubuntu-18.04-x86_64.tar.gz.md5
#    - md5sum chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz > chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz.md5
    - md5sum chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz > chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz.md5
#    - scp chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/16.04/latest.tar.md5
#    - scp chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/14.04/latest.tar.md5
    - scp chaos-distrib-$REVNAME-ubuntu-18.04-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/ubuntu/18.04/latest.tar.md5
    - scp chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/$OUTPUT_REV_DIR/$ARCH/centos/7/latest.tar.md5
#    - if [ $CI_COMMIT_REF_NAME == "experimental" ];then repo init -q --no-clone-bundle -u git@baltig.infn.it:chaos-lnf-control/chaos_repo_bundle.git -b $CI_COMMIT_REF_NAME;repo sync;echo "* merging experimental in development";./chaosframework/tools/chaos_git.sh -o $MERGE_COMMENT -m experimental development ;./chaosframework/tools/chaos_git.sh -p development;fi
  only:
    variables:
      - $BUILD_DISTRIBUTION == null

pages:
  stage: publish
  dependencies:
#    - ubuntu1404_test_x86_64
#    - ubuntu1604_test_x86_64
    - centos7_test_x86_64
    - ubuntu1804_test_x86_64
    - ubuntu1804_test_profile_x86_64
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:lite
  script:
    - mkdir -p perf/ubuntu1404 perf/ubuntu1604 perf/centos7 perf/ubuntu1804 perf/ubuntu1804-profile public
    - ls -latr
#    - if [ -e chaos-distrib-$REVNAME-ubuntu-14.04-x86_64-log-ok.tar.gz ];then tar xfvz chaos-distrib-$REVNAME-ubuntu-14.04-x86_64-log-ok.tar.gz -C perf/ubuntu1404;mv perf/ubuntu1404/log/*.png perf/ubuntu1404;mv perf/ubuntu1404/log/html/* perf/ubuntu1404;rm -rf perf/ubuntu1404/log;fi
#    - if [ -e chaos-distrib-$REVNAME-ubuntu-16.04-x86_64-log-ok.tar.gz ]; then tar xfvz chaos-distrib-$REVNAME-ubuntu-16.04-x86_64-log-ok.tar.gz -C perf/ubuntu1604;mv perf/ubuntu1604/log/*.png perf/ubuntu1604;mv perf/ubuntu1604/log/html/* perf/ubuntu1604;rm -rf perf/ubuntu1604/log;fi
    - if [ -e chaos-distrib-$REVNAME-ubuntu-18.04-x86_64-log-ok.tar.gz ]; then tar xfvz chaos-distrib-$REVNAME-ubuntu-18.04-x86_64-log-ok.tar.gz -C perf/ubuntu1804;mv perf/ubuntu1804/log/*.png perf/ubuntu1804;mv perf/ubuntu1804/log/html/* perf/ubuntu1804;rm -rf perf/ubuntu1804/log;fi
    - if [ -e chaos-distrib-$REVNAME-ubuntu-18.04-profile-x86_64-log-ok.tar.gz ]; then tar xfvz chaos-distrib-$REVNAME-ubuntu-18.04-x86_64-profile-log-ok.tar.gz -C perf/ubuntu1804-profile;mv perf/ubuntu1804-profile/log/*.png perf/ubuntu1804-profile;mv perf/ubuntu1804-profile/log/html/* perf/ubuntu1804-profile;rm -rf perf/ubuntu1804-profile/log;fi
    - if [ -e chaos-distrib-$REVNAME-centos-7-x86_64-log-ok.tar.gz ]; then tar xfvz chaos-distrib-$REVNAME-centos-7-x86_64-log-ok.tar.gz -C perf/centos7;mv perf/centos7/log/*.png perf/centos7/;mv perf/centos7/log/html/* perf/centos7/;rm -rf perf/centos7/log;fi
    - mv perf public
    - git clone git@baltig.infn.it:chaos-lnf-control/chaos_bundle_tools.git -b $CI_COMMIT_REF_NAME
    - ./chaos_bundle_tools/images2html.sh public performace > public/index.html
  allow_failure: true
  artifacts:
    paths:
    - 'public'
    expire_in: 60 day
  only:
    variables:
      - $BUILD_DISTRIBUTION == null

deploy_nightly:
  tags:
    - lnf
  dependencies:
#    - ubuntu1404_x86_64
#    - ubuntu1604_x86_64
    - ubuntu1804_x86_64
    - centos7_x86_64
    - build_i686_dynamic_linux26
    - build_arm_linux26
    - build_armhf_dynamic
    - build_armhf_static        
    - build_i686_static_linux26
  stage: deploy_nightly
  image: baltig.infn.it:4567/chaos-lnf-control/chaos_bundle_compilation:lite
  script:
    - if [ -e chaos-osx10-distrib.tar.gz ];then scp chaos-osx10-distrib.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/osx/$NIGHTLY_NAME;fi
#    - md5sum chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz > chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz.md5
#    - md5sum chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz > chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz.md5
    - md5sum chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz > chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz.md5
#    - scp chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/ubuntu/16.04/latest.tar.md5
#    - scp chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/ubuntu/14.04/latest.tar.md5    
#    - scp chaos-distrib-$REVNAME-ubuntu-18.04-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/ubuntu/18.04/latest.tar.md5
    - scp chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz.md5 chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/centos/7/latest.tar.md5
#    - scp chaos-distrib-$REVNAME-ubuntu-16.04-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/ubuntu/16.04/$NIGHTLY_NAME    
#    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/ubuntu/16.04/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/ubuntu/16.04/latest.tar.gz"        
    - scp chaos-distrib-$REVNAME-ubuntu-18.04-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/ubuntu/18.04/$NIGHTLY_NAME
    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/ubuntu/18.04/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/ubuntu/18.04/latest.tar.gz"
    - scp chaos-distrib-$REVNAME-centos-7-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/centos/7/$NIGHTLY_NAME
    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/centos/7/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/centos/7/latest.tar.gz"
#    - scp chaos-distrib-$REVNAME-ubuntu-14.04-x86_64.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/$ARCH/ubuntu/14.04/$NIGHTLY_NAME
#    - ssh chaosweb@opensource.lnf.infn.it "ln -sf /var/www/html/binary/chaos/nightly/$ARCH/ubuntu/14.04/$NIGHTLY_NAME /var/www/html/binary/chaos/nightly/$ARCH/ubuntu/14.04/latest.tar.gz"
    - scp chaos-distrib-$REVNAME-build_arm_linux26.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/chaos-distrib-$REVNAME-build_arm_linux26.tar.gz
    - scp chaos-distrib-$REVNAME-build_armhf_dynamic.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/chaos-distrib-$REVNAME-build_armhf_dynamic.tar.gz
    - scp chaos-distrib-$REVNAME-build_armhf_static.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/arm/chaos-distrib-$REVNAME-build_armhf_static.tar.gz    
    - scp chaos-distrib-$REVNAME-build_i686_dynamic_linux26.tar.gz chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/i686/chaos-distrib-$REVNAME-build_i686_dynamic_linux26.tar.gz
    - scp chaos-distrib-$REVNAME-build_i686_static_linux26.tar.gz  chaosweb@opensource.lnf.infn.it:/var/www/html/binary/chaos/nightly/i686/chaos-distrib-$REVNAME-build_i686_static_linux26.tar.gz
  allow_failure: true
  only:
    variables:
      - $CI_COMMIT_REF_NAME == "experimental"
