buildClusterEnv.sh 3.8 KB
Newer Older
P
Ping Xiao 已提交
1 2 3
#!/bin/bash
echo "Executing buildClusterEnv.sh"
CURR_DIR=`pwd`
4
IN_TDINTERNAL="community"
P
Ping Xiao 已提交
5

P
Ping Xiao 已提交
6
if [ $# != 6 ]; then 
P
Ping Xiao 已提交
7 8
  echo "argument list need input : "
  echo "  -n numOfNodes"
P
Ping Xiao 已提交
9 10
  echo "  -v version"
  echo "  -d docker dir" 
P
Ping Xiao 已提交
11 12 13 14 15
  exit 1
fi

NUM_OF_NODES=
VERSION=
P
Ping Xiao 已提交
16 17
DOCKER_DIR=
while getopts "n:v:d:" arg
P
Ping Xiao 已提交
18 19 20 21 22 23 24
do
  case $arg in
    n)
      NUM_OF_NODES=$OPTARG
      ;;
    v)
      VERSION=$OPTARG
P
Ping Xiao 已提交
25 26 27
      ;;
    d)
      DOCKER_DIR=$OPTARG
P
Ping Xiao 已提交
28 29 30 31 32 33 34 35 36
      ;;    
    ?)
      echo "unkonwn argument"
      ;;
  esac
done

function prepareBuild {

37
  if [ -d $CURR_DIR/../../../release ]; then
P
Ping Xiao 已提交
38
    echo release exists
39
    rm -rf $CURR_DIR/../../../release/*
P
Ping Xiao 已提交
40 41
  fi

42
  cd $CURR_DIR/../../../packaging 
P
Ping Xiao 已提交
43

P
Ping Xiao 已提交
44 45 46 47 48 49
  if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
    if [ ! -e $DOCKER_DIR/TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz ] || [ ! -e $DOCKER_DIR/TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
              
      echo "generating TDeninge enterprise packages"
      ./release.sh -v cluster -n $VERSION >> /dev/null 2>&1
      
50
      if [ ! -e $CURR_DIR/../../../release/TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz ]; then
51 52 53 54
        echo "no TDengine install package found"
        exit 1
      fi

55
      if [ ! -e $CURR_DIR/../../../release/TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
56 57 58
        echo "no arbitrator install package found"
        exit 1
      fi
P
Ping Xiao 已提交
59

60
      cd $CURR_DIR/../../../release
P
Ping Xiao 已提交
61 62 63 64 65 66 67 68 69
      mv TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
      mv TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
    fi
  else
    if [ ! -e $DOCKER_DIR/TDengine-server-$VERSION-Linux-x64.tar.gz ] || [ ! -e $DOCKER_DIR/TDengine-arbitrator-$VERSION-Linux-x64.tar.gz ]; then

      echo "generating TDeninge community packages"
      ./release.sh -v edge -n $VERSION >> /dev/null 2>&1
      
70
      if [ ! -e $CURR_DIR/../../../release/TDengine-server-$VERSION-Linux-x64.tar.gz ]; then
71 72 73 74
        echo "no TDengine install package found"
        exit 1
      fi

75
      if [ ! -e $CURR_DIR/../../../release/TDengine-arbitrator-$VERSION-Linux-x64.tar.gz ]; then
76 77 78
        echo "no arbitrator install package found"
        exit 1
      fi
79

80
      cd $CURR_DIR/../../../release
81 82
      mv TDengine-server-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
      mv TDengine-arbitrator-$VERSION-Linux-x64.tar.gz $DOCKER_DIR
P
Ping Xiao 已提交
83
    fi   
84
  fi
P
Ping Xiao 已提交
85 86 87 88
  
  rm -rf $DOCKER_DIR/*.yml
  cd $CURR_DIR

89
  cp *.yml  $DOCKER_DIR
P
Ping Xiao 已提交
90 91 92 93
  cp Dockerfile $DOCKER_DIR
}

function clusterUp {
94
  echo "docker compose start"
P
Ping Xiao 已提交
95
  
96
  cd $DOCKER_DIR  
97

98
  if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
P
Ping Xiao 已提交
99
    docker_run="PACKAGE=TDengine-enterprise-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-enterprise-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-enterprise-server-$VERSION DIR2=TDengine-enterprise-arbitrator-$VERSION VERSION=$VERSION DATADIR=$DOCKER_DIR docker-compose -f docker-compose.yml "
100 101 102 103
  else
    docker_run="PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION DATADIR=$DOCKER_DIR docker-compose -f docker-compose.yml "
  fi

104 105 106 107 108 109 110 111 112 113
  if [ $NUM_OF_NODES -ge 2 ];then
    echo "create $NUM_OF_NODES dnodes"
    for((i=3;i<=$NUM_OF_NODES;i++))
    do
      if [ ! -f node$i.yml ];then
        echo "node$i.yml not exist"
        cp node3.yml node$i.yml
        sed -i "s/td2.0-node3/td2.0-node$i/g" node$i.yml
        sed -i "s/'tdnode3'/'tdnode$i'/g" node$i.yml
        sed -i "s#/node3/#/node$i/#g" node$i.yml
L
fix  
liuyq-617 已提交
114
        sed -i "s#hostname: tdnode3#hostname: tdnode$i#g" node$i.yml
115 116 117 118 119
        sed -i "s#ipv4_address: 172.27.0.9#ipv4_address: 172.27.0.`expr $i + 6`#g" node$i.yml
      fi
      docker_run=$docker_run" -f node$i.yml "
    done
    docker_run=$docker_run" up -d"
P
Ping Xiao 已提交
120
  fi
121
  echo $docker_run |sh
L
change  
liuyq-617 已提交
122
  
123
  echo "docker compose finish"
P
Ping Xiao 已提交
124 125
}

126 127
prepareBuild
clusterUp