Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
feat(*): use templated
Browse files Browse the repository at this point in the history
  • Loading branch information
carmstrong committed Jul 10, 2014
1 parent 46bca09 commit 8498d26
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 45 deletions.
59 changes: 24 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,48 @@ define deis_units
sed -n 's/\(deis-.*\.service\).*/\1/p' | tr '\n' ' ')
endef

# TODO: re-evaluate the fragile start order
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/*.service))
START_UNITS = $(foreach C,$(START_COMPONENTS),$(wildcard $(C)/systemd/*.service))
define install_data_container
$(shell UNIT=`basename $$1` ; \
if [[ `$(FLEETCTL) list-units | grep $$UNIT` ]]; then \
echo $$UNIT already loaded. Skipping... ; \
else \
UNIT_NAME=`echo $$1 | sed "s/BOOTID/$$2/g"`; \
$(FLEETCTL) load $$UNIT_NAME ; \
fi ; \
)
endef

DATA_CONTAINER_TEMPLATES=builder/systemd/deis-builder-data.service database/systemd/deis-database-data.service logger/systemd/deis-logger-data.service registry/systemd/deis-registry-data.service
# TODO: re-evaluate the fragile start order
COMPONENTS=builder cache controller database logger registry router
START_UNITS = registry/systemd/deis-registry.service logger/systemd/deis-logger.service cache/systemd/deis-cache.service database/systemd/deis-database.service
DATA_CONTAINER_TEMPLATES=builder/systemd/deis-builder-data@BOOTID.service database/systemd/deis-database-data@BOOTID.service logger/systemd/deis-logger-data@BOOTID.service registry/systemd/deis-registry-data@BOOTID.service

all: build run

build: rsync
$(call ssh_all,'cd share && for c in $(ALL_COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done')
$(call ssh_all,'cd share && for c in $(COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done')

clean: uninstall
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rm -f deis-$$c; done')
$(call ssh_all,'for c in $(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')
$(call ssh_all,'for c in $(COMPONENTS); do docker rmi deis-$$c; done')

install: check-fleet install-routers install-data-containers
$(FLEETCTL) load $(START_UNITS)
$(FLEETCTL) load controller/systemd/*.service
$(FLEETCTL) load builder/systemd/*.service
$(FLEETCTL) load controller/systemd/deis-controller.service
$(FLEETCTL) load builder/systemd/deis-builder.service

install-data-containers: check-fleet
@$(foreach T, $(DATA_CONTAINER_TEMPLATES), \
UNIT=`basename $(T)` ; \
if [[ `$(FLEETCTL) list-units | grep $$UNIT` ]]; then \
echo $$UNIT already loaded. Skipping... ; \
else \
cp $(T).template . ; \
NEW_FILENAME=`ls *.template | sed 's/\.template//g'`; \
mv *.template $$NEW_FILENAME ; \
MACHINE_ID=`$(FLEETCTL) list-machines --no-legend --full list-machines | awk 'BEGIN { OFS="\t"; srand() } { print rand(), $$1 }' | sort -n | cut -f2- | head -1` ; \
sed -e "s/CHANGEME/$$MACHINE_ID/" $$NEW_FILENAME > $$NEW_FILENAME.bak ; \
rm -f $$NEW_FILENAME ; \
mv $$NEW_FILENAME.bak $$NEW_FILENAME ; \
$(FLEETCTL) load $$NEW_FILENAME ; \
rm -f $$NEW_FILENAME ; \
fi ; \
)
$(call install_data_container,)

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:latest; done')
$(call ssh_all,'for c in $(COMPONENTS); do docker pull deis/$$c:latest; done')
$(call ssh_all,'docker pull deis/slugrunner:latest')

restart: stop start
Expand All @@ -95,7 +84,7 @@ start: check-fleet start-warning start-routers

@# controller
$(call echo_yellow,"Waiting for deis-controller to start...")
$(FLEETCTL) start -no-block controller/systemd/*
$(FLEETCTL) start -no-block controller/systemd/deis-controller.service
@until $(FLEETCTL) list-units | egrep -q "deis-controller.+(running|failed)"; \
do sleep 2; \
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \
Expand All @@ -106,7 +95,7 @@ start: check-fleet start-warning start-routers

@# builder
$(call echo_yellow,"Waiting for deis-builder to start...")
$(FLEETCTL) start -no-block builder/systemd/*.service
$(FLEETCTL) start -no-block builder/systemd/deis-builder.service
@until $(FLEETCTL) list-units | egrep -q "deis-builder.+(running|failed)"; \
do sleep 2; \
printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) list-units | \
Expand Down Expand Up @@ -141,7 +130,7 @@ stop: check-fleet
test: test-components test-integration

test-components:
@$(foreach C,$(ALL_COMPONENTS), \
@$(foreach C,$(COMPONENTS), \
echo \\nTesting deis/$(C) ; \
$(MAKE) -C $(C) test ; \
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ExecStart=/bin/sh -c "docker inspect deis-builder-data >/dev/null 2>&1 || docker
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineBootID=CHANGEME
X-ConditionMachineBootID=%i
2 changes: 1 addition & 1 deletion builder/systemd/deis-builder.service
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ ExecStartPost=/bin/sh -c "echo 'Waiting for builder on 2223/tcp...' && until cat
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineOf=deis-builder-data.service
X-ConditionMachineOf=deis-builder-data@%i.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ExecStart=/bin/sh -c "docker inspect deis-database-data >/dev/null 2>&1 || docke
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineBootID=CHANGEME
X-ConditionMachineBootID=%i
2 changes: 1 addition & 1 deletion database/systemd/deis-database.service
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ ExecStop=/bin/bash -c "nsenter --pid --uts --mount --ipc --net --target $(docker
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineOf=deis-database-data.service
X-ConditionMachineOf=deis-database-data@%i.service
2 changes: 1 addition & 1 deletion includes.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define echo_yellow
endef

SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
ROUTER_UNITS = $(shell seq -f "deis-router.%g.service" -s " " $(DEIS_FIRST_ROUTER) 1 $(DEIS_LAST_ROUTER))
ROUTER_UNITS = $(shell seq -f "router/systemd/deis-router@%g.service" -s " " $(DEIS_FIRST_ROUTER) 1 $(DEIS_LAST_ROUTER))

check-fleet:
@LOCAL_VERSION=`$(FLEETCTL) -version`; \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ExecStart=/bin/sh -c "docker inspect deis-logger-data >/dev/null 2>&1 || docker
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineBootID=CHANGEME
X-ConditionMachineBootID=%i
2 changes: 1 addition & 1 deletion logger/systemd/deis-logger.service
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ExecStart=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/logger` && docker run
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineOf=deis-logger-data.service
X-ConditionMachineOf=deis-logger-data@%i.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ExecStart=/bin/sh -c "docker inspect deis-registry-data >/dev/null 2>&1 || docke
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineBootID=CHANGEME
X-ConditionMachineBootID=%i
2 changes: 1 addition & 1 deletion registry/systemd/deis-registry.service
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ ExecStartPost=/bin/sh -c "echo 'Waiting for listener on 5000/tcp...' && until ca
WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineOf=deis-registry-data.service
X-ConditionMachineOf=deis-registry-data@%i.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ExecStart=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/router` && docker run
WantedBy=multi-user.target

[X-Fleet]
X-Conflicts=deis-router.*.service
X-Conflicts=deis-router@*.service

0 comments on commit 8498d26

Please sign in to comment.