Zack Williams | ce63eb0 | 2017-02-28 10:46:22 -0700 | [diff] [blame^] | 1 | # CORD Master Makefile |
| 2 | |
| 3 | # Timestamp for log files |
| 4 | TS := $(shell date +'%Y%m%dT%H%M%SZ') |
| 5 | |
| 6 | # Podconfig must be specified, so an invalid default |
| 7 | PODCONFIG ?= invalid |
| 8 | |
| 9 | # Source path |
| 10 | BUILD ?= . |
| 11 | CORD ?= .. |
| 12 | PI ?= $(BUILD)/platform-install |
| 13 | MAAS ?= $(BUILD)/maas |
| 14 | |
| 15 | # Configuration paths |
| 16 | PODCONFIG_D ?= $(BUILD)/podconfig |
| 17 | PODCONFIG_PATH ?= $(PODCONFIG_D)/$(PODCONFIG) |
| 18 | |
| 19 | SCENARIOS_D ?= $(BUILD)/scenarios |
| 20 | GENCONFIG_D ?= $(BUILD)/genconfig |
| 21 | |
| 22 | # Milestones/logs paths |
| 23 | M ?= $(BUILD)/milestones |
| 24 | LOGS ?= $(BUILD)/logs |
| 25 | |
| 26 | ALL_MILESTONES ?= $(M)/prereqs-check $(M)/vagrant-up $(M)/copy-cord $(M)/cord-config $(M)/copy-config $(M)/prep-buildnode $(M)/prep-headnode $(M)/elasticstack $(M)/prep-computenode $(M)/glance-images $(M)/deploy-openstack $(M)/deploy-maas $(M)/deploy-computenode $(M)/docker-images $(M)/core-image $(M)/start-xos $(M)/onboard-profile $(M)/deploy-onos $(M)/onboard-openstack |
| 27 | |
| 28 | LOCAL_MILESTONES ?= $(M)/local-cord-config $(M)/local-docker-images $(M)/local-core-image $(M)/local-start-xos $(M)/local-onboard-profile |
| 29 | |
| 30 | # Configuration files |
| 31 | MASTER_CONFIG ?= $(GENCONFIG_D)/config.yml |
| 32 | MAKEFILE_CONFIG ?= $(GENCONFIG_D)/config.mk |
| 33 | INVENTORY ?= $(GENCONFIG_D)/inventory.ini |
| 34 | PROFILE_NAME_F ?= $(GENCONFIG_D)/cord_profile |
| 35 | SCENARIO_NAME_F ?= $(GENCONFIG_D)/cord_scenario |
| 36 | |
| 37 | CONFIG_FILES = $(MASTER_CONFIG) $(MAKEFILE_CONFIG) $(INVENTORY) $(PROFILE_NAME_F) $(SCENARIO_NAME_F) |
| 38 | |
| 39 | include $(MAKEFILE_CONFIG) |
| 40 | |
| 41 | # Set using files from genconfig |
| 42 | SCENARIO = $(shell cat $(SCENARIO_NAME_F)) |
| 43 | PROFILE = $(shell cat $(PROFILE_NAME_F)) |
| 44 | |
| 45 | # Host names for SSH commands |
| 46 | BUILDNODE ?= head1 |
| 47 | HEADNODE ?= ${BUILDNODE} |
| 48 | |
| 49 | # Vagrant config |
| 50 | VAGRANT_PROVIDER ?= libvirt |
| 51 | VAGRANT_VMS ?= $(HEADNODE) |
| 52 | VAGRANT_CWD ?= $(SCENARIOS_D)/$(SCENARIO)/ |
| 53 | SSH_CONFIG ?= ~/.ssh/config # Vagrant modifies this, should it always? |
| 54 | |
| 55 | # Ansible args, for verbosity and other runtime parameters |
| 56 | ANSIBLE_ARGS ?= |
| 57 | |
| 58 | # Commands |
| 59 | SHELL = bash -o pipefail |
| 60 | VAGRANT ?= VAGRANT_CWD=$(VAGRANT_CWD) vagrant |
| 61 | ANSIBLE ?= ansible -i $(INVENTORY) |
| 62 | ANSIBLE_PB ?= ansible-playbook $(ANSIBLE_ARGS) -i $(INVENTORY) --extra-vars @$(MASTER_CONFIG) |
| 63 | ANSIBLE_PB_LOCAL ?= ansible-playbook $(ANSIBLE_ARGS) -i $(PI)/inventory/head-localhost --extra-vars "@/opt/cord_profile/genconfig/config.yml" |
| 64 | ANSIBLE_PB_MAAS ?= ansible-playbook $(ANSIBLE_ARGS) -i /etc/maas/ansible/pod-inventory --extra-vars "@/opt/cord_profile/genconfig/config.yml" |
| 65 | IMAGEBUILDER ?= python $(BUILD)/scripts/imagebuilder.py |
| 66 | LOGCMD ?= 2>&1 | tee -a $(LOGS)/$(TS)_$(@F) |
| 67 | SSH_HEAD ?= ssh $(HEADNODE) |
| 68 | SSH_BUILD ?= ssh $(BUILDNODE) |
| 69 | |
| 70 | # default target, prints help |
| 71 | .DEFAULT: help |
| 72 | |
| 73 | help: |
| 74 | @echo "Please specify a target (config, build, teardown, ...)" |
| 75 | |
| 76 | # Config file generation |
| 77 | config: $(CONFIG_FILES) |
| 78 | |
| 79 | |
| 80 | $(CONFIG_FILES): |
| 81 | ansible-playbook -i 'localhost,' --extra-vars="cord_podconfig='$(PODCONFIG_PATH)' genconfig_dir='$(GENCONFIG_D)' scenarios_dir='$(SCENARIOS_D)'" $(BUILD)/ansible/genconfig.yml $(LOGCMD) |
| 82 | |
| 83 | printconfig: config |
| 84 | @echo "Scenario: $(SCENARIO)" |
| 85 | @echo "Profile: $(PROFILE)" |
| 86 | |
| 87 | # Primary Targets |
| 88 | # Many of these targets use target-specific variables |
| 89 | # https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html |
| 90 | |
| 91 | build: $(BUILD_TARGETS) |
| 92 | |
| 93 | # Utility targets |
| 94 | |
| 95 | xos-teardown: xos-update-images |
| 96 | $(ANSIBLE_PB) $(PI)/teardown-playbook.yml $(LOGCMD) |
| 97 | rm -f $(M)/onboard-profile $(M)/local-onboard-profile |
| 98 | |
| 99 | xos-update-images: clean-images |
| 100 | rm -f $(M)/core-image $(M)/start-xos $(M)/local-core-image $(M)local-start-xos |
| 101 | |
| 102 | compute-node-refresh: |
| 103 | $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_MAAS) $(PI)/compute-node-refresh-playbook.yml" $(LOGCMD) |
| 104 | |
| 105 | vagrant-destroy: |
| 106 | $(VAGRANT) destroy $(LOGCMD) |
| 107 | rm -f $(M)/vagrant-up |
| 108 | |
| 109 | clean-images: |
| 110 | rm -f $(M)/docker-images $(M)/local-docker-images |
| 111 | |
| 112 | clean-genconfig: |
| 113 | rm -f $(CONFIG_FILES) |
| 114 | |
| 115 | clean-profile: |
| 116 | rm -rf $(CONFIG_CORD_PROFILE_DIR) |
| 117 | rm -f $(M)/cord-config $(M)/copy-config |
| 118 | |
| 119 | clean-all: vagrant-destroy clean-profile clean-genconfig |
| 120 | rm -f $(ALL_MILESTONES) |
| 121 | |
| 122 | clean-local: clean-profile clean-genconfig |
| 123 | rm -f $(LOCAL_MILESTONES) |
| 124 | |
| 125 | # == PREREQS == # |
| 126 | VAGRANT_UP_PREREQS ?= |
| 127 | CORD_CONFIG_PREREQS ?= |
| 128 | COPY_CONFIG_PREREQS ?= |
| 129 | PREP_BUILDNODE_PREREQS ?= |
| 130 | PREP_HEADNODE_PREREQS ?= |
| 131 | |
| 132 | # == MILESTONES == # |
| 133 | # empty target files are touched in the milestones dir to indicate completion |
| 134 | |
| 135 | $(M)/prereqs-check: |
| 136 | $(ANSIBLE_PB) $(PI)/prereqs-check-playbook.yml $(LOGCMD) |
| 137 | touch $@ |
| 138 | |
| 139 | $(M)/vagrant-up: | $(VAGRANT_UP_PREREQS) |
| 140 | $(VAGRANT) up $(VAGRANT_VMS) --provider $(VAGRANT_PROVIDER) $(LOGCMD) |
| 141 | @echo "Configuring SSH for VM's..." |
| 142 | $(VAGRANT) ssh-config $(VAGRANT_VMS) > $(SSH_CONFIG) |
| 143 | touch $@ |
| 144 | |
| 145 | $(M)/copy-cord: | $(M)/vagrant-up |
| 146 | $(ANSIBLE_PB) $(PI)/copy-cord-playbook.yml $(LOGCMD) |
| 147 | touch $@ |
| 148 | |
| 149 | $(M)/cord-config: | $(M)/vagrant-up $(CORD_CONFIG_PREREQS) |
| 150 | $(ANSIBLE_PB) $(PI)/cord-config-playbook.yml $(LOGCMD) |
| 151 | cp -r $(GENCONFIG_D) $(CONFIG_CORD_PROFILE_DIR)/genconfig |
| 152 | touch $@ |
| 153 | |
| 154 | $(M)/copy-config: | $(COPY_CONFIG_PREREQS) |
| 155 | $(ANSIBLE_PB) $(PI)/copy-profile-playbook.yml $(LOGCMD) |
| 156 | touch $@ |
| 157 | |
| 158 | $(M)/prep-buildnode: | $(M)/vagrant-up $(M)/cord-config $(PREP_BUILDNODE_PREREQS) |
| 159 | $(ANSIBLE_PB) $(PI)/prep-buildnode-playbook.yml $(LOGCMD) |
| 160 | @echo Waiting 10 seconds to timeout SSH ControlPersist, and so future ansible commands gain docker group membership |
| 161 | sleep 10 |
| 162 | touch $@ |
| 163 | |
| 164 | $(M)/prep-headnode: | $(M)/vagrant-up $(M)/cord-config $(PREP_HEADNODE_PREREQS) |
| 165 | $(ANSIBLE_PB) $(PI)/prep-headnode-playbook.yml $(LOGCMD) |
| 166 | touch $@ |
| 167 | |
| 168 | $(M)/elasticstack: | $(M)/prep-headnode |
| 169 | $(ANSIBLE_PB) $(PI)/deploy-elasticstack-playbook.yml $(LOGCMD) |
| 170 | touch $@ |
| 171 | |
| 172 | $(M)/prep-computenode: | $(M)/prep-headnode |
| 173 | $(ANSIBLE_PB) $(PI)/prep-computenode-playbook.yml $(LOGCMD) |
| 174 | touch $@ |
| 175 | |
| 176 | $(M)/glance-images: | $(M)/prep-headnode |
| 177 | $(ANSIBLE_PB) $(PI)/glance-images-playbook.yml $(LOGCMD) |
| 178 | touch $@ |
| 179 | |
| 180 | $(M)/deploy-openstack: | $(M)/elasticstack $(M)/prep-headnode $(M)/prep-computenode |
| 181 | $(ANSIBLE_PB) $(PI)/deploy-openstack-playbook.yml $(LOGCMD) |
| 182 | touch $@ |
| 183 | |
| 184 | $(M)/deploy-maas: | $(M)/deploy-openstack |
| 185 | $(ANSIBLE_PB) $(MAAS)/head.yml $(LOGCMD) |
| 186 | touch $@ |
| 187 | |
| 188 | $(M)/deploy-computenode: | $(M)/deploy-openstack |
| 189 | $(ANSIBLE_PB) $(PI)/deploy-computenode-playbook.yml $(LOGCMD) |
| 190 | touch $@ |
| 191 | |
| 192 | $(M)/docker-images: | $(M)/prep-buildnode |
| 193 | $(SSH_BUILD) "cd /opt/cord/build; $(IMAGEBUILDER) -f $(MASTER_CONFIG) -l $(BUILD)/image_logs -g $(BUILD)/ib_graph.dot -a $(BUILD)/ib_actions.yml " $(LOGCMD) |
| 194 | touch $@ |
| 195 | |
| 196 | $(M)/core-image: | $(M)/docker-images $(M)/prep-headnode |
| 197 | $(ANSIBLE_PB) $(PI)/build-core-image-playbook.yml $(LOGCMD) |
| 198 | touch $@ |
| 199 | |
| 200 | $(M)/start-xos: | $(M)/prep-headnode $(M)/core-image |
| 201 | $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_LOCAL) $(PI)/start-xos-playbook.yml" $(LOGCMD) |
| 202 | touch $@ |
| 203 | |
| 204 | $(M)/onboard-profile: | $(M)/start-xos |
| 205 | $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_LOCAL) $(PI)/onboard-profile-playbook.yml" $(LOGCMD) |
| 206 | touch $@ |
| 207 | |
| 208 | $(M)/deploy-onos: | $(M)/start-xos $(M)/docker-images |
| 209 | $(ANSIBLE_PB) $(PI)/deploy-onos-playbook.yml $(LOGCMD) |
| 210 | touch $@ |
| 211 | |
| 212 | $(M)/onboard-openstack: | $(M)/deploy-computenode $(M)/glance-images $(M)/deploy-onos $(M)/onboard-profile |
| 213 | $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_LOCAL) $(PI)/onboard-openstack-playbook.yml" $(LOGCMD) |
| 214 | touch $@ |
| 215 | |
| 216 | # Testing targets |
| 217 | pod-test: $(M)/onboard-openstack |
| 218 | $(ANSIBLE_PB) $(PI)/pod-test-playbook.yml $(LOGCMD) |
| 219 | |
| 220 | # Local Targets, bring up XOS containers without a VM |
| 221 | |
| 222 | $(M)/local-cord-config: |
| 223 | $(ANSIBLE_PB) $(PI)/cord-config-playbook.yml $(LOGCMD) |
| 224 | touch $@ |
| 225 | |
| 226 | $(M)/local-docker-images: | $(M)/local-cord-config |
| 227 | $(IMAGEBUILDER) -f $(MASTER_CONFIG) -l $(BUILD)/image_logs -g $(BUILD)/ib_graph.dot -a $(BUILD)/ib_actions.yml $(LOGCMD) |
| 228 | touch $@ |
| 229 | |
| 230 | $(M)/local-core-image: | $(M)/local-docker-images |
| 231 | $(ANSIBLE_PB) $(PI)/build-core-image-playbook.yml $(LOGCMD) |
| 232 | touch $@ |
| 233 | |
| 234 | $(M)/local-start-xos: | $(M)/local-core-image |
| 235 | $(ANSIBLE_PB) $(PI)/start-xos-playbook.yml $(LOGCMD) |
| 236 | touch $@ |
| 237 | |
| 238 | $(M)/local-onboard-profile: | $(M)/local-start-xos |
| 239 | $(ANSIBLE_PB) $(PI)/onboard-profile-playbook.yml $(LOGCMD) |
| 240 | touch $@ |
| 241 | |