Makefile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. RELEASE=./.releases
  18. all: lint test build
  19. ci: testcgo build
  20. .PHONY: all ci
  21. #########################################
  22. # Bootstrapping
  23. #########################################
  24. bootstra%:
  25. $Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest
  26. $Q go install golang.org/x/vuln/cmd/govulncheck@latest
  27. $Q go install gotest.tools/gotestsum@latest
  28. .PHONY: bootstra%
  29. #################################################
  30. # Determine the type of `push` and `version`
  31. #################################################
  32. # If TRAVIS_TAG is set then we know this ref has been tagged.
  33. ifdef TRAVIS_TAG
  34. VERSION ?= $(TRAVIS_TAG)
  35. NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
  36. ifeq ($(NOT_RC),)
  37. PUSHTYPE := release-candidate
  38. else
  39. PUSHTYPE := release
  40. endif
  41. # GITHUB Actions
  42. else ifdef GITHUB_REF
  43. VERSION ?= $(shell echo $(GITHUB_REF) | sed 's/^refs\/tags\///')
  44. NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
  45. ifeq ($(NOT_RC),)
  46. PUSHTYPE := release-candidate
  47. else
  48. PUSHTYPE := release
  49. endif
  50. else
  51. VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
  52. # If we are not in an active git dir then try reading the version from .VERSION.
  53. # .VERSION contains a slug populated by `git archive`.
  54. VERSION := $(or $(VERSION),$(shell ./.version.sh .VERSION))
  55. ifeq ($(TRAVIS_BRANCH),master)
  56. PUSHTYPE := master
  57. else
  58. PUSHTYPE := branch
  59. endif
  60. endif
  61. VERSION := $(shell echo $(VERSION) | sed 's/^v//')
  62. DEB_VERSION := $(shell echo $(VERSION) | sed 's/-/./g')
  63. ifdef V
  64. $(info TRAVIS_TAG is $(TRAVIS_TAG))
  65. $(info GITHUB_REF is $(GITHUB_REF))
  66. $(info VERSION is $(VERSION))
  67. $(info DEB_VERSION is $(DEB_VERSION))
  68. $(info PUSHTYPE is $(PUSHTYPE))
  69. endif
  70. include make/docker.mk
  71. #########################################
  72. # Build
  73. #########################################
  74. DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
  75. LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
  76. GOFLAGS := CGO_ENABLED=0
  77. download:
  78. $Q go mod download
  79. build: $(PREFIX)bin/$(BINNAME) $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(PREFIX)bin/$(AWSKMS_BINNAME) $(PREFIX)bin/$(YUBIKEY_BINNAME) $(PREFIX)bin/$(PKCS11_BINNAME)
  80. @echo "Build Complete!"
  81. $(PREFIX)bin/$(BINNAME): download $(call rwildcard,*.go)
  82. $Q mkdir -p $(@D)
  83. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
  84. $(PREFIX)bin/$(CLOUDKMS_BINNAME): download $(call rwildcard,*.go)
  85. $Q mkdir -p $(@D)
  86. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(LDFLAGS) $(CLOUDKMS_PKG)
  87. $(PREFIX)bin/$(AWSKMS_BINNAME): download $(call rwildcard,*.go)
  88. $Q mkdir -p $(@D)
  89. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(AWSKMS_BINNAME) $(LDFLAGS) $(AWSKMS_PKG)
  90. $(PREFIX)bin/$(YUBIKEY_BINNAME): download $(call rwildcard,*.go)
  91. $Q mkdir -p $(@D)
  92. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(YUBIKEY_BINNAME) $(LDFLAGS) $(YUBIKEY_PKG)
  93. $(PREFIX)bin/$(PKCS11_BINNAME): download $(call rwildcard,*.go)
  94. $Q mkdir -p $(@D)
  95. $Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(PKCS11_BINNAME) $(LDFLAGS) $(PKCS11_PKG)
  96. # Target to force a build of step-ca without running tests
  97. simple: build
  98. .PHONY: download build simple
  99. #########################################
  100. # Go generate
  101. #########################################
  102. generate:
  103. $Q go generate ./...
  104. .PHONY: generate
  105. #########################################
  106. # Test
  107. #########################################
  108. test:
  109. $Q $(GOFLAGS) gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  110. testcgo:
  111. $Q gotestsum -- -coverprofile=coverage.out -short -covermode=atomic ./...
  112. .PHONY: test testcgo
  113. integrate: integration
  114. integration: bin/$(BINNAME)
  115. $Q $(GOFLAGS) gotestsum -- -tags=integration ./integration/...
  116. .PHONY: integrate integration
  117. #########################################
  118. # Linting
  119. #########################################
  120. fmt:
  121. $Q goimports -l -w $(SRC)
  122. lint: SHELL:=/bin/bash
  123. lint:
  124. $Q LOG_LEVEL=error golangci-lint run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
  125. $Q govulncheck ./...
  126. .PHONY: fmt lint
  127. #########################################
  128. # Install
  129. #########################################
  130. INSTALL_PREFIX?=/usr/
  131. install: $(PREFIX)bin/$(BINNAME) $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(PREFIX)bin/$(AWSKMS_BINNAME)
  132. $Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
  133. $Q install -D $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(CLOUDKMS_BINNAME)
  134. $Q install -D $(PREFIX)bin/$(AWSKMS_BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(AWSKMS_BINNAME)
  135. uninstall:
  136. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
  137. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(CLOUDKMS_BINNAME)
  138. $Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(AWSKMS_BINNAME)
  139. .PHONY: install uninstall
  140. #########################################
  141. # Clean
  142. #########################################
  143. clean:
  144. ifneq ($(BINNAME),"")
  145. $Q rm -f bin/$(BINNAME)
  146. endif
  147. ifneq ($(CLOUDKMS_BINNAME),"")
  148. $Q rm -f bin/$(CLOUDKMS_BINNAME)
  149. endif
  150. ifneq ($(AWSKMS_BINNAME),"")
  151. $Q rm -f bin/$(AWSKMS_BINNAME)
  152. endif
  153. ifneq ($(YUBIKEY_BINNAME),"")
  154. $Q rm -f bin/$(YUBIKEY_BINNAME)
  155. endif
  156. ifneq ($(PKCS11_BINNAME),"")
  157. $Q rm -f bin/$(PKCS11_BINNAME)
  158. endif
  159. .PHONY: clean
  160. #########################################
  161. # Dev
  162. #########################################
  163. run:
  164. $Q go run cmd/step-ca/main.go $(shell step path)/config/ca.json
  165. .PHONY: run
  166. #########################################
  167. # Debian
  168. #########################################
  169. changelog:
  170. $Q echo "step-ca ($(DEB_VERSION)) unstable; urgency=medium" > debian/changelog
  171. $Q echo >> debian/changelog
  172. $Q echo " * See https://github.com/smallstep/certificates/releases" >> debian/changelog
  173. $Q echo >> debian/changelog
  174. $Q echo " -- Smallstep Labs, Inc. <techadmin@smallstep.com> $(shell date -uR)" >> debian/changelog
  175. debian: changelog
  176. $Q mkdir -p $(RELEASE); \
  177. OUTPUT=../step-ca*.deb; \
  178. rm $$OUTPUT; \
  179. dpkg-buildpackage -b -rfakeroot -us -uc && cp $$OUTPUT $(RELEASE)/
  180. distclean: clean
  181. .PHONY: changelog debian distclean
  182. #################################################
  183. # Targets for creating step artifacts
  184. #################################################
  185. docker-artifacts: docker-$(PUSHTYPE)
  186. .PHONY: docker-artifacts