def container_status(container): command = ['docker', 'inspect', '--format="{{.State.Status}}"', get_container(container)] # note(" ".join(command)) try: result = subprocess.check_output(command, stderr=subprocess.STDOUT) if result == "running\n": output = "^ stacked ^" else: output = result except subprocess.CalledProcessError: output = "_ unstacked _" ignore_quiet = True mention(container + ": " + output, ignore_quiet),
def container_status(container): command = [ 'docker', 'inspect', '--format="{{.State.Status}}"', get_container(container) ] # note(" ".join(command)) try: result = subprocess.check_output(command, stderr=subprocess.STDOUT) if result == "running\n": output = "^ stacked ^" else: output = result except subprocess.CalledProcessError: output = "_ unstacked _" ignore_quiet = True mention(container + ": " + output, ignore_quiet),
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 wait_for_up(container, config): upwhen = config['upwhen'] timeout = 30 if upwhen.has_key('timeout'): timeout = get_value(upwhen, 'timeout') if upwhen.has_key('logmsg'): logmsg = get_value(upwhen, 'logmsg') if upwhen.has_key('logfile'): logfile = mem.VolumePath + "/" + mem.Project + "/" + container + "/" + get_value( upwhen, 'logfile') mention("Waiting up to " + str(timeout) + " seconds for '" + logmsg + "' in '" + logfile + "' to indicate that " + container + " is stacked") else: mention("Waiting up to " + str(timeout) + " seconds for '" + logmsg + "' to indicate that " + container + " is stacked") waited = 0 ok = False while waited <= timeout: if not 'logfile' in locals(): command = ["docker", "logs", get_container(container)] else: if logfile.startswith('/'): command = ["tail", logfile] else: # there's a chance we try to tail it before it exists... just ignore that time if os._exists(logfile): command = ["tail", logfile] # command may not have been set yet if the file didn't exist if 'command' in locals(): try: output = subprocess.check_output(command, stderr=subprocess.STDOUT) except: pass # print output if 'output' in locals() and output.find(logmsg) > -1: ok = True break else: time.sleep(1) waited = waited + 1 if not ok: raise Exception("Timed out waiting for " + container + " to start") if upwhen.has_key('sleep'): mention("Sleeping " + str(upwhen['sleep']) + " extra seconds as configured") time.sleep(int(upwhen['sleep']))
def wait_for_up(container, config): upwhen = config['upwhen'] timeout = 30 if upwhen.has_key('timeout'): timeout = get_value(upwhen, 'timeout') if upwhen.has_key('logmsg'): logmsg = get_value(upwhen, 'logmsg') if upwhen.has_key('logfile'): logfile = mem.VolumePath + "/" + mem.Project + "/" + container + "/" + get_value(upwhen, 'logfile') mention("Waiting up to " + str( timeout) + " seconds for '" + logmsg + "' in '" + logfile + "' to indicate that " + container + " is stacked") else: mention("Waiting up to " + str( timeout) + " seconds for '" + logmsg + "' to indicate that " + container + " is stacked") waited = 0 ok = False while waited <= timeout: if not 'logfile' in locals(): command = ["docker", "logs", get_container(container)] else: if logfile.startswith('/'): command = ["tail", logfile] else: # there's a chance we try to tail it before it exists... just ignore that time if os._exists(logfile): command = ["tail", logfile] # command may not have been set yet if the file didn't exist if 'command' in locals(): try: output = subprocess.check_output(command, stderr=subprocess.STDOUT) except: pass # print output if 'output' in locals() and output.find(logmsg) > -1: ok = True break else: time.sleep(1) waited = waited + 1 if not ok: raise Exception("Timed out waiting for " + container + " to start") if upwhen.has_key('sleep'): mention("Sleeping " + str(upwhen['sleep']) + " extra seconds as configured") time.sleep(int(upwhen['sleep']))