You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
15 KiB

  1. ##
  2. # Extra checks, because we do not use autoconf. Set extra_check to false if it is bothering you.
  3. ##
  4. extra_check = true
  5. go_min_version = 1.8.3
  6. gpg_key = 2122CBE9
  7. ifeq ($(extra_check),true)
  8. ifndef GOPATH
  9. $(error GOPATH not set)
  10. else
  11. go_version := $(shell go version | sed "s/^.* go\([0-9\.]*\) .*$$/\1/" )
  12. $(info Found go version $(go_version))
  13. go_version_check := $(shell echo -e "$(go_min_version)\n$(go_version)" | sort -V | head -1)
  14. ifneq ($(go_min_version),$(go_version_check))
  15. $(error go version go_min_version or above is required)
  16. endif
  17. endif
  18. gpg_check := $(shell gpg -K | grep '/$(gpg_key) ' | sed 's,^.*/\($(gpg_key)\) .*$$,\1,')
  19. ifneq ($(gpg_check),$(gpg_key))
  20. $(error GPG key $(gpg_key) not found.)
  21. else
  22. $(info GPG key $(gpg_key) found)
  23. endif
  24. ifndef GPG_PASSPHRASE
  25. $(error GPG_PASSPHRASE not set)
  26. endif
  27. endif
  28. ###
  29. # Here comes the real deal
  30. ###
  31. binaries = tendermint basecoin ethermint trackomatron gaia cosmos-sdk
  32. build-binaries = build-tendermint build-basecoin build-ethermint build-trackomatron build-gaia build-cosmos-sdk
  33. package-rpm = package-rpm-tendermint package-rpm-basecoin package-rpm-ethermint package-rpm-trackomatron package-rpm-gaia package-rpm-cosmos-sdk
  34. install-rpm = install-rpm-tendermint install-rpm-basecoin install-rpm-ethermint install-rpm-trackomatron install-rpm-gaia package-rpm-cosmos-sdk
  35. package-deb = package-deb-tendermint package-deb-basecoin package-deb-ethermint package-deb-trackomatron package-deb-gaia package-deb-cosmos-sdk
  36. install-deb = install-deb-tendermint install-deb-basecoin install-deb-ethermint install-deb-trackomatron install-deb-gaia install-deb-cosmos-sdk
  37. all: $(binaries)
  38. build: $(build-binaries)
  39. package: $(package-rpm) $(package-deb)
  40. install: $(install-rpm) $(install-deb)
  41. $(binaries): %: build-% package-rpm-% package-deb-%
  42. ###
  43. # Build the binaries
  44. ###
  45. git-branch:
  46. $(eval GIT_BRANCH=$(shell echo $${GIT_BRANCH:-master}))
  47. build-tendermint: git-branch
  48. @echo "*** Building tendermint"
  49. go get -d -u github.com/tendermint/tendermint/cmd/tendermint
  50. cd $(GOPATH)/src/github.com/tendermint/tendermint && git checkout "$(GIT_BRANCH)" && git pull
  51. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/tendermint get_vendor_deps build
  52. cp $(GOPATH)/src/github.com/tendermint/tendermint/build/tendermint $(GOPATH)/bin
  53. @echo "*** Built tendermint"
  54. build-basecoin: git-branch
  55. @echo "*** Building basecoin"
  56. go get -d -u github.com/tendermint/basecoin/cmd/basecoin
  57. cd $(GOPATH)/src/github.com/tendermint/basecoin && git checkout "$(GIT_BRANCH)" && git pull
  58. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/basecoin get_vendor_deps install
  59. @echo "*** Built basecoin"
  60. build-ethermint: git-branch
  61. @echo "*** Building ethermint"
  62. go get -d -u github.com/tendermint/ethermint/cmd/ethermint
  63. cd $(GOPATH)/src/github.com/tendermint/ethermint && git checkout "$(GIT_BRANCH)" && git pull
  64. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/ethermint get_vendor_deps build
  65. cp $(GOPATH)/src/github.com/tendermint/ethermint/build/ethermint $(GOPATH)/bin
  66. @echo "*** Built ethermint"
  67. build-trackomatron: git-branch
  68. @echo "*** Building trackomatron"
  69. go get -d -u go github.com/tendermint/trackomatron/cmd/tracko
  70. cd $(GOPATH)/src/github.com/tendermint/trackomatron && git checkout "$(GIT_BRANCH)" && git pull
  71. $(MAKE) -C $(GOPATH)/src/github.com/tendermint/trackomatron get_vendor_deps install
  72. @echo "Workaround: trackomatron package has tracko as the binary - trackomatron needed for proper packaging" && rm -rf $(GOPATH)/bin/trackomatron && ln -s $(GOPATH)/bin/tracko $(GOPATH)/bin/trackomatron
  73. @echo "*** Built trackomatron"
  74. build-gaia: git-branch
  75. @echo "*** Building gaia"
  76. go get -d -u go github.com/cosmos/gaia || echo "Workaround for go downloads."
  77. cd $(GOPATH)/src/github.com/cosmos/gaia && git checkout "$(GIT_BRANCH)" && git pull
  78. $(MAKE) -C $(GOPATH)/src/github.com/cosmos/gaia get_vendor_deps install
  79. @echo "*** Built gaia"
  80. build-cosmos-sdk: git-branch
  81. @echo "*** Building cosmos-sdk"
  82. go get -d -u go github.com/cosmos/cosmos-sdk || echo "Workaround for go downloads."
  83. cd $(GOPATH)/src/github.com/cosmos/cosmos-sdk && git checkout "$(GIT_BRANCH)" && git pull
  84. $(MAKE) -C $(GOPATH)/src/github.com/cosmos/cosmos-sdk get_vendor_deps install
  85. @echo "Workaround: cosmos-sdk does not have a binary that gives the cosmos-sdk version number." && rm -rf $(GOPATH)/bin/cosmos-sdk && ln -s $(GOPATH)/bin/basecoin $(GOPATH)/bin/cosmos-sdk
  86. @echo "*** Built cosmos-sdk"
  87. ###
  88. # Prepare package files
  89. ###
  90. # set app_version
  91. version-%: $(GOPATH)/bin/%
  92. if [ -z "$(BUILD_NUMBER)" ]; then echo "BUILD_NUMBER not set" ; false ; fi
  93. $(eval $*_version=$(shell $< version | cut -d- -f1 ))
  94. # set build_folder
  95. folder-%: version-%
  96. $(eval build_folder=BUILD/$*-$($*_version)-$(BUILD_NUMBER))
  97. # clean up folder structure for package files
  98. prepare-files = rm -rf $(build_folder) && mkdir -p $(build_folder) && cp -r ./$(1)/* $(build_folder) && mkdir -p $(build_folder)/usr/bin && cp $(GOPATH)/bin/$(1) $(build_folder)/usr/bin
  99. ##
  100. ## Package customizations for the different applications
  101. ##
  102. prepare-tendermint =
  103. prepare-basecoin = cp $(GOPATH)/bin/basecli $(build_folder)/usr/bin
  104. prepare-ethermint = mkdir -p $(build_folder)/etc/ethermint && \
  105. cp $(GOPATH)/src/github.com/tendermint/ethermint/setup/genesis.json $(build_folder)/etc/ethermint/genesis.json && \
  106. cp -r $(GOPATH)/src/github.com/tendermint/ethermint/setup/keystore $(build_folder)/etc/ethermint
  107. prepare-trackomatron = rm -f $(build_folder)/usr/bin/trackomatron && cp $(GOPATH)/bin/tracko $(GOPATH)/bin/trackocli $(build_folder)/usr/bin
  108. prepare-gaia =
  109. prepare-cosmos-sdk = rm -f $(build_folder)/usr/bin/cosmos-sdk && \
  110. cp $(GOPATH)/bin/basecli $(GOPATH)/bin/basecoin $(GOPATH)/bin/baseserver $(GOPATH)/bin/counter $(GOPATH)/bin/countercli $(GOPATH)/bin/eyes $(GOPATH)/bin/eyescli $(build_folder)/usr/bin
  111. ###
  112. # Package the binary for CentOS/RedHat (RPM) and Debian/Ubuntu (DEB)
  113. ###
  114. # Depends on rpmbuild, sorry, this can only be built on CentOS/RedHat machines.
  115. package-rpm-%: folder-%
  116. @echo "*** Packaging RPM $* version $($*_version)"
  117. $(call prepare-files,$*)
  118. $(call prepare-$*)
  119. rm -rf $(build_folder)/DEBIAN
  120. mkdir -p $(build_folder)/usr/share/licenses/$*
  121. cp ./LICENSE $(build_folder)/usr/share/licenses/$*/LICENSE
  122. chmod -Rf a+rX,u+w,g-w,o-w $(build_folder)
  123. mkdir -p {SPECS,tmp}
  124. cp ./spectemplates/$*.spec SPECS
  125. sed -i "s/@VERSION@/$($*_version)/" SPECS/$*.spec
  126. sed -i "s/@BUILD_NUMBER@/$(BUILD_NUMBER)/" SPECS/$*.spec
  127. rpmbuild -bb SPECS/$*.spec --define "_topdir `pwd`" --define "_tmppath `pwd`/tmp"
  128. ./sign RPMS/x86_64/$*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm "$(gpg_key)" "`which gpg`"
  129. rpm -Kv RPMS/x86_64/$*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm || echo "rpm returns non-zero exist for some reason. ($?)"
  130. @echo "*** Packaged RPM $* version $($*_version)"
  131. package-deb-%: folder-%
  132. @echo "*** Packaging DEB $* version $($*_version)-$(BUILD_NUMBER)"
  133. $(call prepare-files,$*)
  134. $(call prepare-$*)
  135. mkdir -p $(build_folder)/usr/share/doc/$*
  136. cp $(build_folder)/DEBIAN/copyright $(build_folder)/usr/share/doc/$*
  137. chmod -Rf a+rX,u+w,g-w,o-w $(build_folder)
  138. sed -i "s/@VERSION@/$($*_version)-$(BUILD_NUMBER)/" $(build_folder)/DEBIAN/changelog
  139. sed -i "s/@STABILITY@/stable/" $(build_folder)/DEBIAN/changelog
  140. sed -i "s/@DATETIMESTAMP@/`date +%a,\ %d\ %b\ %Y\ %T\ %z`/" $(build_folder)/DEBIAN/changelog
  141. sed -i "s/@VERSION@/$($*_version)-$(BUILD_NUMBER)/" $(build_folder)/DEBIAN/control
  142. gzip -c $(build_folder)/DEBIAN/changelog > $(build_folder)/usr/share/doc/$*/changelog.Debian.gz
  143. gzip -c $(build_folder)/DEBIAN/changelog > $(build_folder)/usr/share/doc/$*/changelog.Debian.amd64.gz
  144. sed -i "s/@INSTALLEDSIZE@/`du -ks $(build_folder) | cut -f 1`/" $(build_folder)/DEBIAN/control
  145. cd $(build_folder) && tar --owner=root --group=root -cvJf ../../tmp/data.tar.xz --exclude DEBIAN *
  146. cd $(build_folder)/DEBIAN && tar --owner=root --group=root -cvzf ../../../tmp/control.tar.gz *
  147. echo "2.0" > tmp/debian-binary
  148. cp ./_gpg tmp/
  149. cd tmp && sed -i "s/@DATETIMESTAMP@/`date +%a\ %b\ %d\ %T\ %Y`/" _gpg
  150. cd tmp && sed -i "s/@BINMD5@/`md5sum debian-binary | cut -d\ -f1`/" _gpg
  151. cd tmp && sed -i "s/@BINSHA1@/`sha1sum debian-binary | cut -d\ -f1`/" _gpg
  152. cd tmp && sed -i "s/@BINSIZE@/`stat -c %s debian-binary | cut -d\ -f1`/" _gpg
  153. cd tmp && sed -i "s/@CONMD5@/`md5sum control.tar.gz | cut -d\ -f1`/" _gpg
  154. cd tmp && sed -i "s/@CONSHA1@/`sha1sum control.tar.gz | cut -d\ -f1`/" _gpg
  155. cd tmp && sed -i "s/@CONSIZE@/`stat -c %s control.tar.gz | cut -d\ -f1`/" _gpg
  156. cd tmp && sed -i "s/@DATMD5@/`md5sum data.tar.xz | cut -d\ -f1`/" _gpg
  157. cd tmp && sed -i "s/@DATSHA1@/`sha1sum data.tar.xz | cut -d\ -f1`/" _gpg
  158. cd tmp && sed -i "s/@DATSIZE@/`stat -c %s data.tar.xz | cut -d\ -f1`/" _gpg
  159. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --clearsign tmp/_gpg
  160. mv tmp/_gpg.asc tmp/_gpgbuilder
  161. ar r tmp/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb tmp/debian-binary tmp/control.tar.gz tmp/data.tar.xz tmp/_gpgbuilder
  162. mv tmp/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb RPMS/
  163. rm tmp/debian-binary tmp/control.tar.gz tmp/data.tar.xz tmp/_gpgbuilder tmp/_gpg
  164. @echo "*** Packaged DEB $* version $($*_version)-$(BUILD_NUMBER)"
  165. install-rpm-%: version-%
  166. #Make sure your host has the IAM role to read/write the S3 bucket OR that you set up ~/.boto
  167. @echo "*** Uploading $*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm to AWS $(DEVOPS_PATH)CentOS repository"
  168. aws s3 sync s3://tendermint-packages/$(DEVOPS_PATH)centos/ tmp/s3/ --delete
  169. mkdir -p tmp/s3/7/os/x86_64/Packages
  170. cp RPMS/x86_64/$*-$($*_version)-$(BUILD_NUMBER).x86_64.rpm tmp/s3/7/os/x86_64/Packages
  171. cp ./RPM-GPG-KEY-Tendermint tmp/s3/7/os/x86_64/
  172. cp ./tendermint.repo tmp/s3/7/os/x86_64/
  173. rm -f tmp/s3/7/os/x86_64/repodata/*.bz2 tmp/s3/7/os/x86_64/repodata/*.gz tmp/s3/7/os/x86_64/repodata/repomd.xml.asc
  174. createrepo tmp/s3/7/os/x86_64/Packages -u https://tendermint-packages.interblock.io/$(DEVOPS_PATH)centos/7/os/x86_64/Packages -o tmp/s3/7/os/x86_64 --update -S --repo Tendermint --content tendermint --content basecoin --content ethermint
  175. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --detach-sign -a tmp/s3/7/os/x86_64/repodata/repomd.xml
  176. aws s3 sync tmp/s3/ s3://tendermint-packages/$(DEVOPS_PATH)centos/ --delete --acl public-read
  177. @echo "*** Uploaded $* to AWS $(DEVOPS_PATH)CentOS repository"
  178. install-deb-%: version-%
  179. @echo "*** Uploading $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb to AWS $(DEVOPS_PATH)Debian repository"
  180. @echo "Testing if $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb is already uploaded"
  181. test ! -f tmp/debian-s3/pool/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb
  182. aws s3 sync s3://tendermint-packages/$(DEVOPS_PATH)debian/ tmp/debian-s3/ --delete
  183. @echo "Testing if $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb is already uploaded"
  184. test ! -f tmp/debian-s3/pool/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb
  185. cp ./tendermint.list tmp/debian-s3/
  186. mkdir -p tmp/debian-s3/pool tmp/debian-s3/dists/stable/main/binary-amd64
  187. cp RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb tmp/debian-s3/pool
  188. cp ./Release_amd64 tmp/debian-s3/dists/stable/main/binary-amd64/Release
  189. #Packages / Packages.gz
  190. echo > tmp/Package
  191. echo "Filename: pool/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb" >> tmp/Package
  192. echo "MD5sum: `md5sum RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  193. echo "SHA1: `sha1sum RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  194. echo "SHA256: `sha256sum RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  195. echo "Size: `stat -c %s RPMS/$*-$($*_version)-$(BUILD_NUMBER)_amd64.deb | cut -d\ -f 1`" >> tmp/Package
  196. cat BUILD/$*-$($*_version)-$(BUILD_NUMBER)/DEBIAN/control >> tmp/Package
  197. cat tmp/Package >> tmp/debian-s3/dists/stable/main/binary-amd64/Packages
  198. rm -f tmp/debian-s3/dists/stable/main/binary-amd64/Packages.gz
  199. gzip -c tmp/debian-s3/dists/stable/main/binary-amd64/Packages > tmp/debian-s3/dists/stable/main/binary-amd64/Packages.gz
  200. rm -f tmp/Package
  201. #main / Release / InRelease / Release.gpg
  202. cp ./Release tmp/debian-s3/dists/stable/main/Release
  203. rm -f tmp/debian-s3/dists/stable/main/InRelease
  204. rm -f tmp/debian-s3/dists/stable/main/Release.gpg
  205. echo "MD5Sum:" >> tmp/debian-s3/dists/stable/main/Release
  206. cd tmp/debian-s3/dists/stable/main && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; md5sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  207. echo "SHA1:" >> tmp/debian-s3/dists/stable/main/Release
  208. cd tmp/debian-s3/dists/stable/main && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha1sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  209. echo "SHA256:" >> tmp/debian-s3/dists/stable/main/Release
  210. cd tmp/debian-s3/dists/stable/main && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha256sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  211. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA256 -b -a tmp/debian-s3/dists/stable/main/Release
  212. mv tmp/debian-s3/dists/stable/main/Release.asc tmp/debian-s3/dists/stable/main/Release.gpg
  213. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA512 --clearsign tmp/debian-s3/dists/stable/main/Release
  214. mv tmp/debian-s3/dists/stable/main/Release.asc tmp/debian-s3/dists/stable/main/InRelease
  215. #stable / Release / InRelease / Release.gpg
  216. cp ./Release tmp/debian-s3/dists/stable/Release
  217. rm -f tmp/debian-s3/dists/stable/InRelease
  218. rm -f tmp/debian-s3/dists/stable/Release.gpg
  219. echo "MD5Sum:" >> tmp/debian-s3/dists/stable/Release
  220. cd tmp/debian-s3/dists/stable && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; md5sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  221. echo "SHA1:" >> tmp/debian-s3/dists/stable/Release
  222. cd tmp/debian-s3/dists/stable && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha1sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  223. echo "SHA256:" >> tmp/debian-s3/dists/stable/Release
  224. cd tmp/debian-s3/dists/stable && for f in `find . -type f | sed 's/^.\///'` ; do test "$$f" == "Release" && continue ; echo -n " " ; sha256sum $$f | sed "s/ / `stat -c %s $$f` /" ; done >> Release
  225. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA256 -b -a tmp/debian-s3/dists/stable/Release
  226. mv tmp/debian-s3/dists/stable/Release.asc tmp/debian-s3/dists/stable/Release.gpg
  227. gpg --batch --passphrase "$(GPG_PASSPHRASE)" --digest-algo SHA512 --clearsign tmp/debian-s3/dists/stable/Release
  228. mv tmp/debian-s3/dists/stable/Release.asc tmp/debian-s3/dists/stable/InRelease
  229. aws s3 sync tmp/debian-s3/ s3://tendermint-packages/$(DEVOPS_PATH)debian/ --delete --acl public-read
  230. @echo "*** Uploaded $*-$($*_version)-$(BUILD_NUMBER)_amd64.deb to AWS $(DEVOPS_PATH)Debian repository"
  231. mostlyclean:
  232. rm -rf {BUILDROOT,SOURCES,SPECS,SRPMS,tmp}
  233. clean: mostlyclean
  234. rm -rf {BUILD,RPMS}
  235. distclean: clean
  236. rm -rf $(GOPATH)/src/github.com/tendermint/tendermint
  237. rm -rf $(GOPATH)/src/github.com/tendermint/basecoin
  238. rm -rf $(GOPATH)/src/github.com/tendermint/ethermint
  239. rm -rf $(GOPATH)/src/github.com/tendermint/trackomatron
  240. rm -rf $(GOPATH)/bin/tendermint
  241. rm -rf $(GOPATH)/bin/basecoin
  242. rm -rf $(GOPATH)/bin/basecli
  243. rm -rf $(GOPATH)/bin/ethermint
  244. rm -rf $(GOPATH)/bin/tracko
  245. rm -rf $(GOPATH)/bin/trackocli
  246. .PHONY : clean