github.com/blystad/deis@v0.11.0/Makefile (about)

     1  #
     2  # Deis Makefile
     3  #
     4  
     5  include includes.mk
     6  
     7  list-units = list-units --fields unit,state,load,active,sub,desc,machine
     8  
     9  define check_for_errors
    10  	@if $(FLEETCTL) $(list-units) -no-legend | awk '(($$2 == "launched") && ($$5 == "failed"))' | egrep -q "deis-.+service"; then \
    11  		echo "\033[0;31mOne or more services failed! Check which services by running 'make status'\033[0m" ; \
    12  		echo "\033[0;31mYou can get detailed output with 'fleetctl status deis-servicename.service'\033[0m" ; \
    13  		echo "\033[0;31mThis usually indicates an error with Deis - please open an issue on GitHub or ask for help in IRC\033[0m" ; \
    14  		exit 1 ; \
    15  	fi
    16  endef
    17  
    18  define deis_units
    19  	$(shell $(FLEETCTL) $(list-units) -no-legend=true | \
    20  	  awk '($$2 ~ "$(1)" && ($$4 ~ "$(2)"))' | \
    21  	  sed -n 's/\(deis-.*\.service\).*/\1/p' | tr '\n' ' ')
    22  endef
    23  
    24  # TODO: re-evaluate the fragile start order
    25  COMPONENTS=builder cache controller database logger registry
    26  ALL_COMPONENTS=$(COMPONENTS) router
    27  START_COMPONENTS=logger cache database
    28  
    29  ALL_UNITS = $(foreach C,$(COMPONENTS),$(wildcard $(C)/systemd/*.service))
    30  START_UNITS = $(foreach C,$(START_COMPONENTS),$(wildcard $(C)/systemd/*.service))
    31  
    32  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
    33  
    34  all: build run
    35  
    36  build: rsync
    37  	$(call ssh_all,'cd share && for c in $(ALL_COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done')
    38  
    39  clean: uninstall
    40  	$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rm -f deis-$$c; done')
    41  
    42  full-clean: clean
    43  	$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rmi deis-$$c; done')
    44  
    45  install: check-fleet install-routers install-data-containers
    46  	$(FLEETCTL) load $(START_UNITS)
    47  	$(FLEETCTL) load registry/systemd/*.service
    48  	$(FLEETCTL) load controller/systemd/*.service
    49  	$(FLEETCTL) load builder/systemd/*.service
    50  
    51  install-data-containers: check-fleet
    52  	@$(foreach T, $(DATA_CONTAINER_TEMPLATES), \
    53  		UNIT=`basename $(T)` ; \
    54  		EXISTS=`$(FLEETCTL) $(list-units) | grep $$UNIT` ; \
    55  		if [ "$$EXISTS" != "" ]; then \
    56  		  echo $$UNIT already loaded. Skipping... ; \
    57  		else \
    58  			cp $(T).template . ; \
    59  			NEW_FILENAME=`ls *.template | sed 's/\.template//g'`; \
    60  			mv *.template $$NEW_FILENAME ; \
    61  			MACHINE_ID=`$(FLEETCTL) list-machines --no-legend --full | awk 'BEGIN { OFS="\t"; srand() } { print rand(), $$1 }' | sort -n | cut -f2- | head -1` ; \
    62  			sed -e "s/CHANGEME/$$MACHINE_ID/" $$NEW_FILENAME > $$NEW_FILENAME.bak ; \
    63  			rm -f $$NEW_FILENAME ; \
    64  			mv $$NEW_FILENAME.bak $$NEW_FILENAME ; \
    65  			$(FLEETCTL) load $$NEW_FILENAME ; \
    66  			rm -f $$NEW_FILENAME ; \
    67  		fi ; \
    68  	)
    69  
    70  install-routers: check-fleet
    71  	@$(foreach R, $(ROUTER_UNITS), \
    72  		$(FLEETCTL) load router/systemd/$(R) ; \
    73  	)
    74  
    75  pull:
    76  	$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker pull deis/$$c:v0.11.0; done')
    77  	$(call ssh_all,'docker pull deis/slugrunner:latest')
    78  
    79  restart: stop start
    80  
    81  rsync:
    82  	$(call rsync_all)
    83  
    84  run: install start
    85  
    86  start: check-fleet start-warning start-routers
    87  	@# logger cache database
    88  	$(call echo_yellow,"Waiting for deis-cache to start...")
    89  	$(FLEETCTL) start -no-block $(START_UNITS)
    90  	@until $(FLEETCTL) $(list-units) | egrep -q "deis-cache\..+(running|failed)"; \
    91  		do sleep 2; \
    92  			printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) $(list-units) | \
    93  			grep "deis-cache\." | awk '{printf "%-10s (%s)    \r", $$4, $$5}'; \
    94  			sleep 8; \
    95  		done
    96  	$(call check_for_errors)
    97  
    98  	@# registry
    99  	$(call echo_yellow,"Waiting for deis-registry to start...")
   100  	$(FLEETCTL) start -no-block registry/systemd/*.service
   101  	@until $(FLEETCTL) $(list-units) | egrep -q "deis-registry\..+(running|failed)"; \
   102  		do sleep 2; \
   103  			printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) $(list-units) | \
   104  			grep "deis-registry\." | awk '{printf "%-10s (%s)    \r", $$4, $$5}'; \
   105  			sleep 8; \
   106  		done
   107  	$(call check_for_errors)
   108  
   109  	@# controller
   110  	$(call echo_yellow,"Waiting for deis-controller to start...")
   111  	$(FLEETCTL) start -no-block controller/systemd/*.service
   112  	@until $(FLEETCTL) $(list-units) | egrep -q "deis-controller\..+(running|failed)"; \
   113  		do sleep 2; \
   114  			printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) $(list-units) | \
   115  			grep "deis-controller\." | awk '{printf "%-10s (%s)    \r", $$4, $$5}'; \
   116  			sleep 8; \
   117  		done
   118  	$(call check_for_errors)
   119  
   120  	@# builder
   121  	$(call echo_yellow,"Waiting for deis-builder to start...")
   122  	$(FLEETCTL) start -no-block builder/systemd/*.service
   123  	@until $(FLEETCTL) $(list-units) | egrep -q "deis-builder\..+(running|failed)"; \
   124  		do sleep 2; \
   125  			printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) $(list-units) | \
   126  			grep "deis-builder\." | awk '{printf "%-10s (%s)    \r", $$4, $$5}'; \
   127  			sleep 8; \
   128  		done
   129  	$(call check_for_errors)
   130  
   131  	$(call echo_yellow,"Your Deis cluster is ready to go! Continue following the README to login and use Deis.")
   132  
   133  start-routers: check-fleet start-warning
   134  	$(call echo_yellow,"Waiting for 1 of $(DEIS_NUM_ROUTERS) deis-routers to start...")
   135  	$(foreach R,$(ROUTER_UNITS),$(FLEETCTL) start -no-block $(R);)
   136  	@until $(FLEETCTL) $(list-units) | egrep -q "deis-router.+(running)"; \
   137  		do sleep 2; \
   138  			printf "\033[0;33mStatus:\033[0m "; $(FLEETCTL) $(list-units) | \
   139  			grep "deis-router" | head -n 1 | \
   140  			awk '{printf "%-10s (%s)    \r", $$4, $$5}'; \
   141  			sleep 8; \
   142  		done
   143  	$(call check_for_errors)
   144  
   145  start-warning:
   146  	$(call echo_cyan,"Deis components may take a long time to start the first time they are initialized.")
   147  
   148  status: check-fleet
   149  	$(FLEETCTL) $(list-units)
   150  
   151  stop: check-fleet
   152  	$(FLEETCTL) stop -block-attempts=600 $(strip $(call deis_units,launched,active))
   153  
   154  test: test-components test-integration
   155  
   156  test-components:
   157  	@$(foreach C,$(ALL_COMPONENTS), \
   158  		echo \\nTesting deis/$(C) ; \
   159  		$(MAKE) -C $(C) test ; \
   160  	)
   161  
   162  test-integration:
   163  	$(MAKE) -C tests/ test-full
   164  
   165  test-smoke:
   166  	$(MAKE) -C tests/ test-smoke
   167  
   168  uninstall: check-fleet stop
   169  	$(FLEETCTL) unload -block-attempts=600 $(call deis_units,launched,.)
   170  	$(FLEETCTL) destroy $(strip $(call deis_units,.,.))