dockerbuild.sh 4.7 KB
Newer Older
1
#!/bin/bash
2 3
#

4 5 6 7 8 9 10
set -e
#set -x

# dockerbuild.sh 
#             -c [aarch32 | aarch64 | amd64 | x86 | mips64 ...]  
#             -n [version number]
#             -p [password for docker hub]
11 12
#             -V [stable | beta]
#             -f [pkg file]
13 14

# set parameters by default value
15
cpuType=""
16
cpuTypeAlias=""
17
version=""
18 19
passWord=""
pkgFile=""
20
verType="stable"
haoranc's avatar
haoranc 已提交
21
dockerLatest="n"
22

haoranc's avatar
haoranc 已提交
23
while getopts "hc:n:p:f:V:a:b:" arg
24 25 26 27 28 29 30
do
  case $arg in
    c)
      #echo "cpuType=$OPTARG"
      cpuType=$(echo $OPTARG)
      ;;
    n)
31 32
      #echo "version=$OPTARG"
      version=$(echo $OPTARG)
33 34 35 36 37 38 39 40 41
      ;;
    p)
      #echo "passWord=$OPTARG"
      passWord=$(echo $OPTARG)
      ;;
    f)
      #echo "pkgFile=$OPTARG"
      pkgFile=$(echo $OPTARG)
      ;;
haoranc's avatar
haoranc 已提交
42 43 44 45
    b)
      #echo "branchName=$OPTARG"
      branchName=$(echo $OPTARG)
      ;;
46 47 48 49
    V)
      #echo "verType=$OPTARG"
      verType=$(echo $OPTARG)
      ;;
haoranc's avatar
haoranc 已提交
50 51 52 53
    a)
      #echo "dockerLatest=$OPTARG"
      dockerLatest=$(echo $OPTARG)
      ;;
54
    h)
55
      echo "Usage: `basename $0`  -c [aarch32 | aarch64 | amd64 | x86 | mips64 ...] "
56 57
      echo "                      -n [version number] "
      echo "                      -p [password for docker hub] "
58 59
      echo "                      -V [stable | beta] "
      echo "                      -f [pkg file] "
haoranc's avatar
haoranc 已提交
60
      echo "                      -a [y | n ]   "
61 62 63 64 65 66 67 68 69
      exit 0
      ;;
    ?) #unknow option 
      echo "unkonw argument"
      exit 1
      ;;
  esac
done

haoranc's avatar
haoranc 已提交
70 71 72 73 74

# Check_verison()
# {
# }

75 76 77

if [ "$verType" == "beta" ]; then
  dockername=${cpuType}-${verType}
78
  dirName=${pkgFile%-beta*}
79 80
elif [ "$verType" == "stable" ]; then
  dockername=${cpuType}
81
  dirName=${pkgFile%-Linux*}
82 83 84 85 86 87 88
else
  echo "unknow verType, nor stabel or beta"
  exit 1
fi


echo "cpuType=${cpuType} version=${version} pkgFile=${pkgFile} verType=${verType} "
89 90 91
echo "$(pwd)"
echo "====NOTES: ${pkgFile} must be in the same directory as dockerbuild.sh===="

92 93
scriptDir=$(dirname $(readlink -f $0))
comunityArchiveDir=/nas/TDengine/v$version/community   # community version’package directory
haoranc's avatar
haoranc 已提交
94 95 96
communityDir=${scriptDir}/../../../community
DockerfilePath=${communityDir}/packaging/docker/
Dockerfile=${communityDir}/packaging/docker/Dockerfile
97 98 99 100
cd ${scriptDir}
cp -f ${comunityArchiveDir}/${pkgFile}  .

echo "dirName=${dirName}"
101

102 103 104 105 106 107 108 109 110 111
if [[ "${cpuType}" == "x64" ]] || [[ "${cpuType}" == "amd64" ]]; then
    cpuTypeAlias="amd64"
elif [[ "${cpuType}" == "aarch64" ]]; then
    cpuTypeAlias="arm64"
elif [[ "${cpuType}" == "aarch32" ]]; then
    cpuTypeAlias="armhf"
else
    echo "Unknown cpuType: ${cpuType}"
    exit 1
fi
112

haoranc's avatar
haoranc 已提交
113
docker build --rm -f "${Dockerfile}"  --network=host -t tdengine/tdengine-${dockername}:${version} "." --build-arg pkgFile=${pkgFile} --build-arg dirName=${dirName} --build-arg cpuType=${cpuTypeAlias}
114
docker login -u tdengine -p ${passWord}  #replace the docker registry username and password
115
docker push tdengine/tdengine-${dockername}:${version}
116

haoranc's avatar
haoranc 已提交
117
if [ -n "$(docker ps -aq)" ] ;then 
haoranc's avatar
haoranc 已提交
118
  echo "delete docker process"
haoranc's avatar
haoranc 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131
  docker stop $(docker ps -aq)
  docker rm $(docker ps -aq)
fi

if [  -n "$(pidof taosd)" ] ;then
   echo "kill taosd "
   kill -9 $(pidof taosd)
fi

if [ -n "$(pidof power)" ]  ;then
  echo "kill power "
  kill -9 $(pidof power)
fi
132 133


haoranc's avatar
haoranc 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
echo ">>>>>>>>>>>>> check whether  tdengine/tdengine-${dockername}:${version}  has been published"
docker run -d --name doctest -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp  tdengine/tdengine-${dockername}:${version}
sleep 2
curl -u root:taosdata -d 'show variables;'  127.0.0.1:6041/rest/sql > temp1.data
data_version=$( cat temp1.data |jq .data| jq '.[]' |grep "version" -A 2 -B 1  | jq ".[1]")
echo "${data_version}" 
if [ "${data_version}" == "\"${version}\"" ] ; then
    echo  "docker version is right "
else
    echo  "docker version is wrong "
    exit 1
fi
rm -rf  temp1.data

# set this version to latest version 
if  [ ${dockerLatest} == 'y' ]  ;then
  docker tag tdengine/tdengine-${dockername}:${version} tdengine/tdengine-${dockername}:latest
  docker push tdengine/tdengine-${dockername}:latest
  echo ">>>>>>>>>>>>> check whether  tdengine/tdengine-${dockername}:latest has been published correctly"
  docker run -d --name doctestla -p 7030-7049:6030-6049 -p 7030-7049:6030-6049/udp   tdengine/tdengine-${dockername}:latest 
  sleep 2
  curl -u root:taosdata -d 'show variables;'  127.0.0.1:7041/rest/sql >  temp2.data
  version_latest=` cat temp2.data |jq .data| jq '.[]' |grep "version" -A 2 -B 1  | jq ".[1]" `
  echo "${version_latest}" 
  if [ "${version_latest}" == "\"${version}\"" ] ; then
      echo  "docker version is right "
  else 
      echo  "docker version is wrong "
      exit 1 
  fi
fi
rm -rf  temp2.data

if [ -n "$(docker ps -aq)" ] ;then 
  echo "delte docker process"
  docker stop $(docker ps -aq)
  docker rm $(docker ps -aq)
fi

cd ${scriptDir}
174
rm -f ${pkgFile}