def installFromBaseImage(programName): buildImageScriptPath = paths.getBuildImageScriptPath(programName) #Report to user while True: sys.stdout.write("""\nATTENTION!!! You have asked to install the <{0}>. Doing so requires that the following shell script be run on your computer. SHELL SCRIPT PATH: <{1}> - Do quit [q] or press ENTER - Do you want to view the full contents of this shell script [v]? - Do you want to continue? (Type "run" to run the shell script) [v/run/q]: """.format(programName, paths.getBuildImageScriptPath(programName))) sys.stdout.flush() try: userInput = sys.stdin.readline().strip() if not userInput: sys.exit("\nOperation aborted. Exiting.") else: break except KeyboardInterrupt: sys.exit("\nOperation aborted. Exiting.") if userInput == "v": with open(buildImageScriptPath, 'r') as file_f: print('\n===================== SCRIPT CODE =====================\n') print(file_f.read()) print('\n===================== END SCRIPT CODE =====================\n') while True: sys.stdout.write("""SHELL SCRIPT PATH: <{0}> - Do quit [q] or press ENTER - Do you want to continue? (Type "run" to run the shell script) [run/q]: """.format(buildImageScriptPath)) sys.stdout.flush() try: userInput = sys.stdin.readline().strip() if userInput != "run": sys.exit("\nOperation aborted. Exiting.") else: break except KeyboardInterrupt: sys.exit("\nOperation aborted. Exiting.") if userInput == "run": #Do the installation via SHELL SCRIPT st = os.stat(buildImageScriptPath) os.chmod(buildImageScriptPath, stat.S_IMODE(st.st_mode) | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) subprocessExtras.subprocessCheckedCall([buildImageScriptPath])
def installProgram(programName, useCache): """ Build the docker image associated with a program and create a tiny executable to add that image to your path. """ print("Installing "+programName+" ...") programSrcDir = paths.getProgramSrcDir(programName) _DockerfilePath = paths.getDockerfilePath(programSrcDir) # Check if we use a 'Dockerfile' or a 'BuildImage.sh' if os.path.isfile(paths.getBuildImageScriptPath(programSrcDir)): installFromBaseImage(programName,programSrcDir) elif os.path.isfile(_DockerfilePath): installFromDockerfile(programName,programSrcDir,useCache) else: sys.exit("No buildfile found: There needs to be a 'Dockerfile' or a 'BuildImage.sh' in the docker-image directory.") _permissions = permissions.getPermissions(programName) # Create a small executable that just calls the real executable in the docker image. if 'executable' in _permissions: installExecutable(programName) try: lastUpdateTime = _permissions["last-update-time"] except KeyError: lastUpdateTime = installTime.currentTimeString() imageID = dockerImages.getImageID("subuser-"+programName) registry.registerProgram(programName, lastUpdateTime, imageID)
def installFromBaseImage(programName,programSrcDir): """ Build a docker base image using a script and then install that base image. """ buildImageScriptPath = paths.getBuildImageScriptPath(programSrcDir) print("""\nATTENTION! Installing <"""+programName+"""> requires that the following shell script be run on your computer: <"""+buildImageScriptPath+"""> If you do not trust this shell script do not run it as it may be faulty or malicious! - Do you want to view the full contents of this shell script [v]? - Do you want to continue? (Type "run" to run the shell script) - To quit, press [q]. [v/run/Q]: """) try: userInput = sys.stdin.readline().strip() except KeyboardInterrupt: sys.exit("\nOperation aborted. Exiting.") if userInput == "v": print('\n===================== SCRIPT CODE =====================\n') with open(buildImageScriptPath, 'r') as file_f: print(file_f.read()) print('\n===================== END SCRIPT CODE =====================\n') return installFromBaseImage(programName,programSrcDir) if userInput == "run": #Do the installation via SCRIPT st = os.stat(buildImageScriptPath) os.chmod(buildImageScriptPath, stat.S_IMODE(st.st_mode) | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) subprocessExtras.subprocessCheckedCall([buildImageScriptPath]) return sys.exit("Will not run install script. Nothing to do. Exiting.")
def installProgram(programName, useCache): """ Build the docker image associated with a program and create a tiny executable to add that image to your path. """ print("Installing {0} ...".format(programName)) dockerImageDir = os.path.join(paths.getProgramSrcDir(programName), "docker-image") _DockerfilePath = os.path.join(dockerImageDir, 'Dockerfile') # Check if we use a 'Dockerfile' or a 'BuildImage.sh' if os.path.isfile(paths.getBuildImageScriptPath(programName)): installFromBaseImage(programName, cacheArg) elif os.path.isfile(_DockerfilePath): if useCache: cacheArg = "--no-cache=false" else: cacheArg = "--no-cache=true" docker.runDockerAndExitIfItFails(["build","-rm",cacheArg,"--tag=subuser-"+programName+"",dockerImageDir]) else: sys.exit("No buildfile found: need one of: 'Dockerfile' or 'BuildImage.sh'. PATH: {0}".format(dockerImageDir)) _permissions = permissions.getPermissions(programName) # Create a small executable that just calls the real executable in the docker image. if 'executable' in _permissions: installExecutable(programName) try: lastUpdateTime = _permissions["last-update-time"] except KeyError: lastUpdateTime = installTime.currentTimeString() imageID = dockerImages.getImageID("subuser-{0}".format(programName)) registry.registerProgram(programName, lastUpdateTime, imageID)