This repository has been archived by the owner on Mar 27, 2021. It is now read-only.
forked from TritonDataCenter/containerpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
124 lines (101 loc) · 3.86 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
MAKEFLAGS += --warn-undefined-variables
SHELL := /bin/bash
.SHELLFLAGS := -o pipefail -euc
.DEFAULT_GOAL := build
.PHONY: clean test integration consul etcd run-consul run-etcd example example-consul example-etcd ship dockerfile docker cover lint
IMPORT_PATH := github.com/joyent/containerpilot
VERSION ?= dev-build-not-for-release
LDFLAGS := -X ${IMPORT_PATH}/core.GitHash='$(shell git rev-parse --short HEAD)' -X ${IMPORT_PATH}/core.Version='${VERSION}'
ROOT := $(shell pwd)
COMPOSE_PREFIX_ETCD := exetcd
COMPOSE_PREFIX_CONSUL := exconsul
DOCKERRUN := docker run --rm \
--link containerpilot_consul:consul \
--link containerpilot_etcd:etcd \
-v ${ROOT}/vendor:/go/src \
-v ${ROOT}:/cp/src/${IMPORT_PATH} \
-w /cp/src/${IMPORT_PATH} \
containerpilot_build
DOCKERBUILD := docker run --rm \
-e LDFLAGS="${LDFLAGS}" \
-v ${ROOT}/vendor:/go/src \
-v ${ROOT}:/cp/src/${IMPORT_PATH} \
-w /cp/src/${IMPORT_PATH} \
containerpilot_build
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
docker rm -f containerpilot_etcd > /dev/null 2>&1 || true
./scripts/test.sh clean
# ----------------------------------------------
# docker build
# default top-level target
build: build/containerpilot
build/containerpilot: build/containerpilot_build */*.go vendor
${DOCKERBUILD} 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
# shortcut target for other targets: asserts a
# working test environment
docker: build/containerpilot_build consul etcd
# top-level target for vendoring our packages: godep restore requires
# being in the package directory so we have to run this for each package
vendor: build/containerpilot_build
${DOCKERBUILD} godep restore
# fetch a dependency via go get, vendor it, and then save into the parent
# package's Godeps
# usage DEP=github.com/owner/package make add-dep
add-dep: build/containerpilot_build
docker run --rm \
-e LDFLAGS="${LDFLAGS}" \
-v ${ROOT}:/cp/src/${IMPORT_PATH} \
-w /cp/src/${IMPORT_PATH} \
containerpilot_build \
bash -c "DEP=$(DEP) ./scripts/add_dep.sh"
# ----------------------------------------------
# develop and test
lint: vendor
${DOCKERBUILD} bash ./scripts/lint.sh
# run unit tests and write out test coverage
test: docker vendor
${DOCKERRUN} bash ./scripts/unit_test.sh
cover: docker
mkdir -p cover
${DOCKERRUN} bash ./scripts/cover.sh
# run integration tests
TEST ?= "all"
integration: build
./scripts/test.sh test $(TEST)
# ------ Backends
# Consul Backend
consul:
docker rm -f containerpilot_consul > /dev/null 2>&1 || true
docker run -d -m 256m --name containerpilot_consul \
progrium/consul:latest -server -bootstrap-expect 1 -ui-dir /ui
# Etcd Backend
etcd:
docker rm -f containerpilot_etcd > /dev/null 2>&1 || true
docker run -d -m 256m --name containerpilot_etcd -h etcd quay.io/coreos/etcd:v2.0.8 \
-name etcd0 \
-advertise-client-urls http://etcd:2379,http://etcd:4001 \
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
-initial-advertise-peer-urls http://etcd:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster etcd0=http://etcd:2380 \
-initial-cluster-state new
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.