-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
170 lines (137 loc) · 5.59 KB
/
Makefile
File metadata and controls
170 lines (137 loc) · 5.59 KB
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
#
# Deis Makefile
#
ifndef FLEETCTL
FLEETCTL = fleetctl --strict-host-key-checking=false
endif
ifndef FLEETCTL_TUNNEL
$(error You need to set FLEETCTL_TUNNEL to the IP address of a server in the cluster.)
endif
ifndef DEIS_NUM_INSTANCES
DEIS_NUM_INSTANCES = 1
endif
ifndef DEIS_NUM_ROUTERS
DEIS_NUM_ROUTERS = 1
endif
ifndef DEIS_FIRST_ROUTER
DEIS_FIRST_ROUTER = 1
endif
DEIS_LAST_ROUTER = $(shell echo $(DEIS_FIRST_ROUTER)\+$(DEIS_NUM_ROUTERS)\-1 | bc)
# TODO refactor to support non-vagrant installations, since this Makefile
# is now used by the various contrib/ scripts.
define ssh_all
i=1 ; while [ $$i -le $(DEIS_NUM_INSTANCES) ] ; do \
vagrant ssh deis-$$i -c $(1) ; \
i=`expr $$i + 1` ; \
done
endef
define check_for_errors
@if $(FLEETCTL) list-units -no-legend | awk '(($$2 == "launched") && ($$5 == "failed"))' | egrep -q "deis-.+service"; then \
echo "\033[0;31mOne or more services failed! Check which services by running 'make status'\033[0m" ; \
echo "\033[0;31mYou can get detailed output with 'fleetctl status deis-servicename.service'\033[0m" ; \
echo "\033[0;31mThis usually indicates an error with Deis - please open an issue on GitHub or ask for help in IRC\033[0m" ; \
exit 1 ; \
fi
endef
define deis_units
$(shell $(FLEETCTL) list-units -no-legend=true | \
awk '($$2 ~ "$(1)" && ($$4 ~ "$(2)"))' | \
sed -n 's/\(deis-.*\.service\).*/\1/p' | tr '\n' ' ')
endef
define echo_cyan
@echo "\033[0;36m$(subst ",,$(1))\033[0m"
endef
define echo_yellow
@echo "\033[0;33m$(subst ",,$(1))\033[0m"
endef
# TODO: re-evaluate the start order now that we're on fleet 0.3.2.
# due to scheduling problems with fleet 0.2.0, start order of components
# is fragile. hopefully this can be changed soon...
COMPONENTS=builder cache controller database logger registry
ALL_COMPONENTS=$(COMPONENTS) router
START_COMPONENTS=registry logger cache database
ALL_UNITS = $(foreach C,$(COMPONENTS),$(wildcard $(C)/systemd/*))
START_UNITS = $(foreach C,$(START_COMPONENTS),$(wildcard $(C)/systemd/*))
ROUTER_UNITS = $(shell seq -f "deis-router.%g.service" -s " " $(DEIS_FIRST_ROUTER) 1 $(DEIS_LAST_ROUTER))
all: build run
build:
$(call ssh_all,'cd share && for c in $(ALL_COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done')
check-fleet:
@LOCAL_VERSION=`$(FLEETCTL) -version`; \
REMOTE_VERSION=`ssh -o StrictHostKeyChecking=no core@$(subst :, -p ,$(FLEETCTL_TUNNEL)) fleetctl -version`; \
if [ "$$LOCAL_VERSION" != "$$REMOTE_VERSION" ]; then \
echo "Your fleetctl client version should match the server. Local version: $$LOCAL_VERSION, server version: $$REMOTE_VERSION. Uninstall your local version and install the latest build from https://github.com/coreos/fleet/releases"; exit 1; \
fi
clean: uninstall
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rm -f deis-$$c; done')
full-clean: clean
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rmi deis-$$c; done')
install: check-fleet install-routers
$(FLEETCTL) load $(START_UNITS)
$(FLEETCTL) load controller/systemd/*
$(FLEETCTL) load builder/systemd/*
install-routers: check-fleet
@$(foreach R, $(ROUTER_UNITS), \
cp router/systemd/deis-router.service ./$(R) ; \
$(FLEETCTL) load ./$(R) ; \
rm -f ./$(R) ; \
)
pull:
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker pull deis/$$c; done')
$(call ssh_all,'docker pull deis/slugrunner')
restart: stop start
run: install start
start: check-fleet start-warning start-routers
@# registry logger cache database
$(call echo_yellow,"Waiting for deis-registry to start...")
$(FLEETCTL) start -no-block $(START_UNITS)
@until $(FLEETCTL) list-units | egrep -q "deis-registry.+(running)"; \
do sleep 2; \
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \
grep "deis-registry" | awk '{printf "%-10s (%s) \r", $$4, $$5}'; \
sleep 8; \
done
$(call check_for_errors)
@# controller
$(call echo_yellow,"Waiting for deis-controller to start...")
$(FLEETCTL) start -no-block controller/systemd/*
@until $(FLEETCTL) list-units | egrep -q "deis-controller.+(running)"; \
do sleep 2; \
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \
grep "deis-controller" | awk '{printf "%-10s (%s) \r", $$4, $$5}'; \
sleep 8; \
done
$(call check_for_errors)
@# builder
$(call echo_yellow,"Waiting for deis-builder to start...")
$(FLEETCTL) start -no-block builder/systemd/*
@until $(FLEETCTL) list-units | egrep -q "deis-builder.+(running)"; \
do sleep 2; \
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \
grep "deis-builder" | awk '{printf "%-10s (%s) \r", $$4, $$5}'; \
sleep 8; \
done
$(call check_for_errors)
$(call echo_yellow,"Your Deis cluster is ready to go! Continue following the README to login and use Deis.")
start-routers: check-fleet start-warning
$(call echo_yellow,"Waiting for 1 of $(DEIS_NUM_ROUTERS) deis-routers to start...")
$(foreach R,$(ROUTER_UNITS),$(FLEETCTL) start -no-block $(R);)
@until $(FLEETCTL) list-units | egrep -q "deis-router.+(running)"; \
do sleep 2; \
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \
grep "deis-router" | head -n 1 | \
awk '{printf "%-10s (%s) \r", $$4, $$5}'; \
sleep 8; \
done
$(call check_for_errors)
start-warning:
$(call echo_cyan,"Deis components may take a long time to start the first time they are initialized.")
status: check-fleet
$(FLEETCTL) list-units
stop: check-fleet
$(FLEETCTL) stop -block-attempts=600 $(strip $(call deis_units,launched,active))
tests:
cd test && bundle install && bundle exec rake
uninstall: check-fleet stop
$(FLEETCTL) unload $(call deis_units,launched,.)
$(FLEETCTL) destroy $(strip $(call deis_units,.,.))