def BuildSelection(buildSelection, selectionToBuild): cwd = BuildTools.TryChangeToDirectoryAndGetCwd(buildSelection) oldEnvironmentVariable = BuildTools.AddEnvironmentVariablesFromSelection(buildSelection) BuildTools.HandleTerminalCommandsSelection(buildSelection) TerminalTools.LoadDefaultEnvironmentVariablesFile() if BuildTools.FILES_KEY in buildSelection: composeFiles = buildSelection[BuildTools.FILES_KEY] buildComposeFile = BuildTools.GetAvailableComposeFilename('build', selectionToBuild) DockerComposeTools.MergeComposeFiles(composeFiles, buildComposeFile) try: DockerComposeTools.DockerComposeBuild([buildComposeFile]) except: BuildTools.RemoveComposeFileIfNotPreserved(buildComposeFile, buildSelection) raise if BuildTools.ADDITIONAL_TAG_KEY in buildSelection: DockerComposeTools.TagImages(buildComposeFile, buildSelection[BuildTools.ADDITIONAL_TAG_KEY]) if BuildTools.ADDITIONAL_TAGS_KEY in buildSelection: for tag in buildSelection[BuildTools.ADDITIONAL_TAGS_KEY]: DockerComposeTools.TagImages(buildComposeFile, tag) if SAVE_IMAGES_KEY in buildSelection: outputFolder = buildSelection[SAVE_IMAGES_KEY] DockerComposeTools.SaveImages(buildComposeFile, outputFolder) if BuildTools.COMPOSE_FILE_WITH_DIGESTS_KEY in buildSelection: composeFileWithDigests = buildSelection[BuildTools.COMPOSE_FILE_WITH_DIGESTS_KEY] BuildTools.GenerateComposeFileWithDigests(composeFiles, composeFileWithDigests) BuildTools.RemoveComposeFileIfNotPreserved(buildComposeFile, buildSelection) BuildTools.RemoveEnvironmentVariables(oldEnvironmentVariable) os.chdir(cwd)
def PublishContainerSelection(publishSelection, selectionToPublish): composeFiles = publishSelection[BuildTools.FILES_KEY] publishComposeFile = BuildTools.GetAvailableComposeFilename( 'publish', selectionToPublish) DockerComposeTools.MergeComposeFiles(composeFiles, publishComposeFile) try: DockerComposeTools.PublishDockerImages(publishComposeFile) except: BuildTools.RemoveComposeFileIfNotPreserved(publishComposeFile, publishSelection) raise if BuildTools.ADDITIONAL_TAG_KEY in publishSelection: DockerComposeTools.PublishDockerImagesWithNewTag( publishComposeFile, publishSelection[BuildTools.ADDITIONAL_TAG_KEY]) if BuildTools.ADDITIONAL_TAGS_KEY in publishSelection: for tag in publishSelection[BuildTools.ADDITIONAL_TAGS_KEY]: DockerComposeTools.PublishDockerImagesWithNewTag( publishComposeFile, tag) if BuildTools.COMPOSE_FILE_WITH_DIGESTS_KEY in publishSelection: composeFileWithDigests = publishSelection[ BuildTools.COMPOSE_FILE_WITH_DIGESTS_KEY] BuildTools.GenerateComposeFileWithDigests(composeFiles, composeFileWithDigests) BuildTools.RemoveComposeFileIfNotPreserved(publishComposeFile, publishSelection)
def PromoteImageSelection(promoteSelection, selectionToPromote): print("selection to promote: {}".format(selectionToPromote)) composeFiles = promoteSelection[BuildTools.FILES_KEY] promoteComposeFile = BuildTools.GetAvailableComposeFilename( 'promote', selectionToPromote) DockerComposeTools.MergeComposeFiles(composeFiles, promoteComposeFile) sourceFeed = YamlTools.TryGetFromDictionary(promoteSelection, BuildTools.SOURCE_FEED_KEY, None) targetFeed = YamlTools.TryGetFromDictionary(promoteSelection, BuildTools.TARGET_FEED_KEY, None) user = YamlTools.TryGetFromDictionary(promoteSelection, BuildTools.USER_KEY, None) password = YamlTools.TryGetFromDictionary(promoteSelection, BuildTools.PASSWORD_KEY, None) logout = YamlTools.TryGetFromDictionary(promoteSelection, BuildTools.LOGOUT_KEY, False) dryRun = YamlTools.TryGetFromDictionary(promoteSelection, BuildTools.DRY_RUN_KEY, False) DockerComposeTools.PromoteDockerImages( composeFile=promoteComposeFile, targetTags=promoteSelection[BuildTools.TARGET_TAGS_KEY], sourceFeed=sourceFeed, targetFeed=targetFeed, user=user, password=password, logoutFromFeeds=logout, dryRun=dryRun) BuildTools.RemoveComposeFileIfNotPreserved(promoteComposeFile, promoteSelection)
def RunSelection(runSelection, selectionToRun): cwd = BuildTools.TryChangeToDirectoryAndGetCwd(runSelection) oldEnvironmentVariable = BuildTools.AddEnvironmentVariablesFromSelection( runSelection) BuildTools.HandleTerminalCommandsSelection(runSelection) TerminalTools.LoadDefaultEnvironmentVariablesFile() if BuildTools.FILES_KEY in runSelection: runComposeFile = BuildTools.GetAvailableComposeFilename( 'run', selectionToRun) composeFiles = runSelection[BuildTools.FILES_KEY] if YamlTools.TryGetFromDictionary(runSelection, VERIFY_CONTAINER_EXIT_CODE, False): containerNames = BuildTools.MergeAndPopulateWithContainerNames( composeFiles, runComposeFile) if BuildTools.CONTAINER_NAMES_KEY in runSelection: containerNames = runSelection[BuildTools.CONTAINER_NAMES_KEY] else: containerNames = [] DockerComposeTools.MergeComposeFiles(composeFiles, runComposeFile) try: DockerComposeTools.DockerComposeUp( [runComposeFile], YamlTools.TryGetFromDictionary(runSelection, ABORT_ON_CONTAINER_EXIT_KEY, True), YamlTools.TryGetFromDictionary(runSelection, DETACHED_KEY, False)) except: BuildTools.RemoveComposeFileIfNotPreserved(runComposeFile, runSelection) raise DockerImageTools.VerifyContainerExitCode(containerNames, assertExitCodes=True) BuildTools.HandleCopyFromContainer(runSelection) if YamlTools.TryGetFromDictionary(runSelection, BuildTools.REMOVE_CONTAINERS_KEY, False): DockerComposeTools.DockerComposeRemove([runComposeFile]) BuildTools.RemoveComposeFileIfNotPreserved(runComposeFile, runSelection) BuildTools.RemoveEnvironmentVariables(oldEnvironmentVariable) os.chdir(cwd)
def TestSelection(testSelection, selectionToTest): cwd = BuildTools.TryChangeToDirectoryAndGetCwd(testSelection) oldEnvironmentVariable = BuildTools.AddEnvironmentVariablesFromSelection( testSelection) BuildTools.HandleTerminalCommandsSelection(testSelection) TerminalTools.LoadDefaultEnvironmentVariablesFile() if BuildTools.FILES_KEY in testSelection: testComposeFile = BuildTools.GetAvailableComposeFilename( 'test', selectionToTest) composeFiles = testSelection[BuildTools.FILES_KEY] containerNames = BuildTools.MergeAndPopulateWithContainerNames( composeFiles, testComposeFile) if BuildTools.CONTAINER_NAMES_KEY in testSelection: containerNames = testSelection[BuildTools.CONTAINER_NAMES_KEY] try: DockerComposeTools.ExecuteComposeTests( [testComposeFile], testContainerNames=containerNames, removeTestContainers=False, buildCompose=True, downCompose=False) except: BuildTools.RemoveComposeFileIfNotPreserved(testComposeFile, testSelection) raise BuildTools.HandleCopyFromContainer(testSelection) DockerComposeTools.DockerComposeDown([testComposeFile]) if YamlTools.TryGetFromDictionary(testSelection, BuildTools.REMOVE_CONTAINERS_KEY, False): DockerComposeTools.DockerComposeRemove([testComposeFile]) BuildTools.RemoveComposeFileIfNotPreserved(testComposeFile, testSelection) BuildTools.RemoveEnvironmentVariables(oldEnvironmentVariable) os.chdir(cwd)