create docker-compose.yml
diff --git a/xos/synchronizers/onboarding/steps/sync_xos.py b/xos/synchronizers/onboarding/steps/sync_xos.py
index 095fae8..55e7553 100644
--- a/xos/synchronizers/onboarding/steps/sync_xos.py
+++ b/xos/synchronizers/onboarding/steps/sync_xos.py
@@ -29,6 +29,8 @@
def sync_record(self, xos):
logger.info("Sync'ing XOS %s" % xos)
+ self.create_docker_compose()
+
dockerfiles = [self.create_ui_dockerfile()]
tenant_fields = {"dockerfiles": dockerfiles,
"build_dir": self.build_dir,
diff --git a/xos/synchronizers/onboarding/templates/docker-compose.yml.j2 b/xos/synchronizers/onboarding/templates/docker-compose.yml.j2
new file mode 100644
index 0000000..1532604
--- /dev/null
+++ b/xos/synchronizers/onboarding/templates/docker-compose.yml.j2
@@ -0,0 +1,37 @@
+{% for container_name, container in containers.iteritems() %}
+
+{{ container_name}}:
+ image: {{ container.image }}
+{%- if container.command %}
+ command: {{ container.command }}
+{%- endif %}
+{%- if container.ports %}
+ ports:
+{%- for src,dest in container.ports.iteritems() %}
+ - "{{ src }}:{{ dest }}"
+{%- endfor %}
+{%- endif %}
+{%- if container.links %}
+ lines:
+{%- for link in container.links %}
+ - {{ link }}
+{%- endfor %}
+{%- endif %}
+{%- if container.volumes %}
+{%- for volume in container.volumes %}
+ volumes:
+{%- if volume.read_only %}
+ - {{ volume.host_path }}:{ volume.container_path }}:ro
+{%- else %}
+ - {{ volume.host_path }}:{ volume.container_path }}
+{%- endif %}
+{%- endfor %}
+{%- endif %}
+{%- if container.expose %}
+ expose:
+{%- for expose in container.expose %}
+ - "{{ expose }}"
+{%- endfor %}
+{%- endif %}
+
+{%- endfor %}
diff --git a/xos/synchronizers/onboarding/xosbuilder.py b/xos/synchronizers/onboarding/xosbuilder.py
index 43d735b..5eeb675 100644
--- a/xos/synchronizers/onboarding/xosbuilder.py
+++ b/xos/synchronizers/onboarding/xosbuilder.py
@@ -1,5 +1,6 @@
import os
import base64
+import jinja2
import string
import sys
import urllib2
@@ -7,7 +8,7 @@
import xmlrpclib
from xos.config import Config
-from core.models import Service, ServiceController, ServiceControllerResource
+from core.models import Service, ServiceController, ServiceControllerResource, XOS
from xos.logger import Logger, logging
logger = Logger(level=logging.INFO)
@@ -163,6 +164,42 @@
return {"dockerfile_fn": dockerfile_fn,
"docker_image_name": "xosproject/xos-synchronizer-%s" % controller.name}
+ def create_docker_compose(self):
+ xos = XOS.objects.all()[0]
+
+ volume_list = [] # FINISH ME
+
+ containers = {}
+
+ containers["xos_db"] = \
+ {"image": "xosproject/xos-postgres",
+ "expose": [5432]}
+
+ containers["xos_ui"] = \
+ {"image": "xosproject/xos-ui",
+ "command": "python /opt/xos/manage.py runserver 0.0.0.0:%d --insecure --makemigrations" % xos.ui_port,
+ "ports": {"%d"%xos.ui_port : "%d"%xos.ui_port},
+ "links": ["xos_db"],
+ "volumes": volume_list}
+
+ for c in ServiceController.objects.all():
+ containers["xos_synchronizer_%s" % c.name] = \
+ {"image": "xosproject/xos-synchronizer-%s" % controller.name,
+ "command": 'bash -c "sleep 120; bash /opt/xos/synchronizers/%s/run.sh"',
+ "links": ["xos_db"],
+ "volumes": volume_list}
+
+ vars = { "containers": containers }
+
+ template_loader = jinja2.FileSystemLoader( "/opt/xos/synchronizers/onboarding/templates/" )
+ template_env = jinja2.Environment(loader=template_loader)
+ template = template_env.get_template("docker-compose.yml.j2")
+ buffer = template.render(vars)
+
+ if not os.path.exists("/opt/xos/synchronizers/onboarding/docker-compose"):
+ os.makedirs("/opt/xos/synchronizers/onboarding/docker-compose")
+ file("/opt/xos/synchronizers/onboarding/docker-compose/docker-compose.yml", "w").write(buffer)
+
# def build_xos(self):
# dockerfiles=[]
# dockerfiles.append(self.create_ui_dockerfile())