You've already forked step-ca-cli
mirror of
https://github.com/smallstep/cli.git
synced 2026-10-24 11:19:19 +03:00
* Other repos with their own docker build targets can inlcude common.mk without overwriting their own docker targets. * Normally we could achieve a similar result by placing wildcard symbols (%) in the target names. However, because there is already a sub-directory named 'docker', placing a wildcard in the 'docke%' target name will cause the target to always be secondary to the directory (regardless of .PHONY target) and therefore never meet constraints for being rebuilt.
274 lines
7.3 KiB
Makefile
274 lines
7.3 KiB
Makefile
PKG?=github.com/smallstep/cli/cmd/step
|
|
BINNAME?=step
|
|
|
|
# Set V to 1 for verbose output from the Makefile
|
|
Q=$(if $V,,@)
|
|
PREFIX?=
|
|
SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
|
|
GOOS_OVERRIDE ?=
|
|
OUTPUT_ROOT=output/
|
|
|
|
# Set shell to bash for `echo -e`
|
|
SHELL := /bin/bash
|
|
|
|
all: build lint test
|
|
|
|
.PHONY: all
|
|
|
|
#########################################
|
|
# Bootstrapping
|
|
#########################################
|
|
|
|
bootstra%:
|
|
$Q which dep || go get github.com/golang/dep/cmd/dep
|
|
$Q dep ensure
|
|
|
|
vendor: Gopkg.lock
|
|
$Q dep ensure
|
|
|
|
BOOTSTRAP=\
|
|
github.com/golang/lint/golint \
|
|
github.com/client9/misspell/cmd/misspell \
|
|
github.com/gordonklaus/ineffassign \
|
|
github.com/tsenart/deadcode \
|
|
github.com/alecthomas/gometalinter
|
|
|
|
define VENDOR_BIN_TMPL
|
|
vendor/bin/$(notdir $(1)): vendor
|
|
$Q go build -o $$@ ./vendor/$(1)
|
|
VENDOR_BINS += vendor/bin/$(notdir $(1))
|
|
endef
|
|
|
|
$(foreach pkg,$(BOOTSTRAP),$(eval $(call VENDOR_BIN_TMPL,$(pkg))))
|
|
|
|
.PHONY: bootstra% vendor
|
|
|
|
#################################################
|
|
# Determine the type of `push` and `version`
|
|
#################################################
|
|
|
|
# Version flags to embed in the binaries
|
|
VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
|
|
VERSION := $(shell echo $(VERSION) | sed 's/^v//')
|
|
|
|
# If TRAVIS_TAG is set then we know this ref has been tagged.
|
|
ifdef TRAVIS_TAG
|
|
PUSHTYPE=release
|
|
else
|
|
PUSHTYPE=master
|
|
endif
|
|
|
|
#########################################
|
|
# Build
|
|
#########################################
|
|
|
|
DATE := $(shell date -u '+%Y-%m-%d %H:%M UTC')
|
|
LDFLAGS := -ldflags='-w -X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"'
|
|
GOFLAGS := CGO_ENABLED=0
|
|
|
|
build: $(PREFIX)bin/$(BINNAME)
|
|
@echo "Build Complete!"
|
|
|
|
$(PREFIX)bin/$(BINNAME): vendor $(call rwildcard,*.go)
|
|
$Q mkdir -p $(@D)
|
|
$Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o $(PREFIX)bin/$(BINNAME) $(LDFLAGS) $(PKG)
|
|
|
|
# Target for building without calling dep ensure
|
|
simple:
|
|
$Q mkdir -p bin/
|
|
$Q $(GOOS_OVERRIDE) $(GOFLAGS) go build -v -o bin/$(BINNAME) $(LDFLAGS) $(PKG)
|
|
@echo "Build Complete!"
|
|
|
|
.PHONY: build simple
|
|
|
|
#########################################
|
|
# Go generate
|
|
#########################################
|
|
|
|
generate:
|
|
$Q go generate ./...
|
|
|
|
.PHONY: generate
|
|
|
|
#########################################
|
|
# Test
|
|
#########################################
|
|
test:
|
|
$Q $(GOFLAGS) go test -short -coverprofile=coverage.out ./...
|
|
|
|
vtest:
|
|
$(Q)for d in $$(go list ./... | grep -v vendor); do \
|
|
echo -e "TESTS FOR: for \033[0;35m$$d\033[0m"; \
|
|
$(GOFLAGS) go test -v -bench=. -run=. -short -coverprofile=vcoverage.out $$d; \
|
|
out=$$?; \
|
|
if [[ $$out -ne 0 ]]; then ret=$$out; fi;\
|
|
rm -f profile.coverage.out; \
|
|
done; exit $$ret;
|
|
|
|
.PHONY: test vtest
|
|
|
|
integrate: integration
|
|
|
|
integration: bin/$(BINNAME)
|
|
$Q $(GOFLAGS) go test -tags=integration ./integration/...
|
|
|
|
.PHONY: integrate integration
|
|
|
|
#########################################
|
|
# Linting
|
|
#########################################
|
|
|
|
LINTERS=\
|
|
gofmt \
|
|
golint \
|
|
vet \
|
|
misspell \
|
|
ineffassign \
|
|
deadcode
|
|
|
|
$(patsubst %,%-bin,$(filter-out gofmt vet,$(LINTERS))): %-bin: vendor/bin/%
|
|
gofmt-bin vet-bin:
|
|
|
|
$(LINTERS): %: vendor/bin/gometalinter %-bin vendor
|
|
$Q PATH=`pwd`/vendor/bin:$$PATH gometalinter --tests --disable-all --vendor \
|
|
--deadline=5m -s data -s pkg --enable $@ ./...
|
|
fmt:
|
|
$Q gofmt -l -w $(SRC)
|
|
|
|
lint: $(LINTERS)
|
|
|
|
.PHONY: $(LINTERS) lint fmt
|
|
|
|
#########################################
|
|
# Install
|
|
#########################################
|
|
|
|
INSTALL_PREFIX?=/usr/
|
|
|
|
install: $(PREFIX)bin/$(BINNAME)
|
|
$Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
|
|
|
|
uninstall:
|
|
$Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
|
|
|
|
.PHONY: install uninstall
|
|
|
|
#########################################
|
|
# Debian
|
|
#########################################
|
|
|
|
changelog:
|
|
$Q echo "step-cli ($(VERSION)) unstable; urgency=medium" > debian/changelog
|
|
$Q echo >> debian/changelog
|
|
$Q echo " * See https://github.com/smallstep/cli/releases" >> debian/changelog
|
|
$Q echo >> debian/changelog
|
|
$Q echo " -- Smallstep Labs, Inc. <techadmin@smallstep.com> $(shell date -uR)" >> debian/changelog
|
|
|
|
debian: changelog
|
|
$Q set -e; mkdir -p $(RELEASE); \
|
|
OUTPUT=../step-cli_*.deb; \
|
|
rm -f $$OUTPUT; \
|
|
dpkg-buildpackage -b -rfakeroot -us -uc && cp $$OUTPUT $(RELEASE)/
|
|
|
|
distclean: clean
|
|
|
|
.PHONY: changelog debian distclean
|
|
|
|
#################################################
|
|
# Build statically compiled step binary for various operating systems
|
|
#################################################
|
|
|
|
BINARY_OUTPUT=$(OUTPUT_ROOT)binary/
|
|
BUNDLE_MAKE=v=$v GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2)' PREFIX=$(3) make $(3)bin/step
|
|
RELEASE=./.travis-releases
|
|
|
|
binary-linux:
|
|
$(call BUNDLE_MAKE,linux,amd64,$(BINARY_OUTPUT)linux/)
|
|
|
|
binary-darwin:
|
|
$(call BUNDLE_MAKE,darwin,amd64,$(BINARY_OUTPUT)darwin/)
|
|
|
|
define BUNDLE
|
|
$(q)set -e; BUNDLE_DIR=$(BINARY_OUTPUT)$(1)/bundle; \
|
|
stepName=step_$(2); \
|
|
mkdir -p $$BUNDLE_DIR $(RELEASE); \
|
|
TMP=$$(mktemp -d $$BUNDLE_DIR/tmp.XXXX); \
|
|
trap "rm -rf $$TMP" EXIT INT QUIT TERM; \
|
|
newdir=$$TMP/$$stepName; \
|
|
mkdir -p $$newdir/bin; \
|
|
cp $(BINARY_OUTPUT)$(1)/bin/step $$newdir/bin/; \
|
|
cp README.md $$newdir/; \
|
|
NEW_BUNDLE=$(RELEASE)/step_$(2)_$(1)_$(3).tar.gz; \
|
|
rm -f $$NEW_BUNDLE; \
|
|
tar -zcvf $$NEW_BUNDLE -C $$TMP $$stepName;
|
|
endef
|
|
|
|
define BUNDLE_BREW
|
|
$(q)set -e; BREW_DIR=$(OUTPUT_ROOT)brew; \
|
|
mkdir -p $$BREW_DIR $(RELEASE); \
|
|
TMP=$$(mktemp -d $$BREW_DIR/tmp.XXXX); \
|
|
trap "rm -rf $$TMP" EXIT INT QUIT TERM; \
|
|
NAME=brew_step_$(VERSION); \
|
|
TAR_DIR=$$TMP/$$NAME; \
|
|
mkdir -p $$TAR_DIR; \
|
|
git clone https://github.com/smallstep/cli.git $$TAR_DIR/cli; \
|
|
git --git-dir="$$TAR_DIR/cli/.git" --work-tree="$$TAR_DIR/cli" checkout v$(VERSION); \
|
|
CERT_VERSION=$$(cat .COMPONENT_VERSIONS | grep "certificates" | tr -d "\r\n" | awk '{printf $$2}'); \
|
|
git clone https://github.com/smallstep/certificates.git $$TAR_DIR/certificates; \
|
|
git --git-dir="$$TAR_DIR/certificates/.git" --work-tree="$$TAR_DIR/certificates" checkout $$CERT_VERSION; \
|
|
BREW_TAR=$(RELEASE)/$$NAME.tar.gz; \
|
|
rm -f $$BREW_TAR; \
|
|
tar -zcvf $$BREW_TAR -C $$TMP $$NAME;
|
|
endef
|
|
|
|
bundle-linux: binary-linux
|
|
$(call BUNDLE,linux,$(VERSION),amd64)
|
|
|
|
bundle-darwin: binary-darwin
|
|
$(call BUNDLE,darwin,$(VERSION),amd64)
|
|
|
|
brew:
|
|
$(call BUNDLE_BREW)
|
|
|
|
.PHONY: binary-linux binary-darwin bundle-linux bundle-darwin brew
|
|
|
|
#################################################
|
|
# Targets for creating OS specific artifacts
|
|
#################################################
|
|
|
|
artifacts-linux-tag: bundle-linux debian
|
|
|
|
artifacts-darwin-tag: bundle-darwin brew
|
|
|
|
artifacts-tag: artifacts-linux-tag artifacts-darwin-tag
|
|
|
|
.PHONY: artifacts-linux-tag artifacts-darwin-tag artifacts-tag
|
|
|
|
#################################################
|
|
# Targets for creating step artifacts
|
|
#################################################
|
|
|
|
# For all builds that are not tagged
|
|
artifacts-master:
|
|
|
|
# For all builds with a release tag
|
|
artifacts-release: artifacts-tag
|
|
|
|
# This command is called by travis directly *after* a successful build
|
|
artifacts: artifacts-$(PUSHTYPE) docker-$(PUSHTYPE)
|
|
|
|
.PHONY: artifacts-master artifacts-release artifacts
|
|
|
|
#########################################
|
|
# Clean
|
|
#########################################
|
|
|
|
clean:
|
|
@echo "You will need to run 'make bootstrap' or 'dep ensure' directly to re-download any dependencies."
|
|
$Q rm -rf vendor
|
|
ifneq ($(BINNAME),"")
|
|
$Q rm -f bin/$(BINNAME)
|
|
endif
|
|
|
|
.PHONY: clean
|