Makefile 8.6 KB

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