2018-11-01 04:36:01 +00:00
|
|
|
PKG?=github.com/smallstep/certificates/cmd/step-ca
|
2018-10-05 21:48:36 +00:00
|
|
|
BINNAME?=step-ca
|
|
|
|
|
|
|
|
# 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 ?=
|
2018-11-15 01:53:17 +00:00
|
|
|
OUTPUT_ROOT=output/
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
# Set shell to bash for `echo -e`
|
|
|
|
SHELL := /bin/bash
|
|
|
|
|
2019-02-20 20:45:10 +00:00
|
|
|
all: build test lint
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
# Bootstrapping
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
bootstra%:
|
|
|
|
$Q which dep || go get github.com/golang/dep/cmd/dep
|
|
|
|
$Q dep ensure
|
2019-09-12 23:40:32 +00:00
|
|
|
$Q GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.18.0
|
2019-08-27 23:39:48 +00:00
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
vendor: Gopkg.lock
|
|
|
|
$Q dep ensure
|
|
|
|
|
|
|
|
define VENDOR_BIN_TMPL
|
|
|
|
vendor/bin/$(notdir $(1)): vendor
|
|
|
|
$Q go build -o $$@ ./vendor/$(1)
|
|
|
|
VENDOR_BINS += vendor/bin/$(notdir $(1))
|
|
|
|
endef
|
|
|
|
|
|
|
|
.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")
|
2019-02-20 20:45:10 +00:00
|
|
|
# If we are not in an active git dir then try reading the version from .VERSION.
|
|
|
|
# .VERSION contains a slug populated by `git archive`.
|
|
|
|
VERSION := $(or $(VERSION),$(shell ./.version.sh .VERSION))
|
2018-10-05 21:48:36 +00:00
|
|
|
VERSION := $(shell echo $(VERSION) | sed 's/^v//')
|
2019-03-27 18:35:17 +00:00
|
|
|
NOT_RC := $(shell echo $(VERSION) | grep -v -e -rc)
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
# If TRAVIS_TAG is set then we know this ref has been tagged.
|
|
|
|
ifdef TRAVIS_TAG
|
2019-03-27 18:35:17 +00:00
|
|
|
ifeq ($(NOT_RC),)
|
|
|
|
PUSHTYPE=release-candidate
|
|
|
|
else
|
|
|
|
PUSHTYPE=release
|
|
|
|
endif
|
2018-10-05 21:48:36 +00:00
|
|
|
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:
|
2018-11-03 06:19:56 +00:00
|
|
|
$Q $(GOFLAGS) go test -short -coverprofile=coverage.out ./...
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
vtest:
|
|
|
|
$(Q)for d in $$(go list ./... | grep -v vendor); do \
|
|
|
|
echo -e "TESTS FOR: for \033[0;35m$$d\033[0m"; \
|
2019-02-20 20:45:10 +00:00
|
|
|
$(GOFLAGS) go test -v -bench=. -run=. -short -coverprofile=vcoverage.out $$d; \
|
2018-10-05 21:48:36 +00:00
|
|
|
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
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
fmt:
|
|
|
|
$Q gofmt -l -w $(SRC)
|
|
|
|
|
2019-08-27 23:39:48 +00:00
|
|
|
lint:
|
|
|
|
$Q LOG_LEVEL=error golangci-lint run
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
.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
|
|
|
|
|
2019-02-20 20:45:10 +00:00
|
|
|
#########################################
|
|
|
|
# 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
|
|
|
|
|
2018-11-15 01:53:17 +00:00
|
|
|
#########################################
|
|
|
|
# Building Docker Image
|
|
|
|
#
|
|
|
|
# Builds a dockerfile for step by building a linux version of the step-cli and
|
|
|
|
# then copying the specific binary when building the container.
|
|
|
|
#
|
|
|
|
# This ensures the container is as small as possible without having to deal
|
|
|
|
# with getting access to private repositories inside the container during build
|
|
|
|
# time.
|
|
|
|
#########################################
|
|
|
|
|
|
|
|
# XXX We put the output for the build in 'output' so we don't mess with how we
|
|
|
|
# do rule overriding from the base Makefile (if you name it 'build' it messes up
|
|
|
|
# the wildcarding).
|
|
|
|
DOCKER_OUTPUT=$(OUTPUT_ROOT)docker/
|
|
|
|
|
|
|
|
DOCKER_MAKE=V=$V GOOS_OVERRIDE='GOOS=linux GOARCH=amd64' PREFIX=$(1) make $(1)bin/$(2)
|
|
|
|
DOCKER_BUILD=$Q docker build -t smallstep/$(1):latest -f docker/$(2) --build-arg BINPATH=$(DOCKER_OUTPUT)bin/$(1) .
|
|
|
|
|
|
|
|
docker: docker-make docker/Dockerfile.step-ca
|
|
|
|
$(call DOCKER_BUILD,step-ca,Dockerfile.step-ca)
|
|
|
|
|
|
|
|
docker-make:
|
|
|
|
mkdir -p $(DOCKER_OUTPUT)
|
|
|
|
$(call DOCKER_MAKE,$(DOCKER_OUTPUT),step-ca)
|
|
|
|
|
|
|
|
.PHONY: docker docker-make
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Releasing Docker Images
|
|
|
|
#
|
|
|
|
# Using the docker build infrastructure, this section is responsible for
|
|
|
|
# logging into docker hub and pushing the built docker containers up with the
|
|
|
|
# appropriate tags.
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
DOCKER_TAG=docker tag smallstep/$(1):latest smallstep/$(1):$(2)
|
|
|
|
DOCKER_PUSH=docker push smallstep/$(1):$(2)
|
|
|
|
|
|
|
|
docker-tag:
|
|
|
|
$(call DOCKER_TAG,step-ca,$(VERSION))
|
|
|
|
|
|
|
|
docker-push-tag: docker-tag
|
|
|
|
$(call DOCKER_PUSH,step-ca,$(VERSION))
|
|
|
|
|
2019-03-27 18:35:17 +00:00
|
|
|
docker-push-tag-latest:
|
|
|
|
$(call DOCKER_PUSH,step-ca,latest)
|
|
|
|
|
2018-11-15 01:53:17 +00:00
|
|
|
# Rely on DOCKER_USERNAME and DOCKER_PASSWORD being set inside the CI or
|
|
|
|
# equivalent environment
|
|
|
|
docker-login:
|
|
|
|
$Q docker login -u="$(DOCKER_USERNAME)" -p="$(DOCKER_PASSWORD)"
|
|
|
|
|
2019-03-27 18:35:17 +00:00
|
|
|
.PHONY: docker-login docker-tag docker-push-tag docker-push-tag-latest
|
2018-11-15 01:53:17 +00:00
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Targets for pushing the docker images
|
|
|
|
#################################################
|
|
|
|
|
2019-03-27 19:02:18 +00:00
|
|
|
# For all builds we build the docker container
|
2018-11-15 01:53:17 +00:00
|
|
|
docker-master: docker
|
|
|
|
|
2019-03-27 18:35:17 +00:00
|
|
|
# For all builds with a release candidate tag
|
|
|
|
docker-release-candidate: docker-master docker-login docker-push-tag
|
2018-11-15 01:53:17 +00:00
|
|
|
|
2019-03-27 18:35:17 +00:00
|
|
|
# For all builds with a release tag
|
|
|
|
docker-release: docker-release-candidate docker-push-tag-latest
|
|
|
|
|
|
|
|
.PHONY: docker-master docker-release-candidate docker-release
|
2018-11-15 01:53:17 +00:00
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
#########################################
|
|
|
|
# Debian
|
|
|
|
#########################################
|
|
|
|
|
2018-11-02 22:08:50 +00:00
|
|
|
changelog:
|
|
|
|
$Q echo "step-certificates ($(VERSION)) unstable; urgency=medium" > debian/changelog
|
|
|
|
$Q echo >> debian/changelog
|
|
|
|
$Q echo " * See https://github.com/smallstep/certificates/releases" >> debian/changelog
|
|
|
|
$Q echo >> debian/changelog
|
|
|
|
$Q echo " -- Smallstep Labs, Inc. <techadmin@smallstep.com> $(shell date -uR)" >> debian/changelog
|
|
|
|
|
|
|
|
debian: changelog
|
2018-10-05 21:48:36 +00:00
|
|
|
$Q mkdir -p $(RELEASE); \
|
2018-11-02 22:08:50 +00:00
|
|
|
OUTPUT=../step-certificates_*.deb; \
|
2018-10-05 21:48:36 +00:00
|
|
|
rm $$OUTPUT; \
|
|
|
|
dpkg-buildpackage -b -rfakeroot -us -uc && cp $$OUTPUT $(RELEASE)/
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
|
2018-11-02 22:08:50 +00:00
|
|
|
.PHONY: changelog debian distclean
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Build statically compiled step binary for various operating systems
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
BINARY_OUTPUT=$(OUTPUT_ROOT)binary/
|
2018-11-03 06:52:32 +00:00
|
|
|
BUNDLE_MAKE=v=$v GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2)' PREFIX=$(3) make $(3)bin/$(BINNAME)
|
2018-10-05 21:48:36 +00:00
|
|
|
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)BUNDLE_DIR=$(BINARY_OUTPUT)$(1)/bundle; \
|
2018-11-02 22:08:50 +00:00
|
|
|
stepName=step-certificates_$(2); \
|
2018-10-05 21:48:36 +00:00
|
|
|
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; \
|
2018-11-03 06:52:32 +00:00
|
|
|
cp $(BINARY_OUTPUT)$(1)/bin/$(BINNAME) $$newdir/bin/; \
|
2018-10-05 21:48:36 +00:00
|
|
|
cp README.md $$newdir/; \
|
2018-11-02 22:08:50 +00:00
|
|
|
NEW_BUNDLE=$(RELEASE)/step-certificates_$(2)_$(1)_$(3).tar.gz; \
|
2018-10-05 21:48:36 +00:00
|
|
|
rm -f $$NEW_BUNDLE; \
|
|
|
|
tar -zcvf $$NEW_BUNDLE -C $$TMP $$stepName;
|
|
|
|
endef
|
|
|
|
|
|
|
|
bundle-linux: binary-linux
|
|
|
|
$(call BUNDLE,linux,$(VERSION),amd64)
|
|
|
|
|
|
|
|
bundle-darwin: binary-darwin
|
|
|
|
$(call BUNDLE,darwin,$(VERSION),amd64)
|
|
|
|
|
|
|
|
.PHONY: binary-linux binary-darwin bundle-linux bundle-darwin
|
|
|
|
|
|
|
|
#################################################
|
2019-03-29 19:37:58 +00:00
|
|
|
# Targets for creating OS specific artifacts and archives
|
2018-10-05 21:48:36 +00:00
|
|
|
#################################################
|
|
|
|
|
|
|
|
artifacts-linux-tag: bundle-linux debian
|
|
|
|
|
|
|
|
artifacts-darwin-tag: bundle-darwin
|
|
|
|
|
2019-03-29 19:37:58 +00:00
|
|
|
artifacts-archive-tag:
|
|
|
|
$Q mkdir -p $(RELEASE)
|
2019-04-05 18:38:43 +00:00
|
|
|
$Q git archive v$(VERSION) | gzip > $(RELEASE)/step-certificates_$(VERSION).tar.gz
|
2018-10-05 21:48:36 +00:00
|
|
|
|
2019-03-29 19:53:09 +00:00
|
|
|
artifacts-tag: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag
|
2018-10-05 21:48:36 +00:00
|
|
|
|
2019-03-29 19:37:58 +00:00
|
|
|
.PHONY: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag artifacts-tag
|
2018-10-05 21:48:36 +00:00
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Targets for creating step artifacts
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
# For all builds that are not tagged
|
|
|
|
artifacts-master:
|
|
|
|
|
2019-03-29 19:37:58 +00:00
|
|
|
# For all builds with a release-candidate (-rc) tag
|
2019-03-27 18:35:17 +00:00
|
|
|
artifacts-release-candidate: artifacts-tag
|
|
|
|
|
2018-10-05 21:48:36 +00:00
|
|
|
# For all builds with a release tag
|
|
|
|
artifacts-release: artifacts-tag
|
|
|
|
|
|
|
|
# This command is called by travis directly *after* a successful build
|
2018-11-15 01:53:17 +00:00
|
|
|
artifacts: artifacts-$(PUSHTYPE) docker-$(PUSHTYPE)
|
2018-10-05 21:48:36 +00:00
|
|
|
|
2019-03-27 18:35:17 +00:00
|
|
|
.PHONY: artifacts-master artifacts-release-candidate artifacts-release artifacts
|