forked from TritonDataCenter/containerpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
177 lines (146 loc) · 5.93 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -euc
.DEFAULT_GOAL := build
.PHONY: clean test integration consul ship dockerfile docker cover lint local vendor dep-* tools kirby
IMPORT_PATH := github.com/joyent/containerpilot
VERSION ?= dev-build-not-for-release
LDFLAGS := -X ${IMPORT_PATH}/version.GitHash=$(shell git rev-parse --short HEAD) -X ${IMPORT_PATH}/version.Version=${VERSION}
ROOT := $(shell pwd)
RUNNER := -v ${ROOT}:/go/src/${IMPORT_PATH} -w /go/src/${IMPORT_PATH} containerpilot_build
docker := docker run --disable-content-trust --rm -e LDFLAGS="${LDFLAGS}" $(RUNNER)
export PATH :=$(PATH):$(GOPATH)/bin
# flags for local development
GOPATH ?= $(shell go env GOPATH)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED := 0
GOEXPERIMENT := framepointer
CONSUL_VERSION := 1.6.3
## display this help message
help:
@echo -e "\033[32m"
@echo "Targets in this Makefile build and test ContainerPilot in a build container in"
@echo "Docker. For testing (only), use the 'local' prefix target to run targets directly"
@echo "on your workstation (ex. 'make local test'). You will need to have its GOPATH set"
@echo "and have already run 'make tools'. Set GOOS=linux to build binaries for Docker."
@echo "Do not use 'make local' for building binaries for public release!"
@echo
@awk '/^##.*$$/,/[a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}' | sort
# ----------------------------------------------
# building
## build the ContainerPilot binary
build: build/containerpilot
build/containerpilot: build/containerpilot_build */*/*.go */*.go */*/*.go *.go
$(docker) go build -o build/containerpilot -ldflags "$(LDFLAGS)"
@rm -rf src || true
# builds the builder container
build/containerpilot_build:
mkdir -p ${ROOT}/build
docker rmi -f containerpilot_build > /dev/null 2>&1 || true
docker build -t containerpilot_build ${ROOT}
docker inspect -f "{{ .ID }}" containerpilot_build > build/containerpilot_build
# Before packaging always `make clean build test integration`!
## tag and package ContainerPilot for release; `VERSION=make release`
release: build
mkdir -p release
git tag $(VERSION)
git push joyent --tags
cd build && tar -czf ../release/containerpilot-$(VERSION).tar.gz containerpilot
@echo
@cd release && sha1sum containerpilot-$(VERSION).tar.gz
@cd release && sha1sum containerpilot-$(VERSION).tar.gz > containerpilot-$(VERSION).sha1.txt
@echo Upload files in release/ directory to GitHub release.
## remove build/test artifacts, test fixtures, and vendor directories
clean:
rm -rf build release cover vendor
docker rmi -f containerpilot_build > /dev/null 2>&1 || true
docker rm -f containerpilot_consul > /dev/null 2>&1 || true
./scripts/test.sh clean
# ----------------------------------------------
# dependencies
# NOTE: glide will be replaced with `dep` when its production-ready
# ref https://github.com/golang/dep
## install any changed packages in go.mod and go.sum
vendor: build/update
build/update: build/containerpilot_build go.mod
$(docker) go get -u ./...
@echo date > build/update
## install all dependencies
dep-install:
$(docker) go get -u ./...
@echo date > build/update
# Deprecated with go modules:
# usage DEP=github.com/owner/package make dep-add
## fetch a dependency and vendor it via `glide`
dep-add: build/containerpilot_build
$(docker) bash -c "DEP=$(DEP) ./scripts/add_dep.sh"
# run 'GOOS=darwin make tools' if you're installing on MacOS
## set up local dev environment
tools:
@go version | grep 1.13 || (echo 'WARNING: go1.13 should be installed!')
@$(if $(value GOPATH),, $(error 'GOPATH not set'))
go get golang.org/x/lint/golint
curl --fail -Lso consul.zip "https://releases.hashicorp.com/consul/$(CONSUL_VERSION)/consul_$(CONSUL_VERSION)_$(GOOS)_$(GOARCH).zip"
unzip consul.zip -d "$(GOPATH)/bin"
rm consul.zip
# ----------------------------------------------
# develop and test
## print environment info about this dev environment
debug:
@$(if $(value DOCKER_HOST), echo "DOCKER_HOST=$(DOCKER_HOST)", echo 'DOCKER_HOST not set')
@echo CGO_ENABLED=$(CGO_ENABLED)
@echo GO15VENDOREXPERIMENT=$(GO15VENDOREXPERIMENT)
@echo GOARCH=$(GOARCH)
@echo GOEXPERIMENT=$(GOEXPERIMENT)
@echo GOOS=$(GOOS)
@echo GOPATH=$(GOPATH)
@echo IMPORT_PATH=$(IMPORT_PATH)
@echo LDFLAGS="$(LDFLAGS)"
@echo PATH=$(PATH)
@echo ROOT=$(ROOT)
@echo VERSION=$(VERSION)
@echo
@echo docker commands run as:
@echo $(docker)
## prefix before other make targets to run in your local dev environment
local: | quiet
@$(eval docker= )
quiet: # this is silly but shuts up 'Nothing to be done for `local`'
@:
## run `go lint` and other code quality tools
lint:
$(docker) bash ./scripts/lint.sh
## run unit tests
test: build/containerpilot_build
$(docker) bash ./scripts/unit_test.sh
## run unit tests and write out HTML file of test coverage
cover: build/containerpilot_build
mkdir -p cover
$(docker) bash ./scripts/cover.sh
## generate stringer code
generate:
go install github.com/joyent/containerpilot/events
cd events && stringer -type EventCode
# fix this up for making it pass linting
sed -i '.bak' 's/_EventCode_/eventCode/g' ./events/eventcode_string.go
@rm -f ./events/eventcode_string.go.bak
TEST ?= "all"
## run integration tests; filter with `TEST=testname make integration`
integration: build
./scripts/test.sh test $(TEST)
## stand up a Consul server in development mode in Docker
consul:
docker rm -f containerpilot_consul > /dev/null 2>&1 || true
docker run -d -m 256m -p 8500:8500 --name containerpilot_consul \
consul:latest agent -dev -client 0.0.0.0 -bind=0.0.0.0
## build documentation for Kirby
kirby: build/docs
## preview the Kirby documentation
kirby-preview: build/docs
docker run --rm -it -p 80:80 \
-v ${ROOT}/build/docs:/var/www/html/content/1-containerpilot/1-docs/ \
joyent/kirby-preview-base:latest
build/docs: docs/* scripts/docs.py
rm -rf build/docs
./scripts/docs.py