Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

WIP: mount a host folder on api containers for logging #301

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions container/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ WORKDIR /home/juser
RUN /opt/julia_0.4.0/bin/julia -e "try; Pkg.installed(\"JuliaWebAPI\"); catch; Pkg.clone(\"https://github.com/tanmaykm/JuliaWebAPI.jl\"); end"
RUN /opt/julia_0.3.11/bin/julia -e "try; Pkg.installed(\"JuliaWebAPI\"); catch; Pkg.clone(\"https://github.com/tanmaykm/JuliaWebAPI.jl\"); end"

# create a folder for storing log files, which can be mounted to a host volume during startup
RUN mkdir -p /home/juser/logs

ENTRYPOINT ["julia", "-e", "using JuliaWebAPI; using Compat; process();"]
4 changes: 3 additions & 1 deletion engine/conf/tornado.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
# Maximum number of requests in queue before rejecting new requests
"numapilocalmax" : 5,
# Seconds to wait before force deleting a non-responding container
"expire" : 1800
"expire" : 1800,
# Host folder where API containers can write logs. This is mounted as /home/juser/logs in the container.
"log_location" : "/jboxengine/logs/api"
},

# interactive container configuration
Expand Down
13 changes: 12 additions & 1 deletion engine/src/juliabox/api/api_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class APIContainer(BaseContainer):
CPU_LIMIT = 1024
MEM_LIMIT = None
EXPIRE_SECS = 0
VOLUMES = ['/home/juser/logs']
HOST_LOG_FOLDER = '/jboxengine/logs/api'
MAX_CONTAINERS = 0
MAX_PER_API_CONTAINERS = 0

Expand All @@ -44,6 +46,7 @@ def configure():
APIContainer.MAX_CONTAINERS = JBoxCfg.get('api.numlocalmax')
APIContainer.MAX_PER_API_CONTAINERS = JBoxCfg.get('api.numapilocalmax')
APIContainer.EXPIRE_SECS = JBoxCfg.get('api.expire')
APIContainer.HOST_LOG_FOLDER = JBoxCfg.get('api.log_location')

@staticmethod
def unique_container_name(api_name):
Expand Down Expand Up @@ -80,6 +83,13 @@ def ensure_container_available(api_name):

@staticmethod
def create_new(api_name):
vols = {
APIContainer.HOST_LOG_FOLDER: {
'bind': APIContainer.VOLUMES[0],
'ro': False
}
}

container_name = APIContainer.unique_container_name(api_name)
queue = APIQueue.get_queue(api_name)
env = {
Expand All @@ -92,12 +102,13 @@ def create_new(api_name):
if image_name is None:
image_name = APIContainer.DCKR_IMAGE

hostcfg = docker.utils.create_host_config(mem_limit=APIContainer.MEM_LIMIT)
hostcfg = docker.utils.create_host_config(binds=vols, mem_limit=APIContainer.MEM_LIMIT)

jsonobj = APIContainer.DCKR.create_container(image_name,
detach=True,
host_config=hostcfg,
cpu_shares=APIContainer.CPU_LIMIT,
volumes=APIContainer.VOLUMES,
environment=env,
hostname='juliabox',
name=container_name)
Expand Down