def stack_container(container, config): announce("Stacking " + container + " container") if config.has_key('run') and not config['run']: note("container has 'run' key set to " + str(config['run']) + ", skipping") return command = ['docker', 'run', '-d', '--name', get_container(container)] if config.has_key('options'): for option in config['options']: command = command + [parse_template(option)] if config.has_key('hostname'): command = command + ['--hostname', get_value(config, 'hostname')] # else: # command = command + ['--hostname', container] if config.has_key('dns'): command = command + ['--dns', get_value(config, 'dns')] if config.has_key('volumes'): for volumespec in config['volumes']: volumespec_parsed = parse_template(volumespec) if volumespec_parsed.startswith("/"): command = command + ['-v', volumespec_parsed] else: command = command + [ '-v', mem.VolumePath + "/" + mem.Project + "/" + container + "/" + volumespec_parsed ] if config.has_key('ports'): for portspec in config['ports']: command = command + ['-p', parse_template(portspec)] if config.has_key('environment'): for envvar in config['environment']: command = command + [ '-e', parse_template(envvar) + '=' + parse_template(config['environment'][envvar]) ] if config.has_key('links'): for link in config['links']: command = command + [ "--link=" + get_container(parse_template(link)) ] command.append(get_image(config)) if config.has_key('command'): command = command + shlex.split(get_value(config, 'command')) note(" ".join(command)) quietcall(command) if config.has_key('upwhen'): wait_for_up(container, config)
def unstack_container(container): announce("Unstacking " + container + " container") command = ['docker', 'stop', get_container(container)] note(" ".join(command)) quietcall(command) command = ['docker', 'rm', '--force', get_container(container)] note(" ".join(command)) quietcall(command)
def enter_container(commands): which = commands.popleft() run = ["/bin/bash"] if len(commands) > 0: run = list(commands) announce("Entering '" + which + "' container and running: " + str(run)) command = ['docker', 'exec', '-ti', get_container(which)] + run note(" ".join(command)) call(command)
def stack_container(container, config): announce("Stacking " + container + " container") if config.has_key('run') and not config['run']: note("container has 'run' key set to " + str(config['run']) + ", skipping") return command = ['docker', 'run', '-d', '--name', get_container(container)] if config.has_key('options'): for option in config['options']: command = command + [parse_template(option)] if config.has_key('hostname'): command = command + ['--hostname', get_value(config, 'hostname')] # else: # command = command + ['--hostname', container] if config.has_key('dns'): command = command + ['--dns', get_value(config, 'dns')] if config.has_key('volumes'): for volumespec in config['volumes']: volumespec_parsed = parse_template(volumespec) if volumespec_parsed.startswith("/"): command = command + ['-v', volumespec_parsed] elif volumespec_parsed.startswith('./'): # docker complains if path starts with "." so expand CWD here cwd = os.path.dirname(os.path.realpath(volumespec_parsed.split(':')[0])) realpath = cwd + '/' + volumespec_parsed.strip('./') command = command + ['-v', realpath] else: command = command + ['-v', mem.VolumePath + '/' + mem.Project + '/' + container + '/' + volumespec_parsed] if config.has_key('ports'): for portspec in config['ports']: command = command + ['-p', parse_template(portspec)] if config.has_key('environment'): for envvar in config['environment']: command = command + ['-e', parse_template(envvar) + '=' + parse_template(config['environment'][envvar])] if config.has_key('links'): for link in config['links']: command = command + ["--link=" + get_container(parse_template(link))] command.append(get_image(config)) if config.has_key('command'): command = command + shlex.split(get_value(config, 'command')) note(" ".join(command)) quietcall(command) if config.has_key('upwhen'): wait_for_up(container, config)
def fill_container(container, config): announce("Filling " + container + " container") if config.has_key('build'): build = get_value(config, 'build') tag = mem.Project + "/" + build if config.has_key('tag'): tag = get_value(config, 'tag') target = build if build[:4] == 'git:': if not config.has_key('tag'): raise Exception( "If you are using a git repo for 'build' you must also specify 'tag'" ) tag = get_value(config, 'tag') url = build[4:] print("Cloning " + tag + " from " + url, end="") dir = "_grua_" + tag.replace("/", "_") if os.path.isdir(dir): shutil.rmtree(dir) command = ['git', 'clone', url, dir] note(" ".join(command)) call(command) target = dir mention("building " + container + " ( " + target + " ) " + " with tag '" + tag + "'") command = ['docker', 'build', '-t', tag, target] note(" ".join(command)) quietcall(command) else: mention(container + " uses an image. Pulling " + get_value(config, 'image')) command = ['docker', 'pull', get_value(config, 'image')] note(" ".join(command)) quietcall(command)
def fill_container(container, config): announce("Filling " + container + " container") if config.has_key('build'): build = get_value(config, 'build') tag = mem.Project + "/" + build if config.has_key('tag'): tag = get_value(config, 'tag') target = build if build[:4] == 'git:': if not config.has_key('tag'): raise Exception("If you are using a git repo for 'build' you must also specify 'tag'") tag = get_value(config, 'tag') url = build[4:] print ( "Cloning " + tag + " from " + url, end="" ) dir = "_grua_" + tag.replace("/", "_") if os.path.isdir(dir): shutil.rmtree(dir) command = ['git', 'clone', url, dir] note(" ".join(command)) call(command) target = dir mention("building " + container + " ( " + target + " ) " + " with tag '" + tag + "'") command = ['docker', 'build', '-t', tag, target] note(" ".join(command)) quietcall(command) else: mention(container + " uses an image. Pulling " + get_value(config, 'image')) command = ['docker', 'pull', get_value(config, 'image')] note(" ".join(command)) quietcall(command)
def empty_container(container, config): announce("Emptying image " + container) command = ['docker', 'rmi', get_image(config)] note(" ".join(command)) quietcall(command)