download services before bootstrapping

Change-Id: Id6e0994c8aec0123bb2a3a4b9175bf2c997ef5ce
diff --git a/xos/configurations/common/Makefile.services b/xos/configurations/common/Makefile.services
index 6a5cb06..b5ee431 100644
--- a/xos/configurations/common/Makefile.services
+++ b/xos/configurations/common/Makefile.services
@@ -1,49 +1,51 @@
-services: /opt/xos_services \
-          /opt/xos_services/exampleservice \
-          /opt/xos_services/olt \
-	  /opt/xos_services/vsg \
-          /opt/xos_services/vtn \
-	  /opt/xos_services/vrouter \
-	  /opt/xos_services/vtr \
-	  /opt/xos_services/onos-service \
-	  /opt/xos_services/fabric
+SERVICE_DIR=../../../../xos_services
 
-/opt/xos_services:
-	mkdir -p /opt/xos_services
+services: $(SERVICE_DIR) \
+          $(SERVICE_DIR)/exampleservice \
+          $(SERVICE_DIR)/olt \
+	  $(SERVICE_DIR)/vsg \
+          $(SERVICE_DIR)/vtn \
+	  $(SERVICE_DIR)/vrouter \
+	  $(SERVICE_DIR)/vtr \
+	  $(SERVICE_DIR)/onos-service \
+	  $(SERVICE_DIR)/fabric
 
-/opt/xos_services/exampleservice:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/exampleservice.git
+$(SERVICE_DIR):
+	mkdir -p $(SERVICE_DIR)
 
-/opt/xos_services/olt:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/olt.git
+$(SERVICE_DIR)/exampleservice:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/exampleservice.git
 
-/opt/xos_services/vsg:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/vsg.git
+$(SERVICE_DIR)/olt:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/olt.git
 
-/opt/xos_services/vtn:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/vtn.git
+$(SERVICE_DIR)/vsg:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/vsg.git
 
-/opt/xos_services/vrouter:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/vrouter.git
+$(SERVICE_DIR)/vtn:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/vtn.git
 
-/opt/xos_services/vtr:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/vtr.git
+$(SERVICE_DIR)/vrouter:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/vrouter.git
 
-/opt/xos_services/onos-service:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/onos-service.git
+$(SERVICE_DIR)/vtr:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/vtr.git
 
-/opt/xos_services/fabric:
-	git -C /opt/xos_services clone https://gerrit.opencord.org/p/fabric.git
+$(SERVICE_DIR)/onos-service:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/onos-service.git
+
+$(SERVICE_DIR)/fabric:
+	git -C $(SERVICE_DIR) clone https://gerrit.opencord.org/p/fabric.git
 
 cleanup:
-	rm -rf /opt/xos_services/*
+	rm -rf $(SERVICE_DIR)/*
 
 update:
-	git -C /opt/xos_services/exampleservice pull
-	git -C /opt/xos_services/olt pull
-	git -C /opt/xos_services/vsg pull
-	git -C /opt/xos_services/vtn pull
-	git -C /opt/xos_services/vrouter pull
-	git -C /opt/xos_services/vtr pull
-	git -C /opt/xos_services/onos-service pull
-	git -C /opt/xos_services/fabric pull
+	git -C $(SERVICE_DIR)/exampleservice pull
+	git -C $(SERVICE_DIR)/olt pull
+	git -C $(SERVICE_DIR)/vsg pull
+	git -C $(SERVICE_DIR)/vtn pull
+	git -C $(SERVICE_DIR)/vrouter pull
+	git -C $(SERVICE_DIR)/vtr pull
+	git -C $(SERVICE_DIR)/onos-service pull
+	git -C $(SERVICE_DIR)/fabric pull
diff --git a/xos/configurations/cord-pod/Makefile b/xos/configurations/cord-pod/Makefile
index 3a1f6bf..42a1a68 100644
--- a/xos/configurations/cord-pod/Makefile
+++ b/xos/configurations/cord-pod/Makefile
@@ -17,10 +17,10 @@
 	sudo docker-compose -p $(DOCKER_PROJECT) -f $(BOOTSTRAP_YML) run -e CONFIG_DIR=$(CONFIG_DIR) xos_bootstrap_ui python /opt/xos/tosca/run.py none /opt/xos/configurations/cord-pod/xos.yaml
 
 download_services:
-	sudo make -f ../common/Makefile.services
+	make -f ../common/Makefile.services
 
 update_services:
-	sudo make -f ../common/Makefile.services update
+	make -f ../common/Makefile.services update
 
 onboarding:
 	echo "[ONBOARDING]"
diff --git a/xos/configurations/cord-pod/docker-compose-bootstrap.yml b/xos/configurations/cord-pod/docker-compose-bootstrap.yml
index 1bc3e66..a00646b 100644
--- a/xos/configurations/cord-pod/docker-compose-bootstrap.yml
+++ b/xos/configurations/cord-pod/docker-compose-bootstrap.yml
@@ -16,7 +16,7 @@
         - /var/run/docker.sock:/var/run/docker.sock
         - ./key_import:/opt/xos/key_import:ro
         - ./onboarding-docker-compose:/opt/xos/synchronizers/onboarding/docker-compose
-        - /opt/xos_services:/opt/xos_services
+        - ../../../../xos_services:/opt/xos_services
     log_driver: "json-file"
     log_opt:
             max-size: "100k"
@@ -53,7 +53,7 @@
         - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
         - ./xos_cord_config:/opt/xos/xos_configuration/xos_cord_config:ro
         - ../vtn/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
-        - /opt/xos_services:/opt/xos_services
+        - ../../../../xos_services:/opt/xos_services
     log_driver: "json-file"
     log_opt:
             max-size: "100k"
diff --git a/xos/configurations/frontend/Makefile b/xos/configurations/frontend/Makefile
index 842cb82..c95322e 100644
--- a/xos/configurations/frontend/Makefile
+++ b/xos/configurations/frontend/Makefile
@@ -6,16 +6,21 @@
 XOS_BOOTSTRAP_PORT=9998
 XOS_UI_PORT=9999
 
-frontend: prereqs bootstrap download_services onboarding frontendconfig
+frontend: prereqs dirs download_services bootstrap onboarding frontendconfig
 
 prereqs:
 	sudo make -f ../common/Makefile.prereqs
 
+dirs:
+	# if this directory doesn't exist, then docker-compose will create it with root permission
+	mkdir -p key_import
+	mkdir -p onboarding-docker-compose
+
 download_services:
-	sudo make -f ../common/Makefile.services
+	make -f ../common/Makefile.services
 
 update_services:
-	sudo make -f ../common/Makefile.services update
+	make -f ../common/Makefile.services update
 
 bootstrap:
 	echo "[BOOTSTRAP]"
diff --git a/xos/configurations/frontend/docker-compose-bootstrap.yml b/xos/configurations/frontend/docker-compose-bootstrap.yml
index d0b360f..5341209 100644
--- a/xos/configurations/frontend/docker-compose-bootstrap.yml
+++ b/xos/configurations/frontend/docker-compose-bootstrap.yml
@@ -13,7 +13,7 @@
     volumes:
       - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config
       - ../vtn/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
-      - /opt/xos_services:/opt/xos_services
+      - ../../../../xos_services:/opt/xos_services
 
 xos_synchronizer_onboarding:
     image: xosproject/xos-synchronizer-onboarding
@@ -28,7 +28,7 @@
         - /var/run/docker.sock:/var/run/docker.sock
         - ./key_import:/opt/xos/key_import:ro
         - ./onboarding-docker-compose:/opt/xos/synchronizers/onboarding/docker-compose
-        - /opt/xos_services:/opt/xos_services
+        - ../../../../xos_services:/opt/xos_services
     log_driver: "json-file"
     log_opt:
             max-size: "100k"
diff --git a/xos/configurations/test-standalone/Makefile b/xos/configurations/test-standalone/Makefile
index a3ee0a2..7aaba41 100644
--- a/xos/configurations/test-standalone/Makefile
+++ b/xos/configurations/test-standalone/Makefile
@@ -25,11 +25,16 @@
 	sudo docker exec -i teststandalone_xos_ui_1 bash -c "cd /opt/xos/tests/api; npm install --production"
 	sudo docker exec teststandalone_xos_ui_1 pip install dredd_hooks
 
-xos: prereqs bootstrap download_services onboarding
+xos: prereqs dirs download_services bootstrap onboarding
 
 prereqs:
 	sudo make -f ../common/Makefile.prereqs
 
+dirs:
+	# if this directory doesn't exist, then docker-compose will create it with root permission
+	mkdir -p key_import
+	mkdir -p onboarding-docker-compose
+
 bootstrap:
 	echo "[BOOTSTRAP]"
 	sudo rm -f onboarding-docker-compose/docker-compose.yml
@@ -82,9 +87,9 @@
 	# sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/setup.yaml
 	# sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/nodes.yaml
 	# sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/images.yaml
-	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/mgmt-net.yaml
-	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/test-standalone/services.yaml
-	sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/cord-volt-devices.yaml
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(DOCKER_COMPOSE_YML) run xos_ui python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/mgmt-net.yaml
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(DOCKER_COMPOSE_YML) run xos_ui python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/test-standalone/services.yaml
+	sudo docker-compose -p $(DOCKER_PROJECT) -f $(DOCKER_COMPOSE_YML) run xos_ui python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/cord-volt-devices.yaml
 
 
 test: restore-initial-db-status
diff --git a/xos/configurations/test-standalone/docker-compose-bootstrap.yml b/xos/configurations/test-standalone/docker-compose-bootstrap.yml
index d0b360f..5341209 100644
--- a/xos/configurations/test-standalone/docker-compose-bootstrap.yml
+++ b/xos/configurations/test-standalone/docker-compose-bootstrap.yml
@@ -13,7 +13,7 @@
     volumes:
       - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config
       - ../vtn/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
-      - /opt/xos_services:/opt/xos_services
+      - ../../../../xos_services:/opt/xos_services
 
 xos_synchronizer_onboarding:
     image: xosproject/xos-synchronizer-onboarding
@@ -28,7 +28,7 @@
         - /var/run/docker.sock:/var/run/docker.sock
         - ./key_import:/opt/xos/key_import:ro
         - ./onboarding-docker-compose:/opt/xos/synchronizers/onboarding/docker-compose
-        - /opt/xos_services:/opt/xos_services
+        - ../../../../xos_services:/opt/xos_services
     log_driver: "json-file"
     log_opt:
             max-size: "100k"