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.

289 lines
14 KiB

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