/build-all.sh

https://github.com/tinode/chat · Shell · 191 lines · 122 code · 34 blank · 35 comment · 11 complexity · bd40ad92eb2112d9d33640738f09fa1b MD5 · raw file

  1. #!/bin/bash
  2. # Cross-compiling script using https://github.com/mitchellh/gox
  3. # This scripts build and archives binaries and supporting files.
  4. # If directory ./server/static exists, it's asumed to contain
  5. # TinodeWeb and then it's also copied and archived.
  6. # Check if gox is installed. Abort otherwise.
  7. command -v gox >/dev/null 2>&1 || {
  8. echo >&2 "This script requires https://github.com/mitchellh/gox. Please install it before running."; exit 1;
  9. }
  10. # Supported OSs: darwin windows linux
  11. goplat=( darwin windows linux )
  12. # Supported CPU architectures: amd64
  13. goarc=( amd64 )
  14. # Supported database tags
  15. dbadapters=( mysql mongodb rethinkdb )
  16. dbtags=( ${dbadapters[@]} alldbs )
  17. for line in $@; do
  18. eval "$line"
  19. done
  20. version=${tag#?}
  21. if [ -z "$version" ]; then
  22. # Get last git tag as release version. Tag looks like 'v.1.2.3', so strip 'v'.
  23. version=`git describe --tags`
  24. version=${version#?}
  25. fi
  26. echo "Releasing $version"
  27. GOSRC=${GOPATH}/src/github.com/tinode
  28. pushd ${GOSRC}/chat > /dev/null
  29. # Prepare directory for the new release
  30. rm -fR ./releases/${version}
  31. mkdir ./releases/${version}
  32. for plat in "${goplat[@]}"
  33. do
  34. for arc in "${goarc[@]}"
  35. do
  36. # Keygen is database-independent
  37. # Remove previous build
  38. rm -f $GOPATH/bin/keygen
  39. # Build
  40. gox -osarch="${plat}/${arc}" -ldflags "-s -w" -output $GOPATH/bin/keygen ./keygen > /dev/null
  41. for dbtag in "${dbtags[@]}"
  42. do
  43. echo "Building ${dbtag}-${plat}/${arc}..."
  44. # Remove previous builds
  45. rm -f $GOPATH/bin/tinode
  46. rm -f $GOPATH/bin/init-db
  47. # Build tinode server and database initializer for RethinkDb and MySQL.
  48. # For 'alldbs' tag, we compile in all available DB adapters.
  49. if [ "$dbtag" = "alldbs" ]; then
  50. buildtag="${dbadapters[@]}"
  51. else
  52. buildtag=$dbtag
  53. fi
  54. gox -osarch="${plat}/${arc}" \
  55. -ldflags "-s -w -X main.buildstamp=`git describe --tags`" \
  56. -tags "${buildtag}" -output $GOPATH/bin/tinode ./server > /dev/null
  57. gox -osarch="${plat}/${arc}" \
  58. -ldflags "-s -w" \
  59. -tags "${buildtag}" -output $GOPATH/bin/init-db ./tinode-db > /dev/null
  60. # Tar on Mac is inflexible about directories. Let's just copy release files to
  61. # one directory.
  62. rm -fR ./releases/tmp
  63. mkdir -p ./releases/tmp/templ
  64. # Copy templates and database initialization files
  65. cp ./server/tinode.conf ./releases/tmp
  66. cp ./server/templ/*.templ ./releases/tmp/templ
  67. cp ./tinode-db/data.json ./releases/tmp
  68. cp ./tinode-db/*.jpg ./releases/tmp
  69. cp ./tinode-db/credentials.sh ./releases/tmp
  70. # Create directories for and copy TinodeWeb files.
  71. if [[ -d ./server/static ]]
  72. then
  73. mkdir -p ./releases/tmp/static/img
  74. mkdir ./releases/tmp/static/css
  75. mkdir ./releases/tmp/static/audio
  76. mkdir ./releases/tmp/static/src
  77. mkdir ./releases/tmp/static/umd
  78. cp ./server/static/img/*.png ./releases/tmp/static/img
  79. cp ./server/static/img/*.svg ./releases/tmp/static/img
  80. cp ./server/static/audio/*.mp3 ./releases/tmp/static/audio
  81. cp ./server/static/css/*.css ./releases/tmp/static/css
  82. cp ./server/static/index.html ./releases/tmp/static
  83. cp ./server/static/index-dev.html ./releases/tmp/static
  84. cp ./server/static/umd/*.js ./releases/tmp/static/umd
  85. cp ./server/static/manifest.json ./releases/tmp/static
  86. cp ./server/static/service-worker.js ./releases/tmp/static
  87. # Create empty FCM client-side config.
  88. echo > ./releases/tmp/static/firebase-init.js
  89. else
  90. echo "TinodeWeb not found, skipping"
  91. fi
  92. # Build archive. All platforms but Windows use tar for archiving. Windows uses zip.
  93. if [ "$plat" = "windows" ]; then
  94. # Copy binaries
  95. cp $GOPATH/bin/tinode.exe ./releases/tmp
  96. cp $GOPATH/bin/init-db.exe ./releases/tmp
  97. cp $GOPATH/bin/keygen.exe ./releases/tmp
  98. # Remove possibly existing archive.
  99. rm -f ./releases/${version}/tinode-${dbtag}."${plat}-${arc}".zip
  100. # Generate a new one
  101. pushd ./releases/tmp > /dev/null
  102. zip -q -r ../${version}/tinode-${dbtag}."${plat}-${arc}".zip ./*
  103. popd > /dev/null
  104. else
  105. plat2=$plat
  106. # Rename 'darwin' tp 'mac'
  107. if [ "$plat" = "darwin" ]; then
  108. plat2=mac
  109. fi
  110. # Copy binaries
  111. cp $GOPATH/bin/tinode ./releases/tmp
  112. cp $GOPATH/bin/init-db ./releases/tmp
  113. cp $GOPATH/bin/keygen ./releases/tmp
  114. # Remove possibly existing archive.
  115. rm -f ./releases/${version}/tinode-${dbtag}."${plat2}-${arc}".tar.gz
  116. # Generate a new one
  117. tar -C ${GOSRC}/chat/releases/tmp -zcf ./releases/${version}/tinode-${dbtag}."${plat2}-${arc}".tar.gz .
  118. fi
  119. done
  120. done
  121. done
  122. # Need to rebuild the linux-rethink binary without stripping debug info.
  123. echo "Building the binary for web.tinode.co"
  124. rm -f $GOPATH/bin/tinode
  125. rm -f $GOPATH/bin/init-db
  126. gox -osarch=linux/amd64 \
  127. -ldflags "-X main.buildstamp=`git describe --tags`" \
  128. -tags rethinkdb -output $GOPATH/bin/tinode ./server > /dev/null
  129. gox -osarch=linux/amd64 \
  130. -tags rethinkdb -output $GOPATH/bin/init-db ./tinode-db > /dev/null
  131. # Build chatbot release
  132. echo "Building python code..."
  133. ./build-py-grpc.sh
  134. # Release chatbot
  135. echo "Packaging chatbot.py..."
  136. rm -fR ./releases/tmp
  137. mkdir -p ./releases/tmp
  138. cp ${GOSRC}/chat/chatbot/python/chatbot.py ./releases/tmp
  139. cp ${GOSRC}/chat/chatbot/python/quotes.txt ./releases/tmp
  140. cp ${GOSRC}/chat/chatbot/python/requirements.txt ./releases/tmp
  141. tar -C ${GOSRC}/chat/releases/tmp -zcf ./releases/${version}/py-chatbot.tar.gz .
  142. pushd ./releases/tmp > /dev/null
  143. zip -q -r ../${version}/py-chatbot.zip ./*
  144. popd > /dev/null
  145. # Release tn-cli
  146. echo "Packaging tn-cli..."
  147. rm -fR ./releases/tmp
  148. mkdir -p ./releases/tmp
  149. cp ${GOSRC}/chat/tn-cli/*.py ./releases/tmp
  150. cp ${GOSRC}/chat/tn-cli/requirements.txt ./releases/tmp
  151. tar -C ${GOSRC}/chat/releases/tmp -zcf ./releases/${version}/tn-cli.tar.gz .
  152. pushd ./releases/tmp > /dev/null
  153. zip -q -r ../${version}/tn-cli.zip ./*
  154. popd > /dev/null
  155. # Clean up temporary files
  156. rm -fR ./releases/tmp
  157. popd > /dev/null