Skip to content

Commit

Permalink
drive-by env handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich committed Jan 14, 2018
1 parent 23f3c66 commit 193c979
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
15 changes: 15 additions & 0 deletions packtivity/handlers/environment_handlers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import packtivity.utils as utils

handlers,environment = utils.handler_decorator()

@environment('docker-encapsulated')
def docker(environment,parameters,state):
for i,x in enumerate(environment['par_mounts']):
script = x.pop('jqscript')
x['mountcontent'] = jq.jq(script).transform(parameters, text_output = True)

if environment['workdir'] is not None:
environment['workdir'] = state.contextualize_value(environment['workdir'])
return environment


@environment('default')
def default(environment,parameters,state):
return environment
27 changes: 18 additions & 9 deletions packtivity/syncbackends.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,24 @@ def build_env(environment,parameters,state,pack_config):
this will use a handler in the future (just as build_job)
'''

env = copy.deepcopy(environment)
if environment['environment_type'] == 'docker-encapsulated':
for i,x in enumerate(env['par_mounts']):
script = x.pop('jqscript')
x['mountcontent'] = jq.jq(script).transform(parameters, text_output = True)

if env['workdir'] is not None:
env['workdir'] = state.contextualize_value(env['workdir'])
return env
env_type = environment['environment_type']
impl = pack_config.get_impl('environment',env_type)
from .handlers.environment_handlers import handlers as env_handlers
try:
handler = env_handlers[env_type][impl]
except KeyError:
handler = env_handlers['default']['default']
return handler(environment,parameters,state)
#
# env = copy.deepcopy(environment)
# if environment['environment_type'] == 'docker-encapsulated':
# for i,x in enumerate(env['par_mounts']):
# script = x.pop('jqscript')
# x['mountcontent'] = jq.jq(script).transform(parameters, text_output = True)
#
# if env['workdir'] is not None:
# env['workdir'] = state.contextualize_value(env['workdir'])
# return env

def run_in_env(environment,job,state,metadata,pack_config):
'''
Expand Down

0 comments on commit 193c979

Please sign in to comment.