Makefile 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. PKG?=github.com/smallstep/certificates/cmd/step-ca
  2. BINNAME?=step-ca
  3. CLOUDKMS_BINNAME?=step-cloudkms-init
  4. CLOUDKMS_PKG?=github.com/smallstep/certificates/cmd/step-cloudkms-init
  5. AWSKMS_BINNAME?=step-awskms-init
  6. AWSKMS_PKG?=github.com/smallstep/certificates/cmd/step-awskms-init
  7. YUBIKEY_BINNAME?=step-yubikey-init
  8. YUBIKEY_PKG?=github.com/smallstep/certificates/cmd/step-yubikey-init
  9. PKCS11_BINNAME?=step-pkcs11-init
  10. PKCS11_PKG?=github.com/smallstep/certificates/cmd/step-pkcs11-init
  11. # Set V to 1 for verbose output from the Makefile
  12. Q=$(if $V,,@)
  13. PREFIX?=
  14. SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
  15. GOOS_OVERRIDE ?=
  16. OUTPUT_ROOT=output/
  17. all: lint test build
  18. .PHONY: all
  19. #########################################
  20. # Bootstrapping
  21. #########################################
  22. bootstra%:
  23. # Using a released version of golangci-lint to take into account custom replacements in their go.mod
  24. $Q GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0
  25. .PHONY: bootstra%
  26. #################################################
  27. # Determine the type of `push` and `version`
  28. #################################################
  29. # If TRAVIS_TAG is set then we know this ref has been tagged.
  30. ifdef TRAVIS_TAG
  31. VERSION := $(TRAVIS_TAG)
  32. NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
  33. ifeq ($(NOT_RC),)
  34. PUSHTYPE := release-candidate
  35. else
  36. PUSHTYPE := release
  37. endif
  38. else
  39. VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
  40. # If we are not in an active git dir then try reading the version from .VERSION.
  41. # .VERSION contains a slug populated by `git archive`.
  42. VERSION := $(or $(VERSION),$(shell ./.version.sh .VERSION))
  43. ifeq ($(TRAVIS_BRANCH),master)
  44. PUSHTYPE := master
  45. else
  46. PUSHTYPE := branch
  47. endif
  48. endif
  49. VERSION := $(shell echo $(VERSION) | sed 's/^v//')
  50. DEB_VERSION := $(shell echo $(VERSION) | sed 's/-/~/g')
  51. ifdef V
  52. $(info TRAVIS_TAG is $(TRAVIS_TAG))
  53. $(info VERSION is $(VERSION))
  54. $(info DEB_VERSION is $(DEB_VERSION))
  55. $(info PUSHTYPE is $(PUSHTYPE))
  56. endif
  57. include make/docker.mk
  58. #########################################
  59. # Build
  60. #########################################
  61. DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
  62. LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
  63. GOFLAGS := CGO_ENABLED=0
  64. download:
  65. $Q go mod download
  66. build: $(PREFIX)bin/$(BINNAME) $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(PREFIX)bin/$(AWSKMS_BINNAME) $(PREFIX)bin/$(YUBIKEY_BINNAME) $(PREFIX)bin/$(PKCS11_BINNAME)
  67. @echo "Build Complete!"
  68. $(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
  69. $Q mkdir -p $(@D)
  70. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
  71. $(PREFIX)bin/$(CLOUDKMS_BINNAME): download $(call rwildcard,*.go)
  72. $Q mkdir -p $(@D)
  73. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(LDFLAGS) $(CLOUDKMS_PKG)
  74. $(PREFIX)bin/$(AWSKMS_BINNAME): download $(call rwildcard,*.go)
  75. $Q mkdir -p $(@D)
  76. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(AWSKMS_BINNAME) $(LDFLAGS) $(AWSKMS_PKG)
  77. $(PREFIX)bin/$(YUBIKEY_BINNAME): download $(call rwildcard,*.go)
  78. $Q mkdir -p $(@D)
  79. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(YUBIKEY_BINNAME) $(LDFLAGS) $(YUBIKEY_PKG)
  80. $(PREFIX)bin/$(PKCS11_BINNAME): download $(call rwildcard,*.go)
  81. $Q mkdir -p $(@D)
  82. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(PKCS11_BINNAME) $(LDFLAGS) $(PKCS11_PKG)
  83. # Target to force a build of step-ca without running tests
  84. simple: build
  85. .PHONY: download build simple
  86. #########################################
  87. # Go generate
  88. #########################################
  89. generate:
  90. $Q go generate ./...
  91. .PHONY: generate
  92. #########################################
  93. # Test
  94. #########################################
  95. test:
  96. $Q go test -short -coverprofile=coverage.out ./...
  97. .PHONY: test
  98. integrate: integration
  99. integration: bin/$(BINNAME)
  100. $Q $(GOFLAGS) go test -tags=integration ./integration/...
  101. .PHONY: integrate integration
  102. #########################################
  103. # Linting
  104. #########################################
  105. fmt:
  106. $Q gofmt -l -w $(SRC)
  107. lint:
  108. $Q LOG_LEVEL=error golangci-lint run --timeout=30m
  109. .PHONY: lint fmt
  110. #########################################
  111. # Install
  112. #########################################
  113. INSTALL_PREFIX?=/usr/
  114. install: $(PREFIX)bin/$(BINNAME) $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(PREFIX)bin/$(AWSKMS_BINNAME)
  115. $Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
  116. $Q install -D $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(CLOUDKMS_BINNAME)
  117. $Q install -D $(PREFIX)bin/$(AWSKMS_BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(AWSKMS_BINNAME)
  118. uninstall:
  119. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  120. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(CLOUDKMS_BINNAME)
  121. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(AWSKMS_BINNAME)
  122. .PHONY: install uninstall
  123. #########################################
  124. # Clean
  125. #########################################
  126. clean:
  127. ifneq ($(BINNAME),"")
  128. $Q rm -f bin/$(BINNAME)
  129. endif
  130. ifneq ($(CLOUDKMS_BINNAME),"")
  131. $Q rm -f bin/$(CLOUDKMS_BINNAME)
  132. endif
  133. ifneq ($(AWSKMS_BINNAME),"")
  134. $Q rm -f bin/$(AWSKMS_BINNAME)
  135. endif
  136. ifneq ($(YUBIKEY_BINNAME),"")
  137. $Q rm -f bin/$(YUBIKEY_BINNAME)
  138. endif
  139. ifneq ($(PKCS11_BINNAME),"")
  140. $Q rm -f bin/$(PKCS11_BINNAME)
  141. endif
  142. .PHONY: clean
  143. #########################################
  144. # Dev
  145. #########################################
  146. run:
  147. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  148. .PHONY: run
  149. #########################################
  150. # Debian
  151. #########################################
  152. changelog:
  153. $Q echo "step-certificates ($(DEB_VERSION)) unstable; urgency=medium" > debian/changelog
  154. $Q echo >> debian/changelog
  155. $Q echo " * See https://github.com/smallstep/certificates/releases" >> debian/changelog
  156. $Q echo >> debian/changelog
  157. $Q echo " -- Smallstep Labs, Inc. <techadmin@smallstep.com> $(shell date -uR)" >> debian/changelog
  158. debian: changelog
  159. $Q mkdir -p $(RELEASE); \
  160. OUTPUT=../step-certificates_*.deb; \
  161. rm $$OUTPUT; \
  162. dpkg-buildpackage -b -rfakeroot -us -uc && cp $$OUTPUT $(RELEASE)/
  163. distclean: clean
  164. .PHONY: changelog debian distclean
  165. #################################################
  166. # Build statically compiled step binary for various operating systems
  167. #################################################
  168. BINARY_OUTPUT=$(OUTPUT_ROOT)binary/
  169. RELEASE=./.travis-releases
  170. define BUNDLE_MAKE
  171. # $(1) -- Go Operating System (e.g. linux, darwin, windows, etc.)
  172. # $(2) -- Go Architecture (e.g. amd64, arm, arm64, etc.)
  173. # $(3) -- Go ARM architectural family (e.g. 7, 8, etc.)
  174. # $(4) -- Parent directory for executables generated by 'make'.
  175. $(q) GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2) GOARM=$(3)' PREFIX=$(4) make $(4)bin/$(BINNAME) $(4)bin/$(CLOUDKMS_BINNAME) $(4)bin/$(AWSKMS_BINNAME)
  176. endef
  177. binary-linux:
  178. $(call BUNDLE_MAKE,linux,amd64,,$(BINARY_OUTPUT)linux/)
  179. binary-linux-arm64:
  180. $(call BUNDLE_MAKE,linux,arm64,,$(BINARY_OUTPUT)linux.arm64/)
  181. binary-linux-armv7:
  182. $(call BUNDLE_MAKE,linux,arm,7,$(BINARY_OUTPUT)linux.armv7/)
  183. binary-darwin:
  184. $(call BUNDLE_MAKE,darwin,amd64,,$(BINARY_OUTPUT)darwin/)
  185. define BUNDLE
  186. # $(1) -- Binary Output Dir Name
  187. # $(2) -- Step Platform Name
  188. # $(3) -- Step Binary Architecture
  189. # $(4) -- Step Binary Name (For Windows Comaptibility)
  190. $(q) ./make/bundle.sh "$(BINARY_OUTPUT)$(1)" "$(RELEASE)" "$(VERSION)" "$(2)" "$(3)" "$(4)" "$(5)" "$(6)"
  191. endef
  192. bundle-linux: binary-linux binary-linux-arm64 binary-linux-armv7
  193. $(call BUNDLE,linux,linux,amd64,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
  194. $(call BUNDLE,linux.arm64,linux,arm64,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
  195. $(call BUNDLE,linux.armv7,linux,armv7,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
  196. bundle-darwin: binary-darwin
  197. $(call BUNDLE,darwin,darwin,amd64,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
  198. .PHONY: binary-linux binary-darwin bundle-linux bundle-darwin
  199. #################################################
  200. # Targets for creating OS specific artifacts and archives
  201. #################################################
  202. artifacts-linux-tag: bundle-linux debian
  203. artifacts-darwin-tag: bundle-darwin
  204. artifacts-archive-tag:
  205. $Q mkdir -p $(RELEASE)
  206. $Q git archive v$(VERSION) | gzip > $(RELEASE)/step-certificates_$(VERSION).tar.gz
  207. artifacts-tag: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag
  208. .PHONY: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag artifacts-tag
  209. #################################################
  210. # Targets for creating step artifacts
  211. #################################################
  212. # For all builds that are not tagged and not on the master branch
  213. artifacts-branch:
  214. # For all builds that are not tagged
  215. artifacts-master:
  216. # For all builds with a release-candidate (-rc) tag
  217. artifacts-release-candidate: artifacts-tag
  218. # For all builds with a release tag
  219. artifacts-release: artifacts-tag
  220. # This command is called by travis directly *after* a successful build
  221. artifacts: artifacts-$(PUSHTYPE) docker-$(PUSHTYPE)
  222. .PHONY: artifacts-master artifacts-release-candidate artifacts-release artifacts