Makefile 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 build test
  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)
  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. uninstall:
  113. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  114. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(CLOUDKMS_BINNAME)
  115. .PHONY: install uninstall
  116. #########################################
  117. # Clean
  118. #########################################
  119. clean:
  120. ifneq ($(BINNAME),"")
  121. $Q rm -f bin/$(BINNAME)
  122. endif
  123. ifneq ($(CLOUDKMS_BINNAME),"")
  124. $Q rm -f bin/$(CLOUDKMS_BINNAME)
  125. endif
  126. .PHONY: clean
  127. #########################################
  128. # Dev
  129. #########################################
  130. run:
  131. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  132. .PHONY: run
  133. #########################################
  134. # Debian
  135. #########################################
  136. changelog:
  137. $Q echo "step-certificates ($(DEB_VERSION)) unstable; urgency=medium" > debian/changelog
  138. $Q echo >> debian/changelog
  139. $Q echo " * See https://github.com/smallstep/certificates/releases" >> debian/changelog
  140. $Q echo >> debian/changelog
  141. $Q echo " -- Smallstep Labs, Inc. <techadmin@smallstep.com> $(shell date -uR)" >> debian/changelog
  142. debian: changelog
  143. $Q mkdir -p $(RELEASE); \
  144. OUTPUT=../step-certificates_*.deb; \
  145. rm $$OUTPUT; \
  146. dpkg-buildpackage -b -rfakeroot -us -uc && cp $$OUTPUT $(RELEASE)/
  147. distclean: clean
  148. .PHONY: changelog debian distclean
  149. #################################################
  150. # Build statically compiled step binary for various operating systems
  151. #################################################
  152. BINARY_OUTPUT=$(OUTPUT_ROOT)binary/
  153. RELEASE=./.travis-releases
  154. define BUNDLE_MAKE
  155. # $(1) -- Go Operating System (e.g. linux, darwin, windows, etc.)
  156. # $(2) -- Go Architecture (e.g. amd64, arm, arm64, etc.)
  157. # $(3) -- Go ARM architectural family (e.g. 7, 8, etc.)
  158. # $(4) -- Parent directory for executables generated by 'make'.
  159. $(q) GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2) GOARM=$(3)' PREFIX=$(4) make $(4)bin/$(BINNAME) $(4)bin/$(CLOUDKMS_BINNAME)
  160. endef
  161. binary-linux:
  162. $(call BUNDLE_MAKE,linux,amd64,,$(BINARY_OUTPUT)linux/)
  163. binary-linux-arm64:
  164. $(call BUNDLE_MAKE,linux,arm64,,$(BINARY_OUTPUT)linux.arm64/)
  165. binary-linux-armv7:
  166. $(call BUNDLE_MAKE,linux,arm,7,$(BINARY_OUTPUT)linux.armv7/)
  167. binary-darwin:
  168. $(call BUNDLE_MAKE,darwin,amd64,,$(BINARY_OUTPUT)darwin/)
  169. define BUNDLE
  170. # $(1) -- Binary Output Dir Name
  171. # $(2) -- Step Platform Name
  172. # $(3) -- Step Binary Architecture
  173. # $(4) -- Step Binary Name (For Windows Comaptibility)
  174. $(q) ./make/bundle.sh "$(BINARY_OUTPUT)$(1)" "$(RELEASE)" "$(VERSION)" "$(2)" "$(3)" "$(4)" "$(5)"
  175. endef
  176. bundle-linux: binary-linux binary-linux-arm64 binary-linux-armv7
  177. $(call BUNDLE,linux,linux,amd64,$(BINNAME),$(CLOUDKMS_BINNAME))
  178. $(call BUNDLE,linux.arm64,linux,arm64,$(BINNAME),$(CLOUDKMS_BINNAME))
  179. $(call BUNDLE,linux.armv7,linux,armv7,$(BINNAME),$(CLOUDKMS_BINNAME))
  180. bundle-darwin: binary-darwin
  181. $(call BUNDLE,darwin,darwin,amd64,$(BINNAME),$(CLOUDKMS_BINNAME))
  182. .PHONY: binary-linux binary-darwin bundle-linux bundle-darwin
  183. #################################################
  184. # Targets for creating OS specific artifacts and archives
  185. #################################################
  186. artifacts-linux-tag: bundle-linux debian
  187. artifacts-darwin-tag: bundle-darwin
  188. artifacts-archive-tag:
  189. $Q mkdir -p $(RELEASE)
  190. $Q git archive v$(VERSION) | gzip > $(RELEASE)/step-certificates_$(VERSION).tar.gz
  191. artifacts-tag: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag
  192. .PHONY: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag artifacts-tag
  193. #################################################
  194. # Targets for creating step artifacts
  195. #################################################
  196. # For all builds that are not tagged and not on the master branch
  197. artifacts-branch:
  198. # For all builds that are not tagged
  199. artifacts-master:
  200. # For all builds with a release-candidate (-rc) tag
  201. artifacts-release-candidate: artifacts-tag
  202. # For all builds with a release tag
  203. artifacts-release: artifacts-tag
  204. # This command is called by travis directly *after* a successful build
  205. artifacts: artifacts-$(PUSHTYPE) docker-$(PUSHTYPE)
  206. .PHONY: artifacts-master artifacts-release-candidate artifacts-release artifacts