Commit 1578fbfb authored by Daniele Venzano's avatar Daniele Venzano

Add a volume for logs to each service

parent 210784f2
......@@ -23,3 +23,12 @@ Whenever Zoe needs to access the container backend it will create a new instance
.. autoclass:: zoe_master.backends.base.BaseBackend
:members:
Obligations for backends
------------------------
When a backend creates a container it must:
1. add all variables from ``zoe_master.backends.common.gen_environment(service, execution)`` to the environment of the container
2. add all volumes from ``zoe_master.backends.common.gen_volumes(service, execution)`` to the environment of the container
3. run the /zoe.sh script as the container entrypoint, passing any command specified in the application description as one or more arguments
......@@ -18,8 +18,8 @@ All information from Zoe is passed in predefined environment variables:
A number of volumes will be mounted on all containers:
* User workspace, same for all containers of a certain user
* Logs, different for each container
* User workspace, same for all containers of a certain user, mounted at /workspace
* Logs, different for each container, mounted at /logs
A Zoe script will be the entrypoint for all ZApp containers. If a command is specified for a container, it must be a user-specified script that will be run by the Zoe script.
......
......@@ -65,6 +65,8 @@ def load_configuration(test_conf=None):
argparser.add_argument('--gelf-address', help='Enable Docker GELF log output to this destination (ex. udp://1.2.3.4:1234)', default='')
argparser.add_argument('--workspace-base-path', help='Path where user workspaces will be created by Zoe. Must be visible at this path on all Swarm hosts.', default='/mnt/zoe-workspaces')
argparser.add_argument('--workspace-deployment-path', help='Path appended to the workspace path to distinguish this deployment. If unspecified is equal to the deployment name.', default='--default--')
argparser.add_argument('--logs-base-path', help='Base path where containers will be able to save logs. Must be a shared directory, visible at this path on all Swarm hosts and writable by Zoe.', default='/mnt/zoe-logs')
argparser.add_argument('--overlay-network-name', help='Name of the Swarm overlay network Zoe should use', default='zoe')
# API options
......
......@@ -18,4 +18,4 @@
from zoe_lib.state.base import Base
from zoe_lib.state.execution import Execution
from zoe_lib.state.sql_manager import SQLManager
from zoe_lib.state.service import Service
from zoe_lib.state.service import Service, VolumeDescription
......@@ -15,10 +15,15 @@
"""The high-level interface that Zoe uses to talk to the configured container backend."""
from zoe_lib.state import Service, Execution
import os
import logging
from zoe_lib.state import Service, Execution, VolumeDescription
from zoe_lib.config import get_conf
from zoe_master.workspace.filesystem import ZoeFSWorkspace
log = logging.getLogger(__name__)
def gen_environment(service: Service, execution: Execution):
"""Return the list of environment variables that needs to be added to all containers."""
......@@ -42,11 +47,28 @@ def gen_environment(service: Service, execution: Execution):
return env_list
def _create_logs_directories(exec_id, service_name):
path = get_conf().logs_base_path + '/' + get_conf().deployment_name + str(exec_id) + '/' + service_name
try:
os.makedirs(path)
except OSError as e:
log.error('Cannot create path {}: {}'.format(path, str(e)))
return None
return path
def gen_volumes(service: Service, execution: Execution):
"""Return the list of default volumes to be added to all containers."""
vol_list = []
fswk = ZoeFSWorkspace()
if fswk.can_be_attached():
vol_list.append(fswk.get(execution.user_id))
wk_vol = fswk.get(execution.user_id)
vol_list.append(wk_vol)
logs_path = _create_logs_directories(execution.id, service.name)
if logs_path is not None:
logs_mountpoint = '/logs'
logs_vol = VolumeDescription((logs_path, logs_mountpoint, True))
vol_list.append(logs_vol)
return vol_list
......@@ -19,7 +19,7 @@ import logging
import os.path
import zoe_lib.config as config
from zoe_lib.state.service import VolumeDescription
from zoe_lib.state import VolumeDescription
import zoe_master.workspace.base
log = logging.getLogger(__name__)
......@@ -46,8 +46,8 @@ class ZoeFSWorkspace(zoe_master.workspace.base.ZoeWorkspaceBase):
@classmethod
def get_mountpoint(cls):
"""Get the volume mount point."""
return '/mnt/workspace'
return '/workspace'
def get(self, user_id):
"""Return a VolumeDescription."""
"""Return a VolumeDescription for the user workspace."""
return VolumeDescription((self.get_path(user_id), self.get_mountpoint(), False))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment