Makefile 6.7 KB

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