David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 1 | SUBDIRS := automation config-generator harvester ip-allocator provisioner switchq |
| 2 | TARGETS := build publish clean test |
| 3 | PUBLIC_IMAGES := consul@sha256:0dc990ff3c44d5b5395475bcc5ebdae4fc8b67f69e17942a8b9793b3df74d290 |
| 4 | I2 := consul:latest |
| 5 | I3 := consul |
| 6 | |
| 7 | ANSIBLE_ARGS?= |
| 8 | MAKE_CONFIG?=config.mk |
| 9 | |
| 10 | # [EXPERIMENTAL] Deployment via make is currently experimental |
| 11 | DEPLOY_INVENTORY=deploy-inv |
| 12 | DEPLOY_CONFIG=deploy-vars |
| 13 | |
| 14 | # expands to lists of of the form: |
| 15 | # <target>_TARGETS := <subdir1>_<target> <subdir2>_<target> |
| 16 | $(foreach TARGET, $(TARGETS), $(eval $(TARGET)_TARGETS := $(addsuffix _$(TARGET), $(SUBDIRS)))) |
| 17 | |
| 18 | ifeq ($(realpath $(MAKE_CONFIG)),) |
| 19 | $(info Makefile configuration not found, defaults will be used.) |
| 20 | else |
| 21 | $(info Using makefile configuration "$(MAKE_CONFIG)") |
| 22 | endif |
| 23 | |
| 24 | define recursive_rule |
| 25 | $1_$2: |
| 26 | $$(MAKE) MAKE_CONFIG=$(realpath $(MAKE_CONFIG)) CONFIG=$(realpath $(CONFIG)) -C $1 $2 |
| 27 | endef |
| 28 | |
| 29 | $(foreach SUBDIR, $(SUBDIRS), $(foreach TARGET, $(TARGETS), $(eval $(call recursive_rule,$(SUBDIR),$(TARGET))))) |
| 30 | |
| 31 | $(foreach TARGET, $(TARGETS), $(eval $(TARGET): $($(TARGET)_TARGETS))) |
| 32 | |
| 33 | include help.mk |
| 34 | |
| 35 | ifneq ($(realpath $(MAKE_CONFIG)),) |
| 36 | include $(MAKE_CONFIG) |
| 37 | endif |
| 38 | |
| 39 | define public_image_rules |
| 40 | $2.image: |
| 41 | docker pull $1 |
| 42 | @touch $$@ |
| 43 | |
| 44 | $2.publish: $2.image |
| 45 | docker tag $1 $(DOCKER_REGISTRY)/$2:$(DEPLOY_DOCKER_TAG) |
| 46 | docker push $(DOCKER_REGISTRY)/$2:$(DEPLOY_DOCKER_TAG) |
| 47 | @touch $$@ |
| 48 | |
| 49 | publish: $2.publish |
| 50 | endef |
| 51 | |
| 52 | $(foreach PUBLIC_IMAGE, $(PUBLIC_IMAGES), $(eval $(call public_image_rules,$(PUBLIC_IMAGE),$(word 1,$(subst @, ,$(subst :, ,$(PUBLIC_IMAGE))))))) |
| 53 | |
| 54 | prime: |
| 55 | ansible-playbook -i $(DEPLOY_INVENTORY) --extra-vars=@$(DEPLOY_CONFIG) $(ANSIBLE_ARGS) prime-node.yml |
| 56 | |
| 57 | deploy: publish |
| 58 | ansible-playbook -i $(DEPLOY_INVENTORY) --extra-vars=@$(DEPLOY_CONFIG) $(ANSIBLE_ARGS) head-node.yml |
| 59 | |
| 60 | config: |
| 61 | @echo "hello" |
| 62 | |
| 63 | clean: |