Beispiel #1
0
def BuildDocker(buildSelection):
    VersionTools.ExportVersionFromChangelogToEnvironment(
        'CHANGELOG.md', 'VERSION')
    srcFolder = ['src', '..']
    miniSwarmManagementFile = 'swarm-management.yml'
    migratorComposeFiles = ['docker-compose.migrator.yml']
    nugetDockerComposeFiles = ['docker-compose.publish.nuget.yml']
    generalComposeFiles = [
        'docker-compose.message.handler.yml',
        'docker-compose.outboxcleaner.yml',
        'docker-compose.message.spammer.yml'
    ]

    if buildSelection == 'run':
        os.chdir(srcFolder[0])
        DockerComposeTools.DockerComposeUp(migratorComposeFiles)
        DockerComposeTools.DockerComposeUp(generalComposeFiles)
        os.chdir(srcFolder[1])

    elif buildSelection == 'build':
        os.chdir(srcFolder[0])
        DockerComposeTools.DockerComposeBuild(generalComposeFiles +
                                              migratorComposeFiles)
        os.chdir(srcFolder[1])

    elif buildSelection == 'test':
        os.chdir(srcFolder[0])
        DockerComposeTools.ExecuteComposeTests(['docker-compose.tests.yml'],
                                               ['saferebus-tests'])
        os.chdir(srcFolder[1])

    elif buildSelection == 'publish':
        os.chdir(srcFolder[0])
        DockerComposeTools.DockerComposeBuild(nugetDockerComposeFiles)
        DockerComposeTools.DockerComposeUp(nugetDockerComposeFiles, False)
        os.chdir(srcFolder[1])

    elif buildSelection == 'start-dev':
        os.chdir(srcFolder[0] + '/ServiceDependencies')
        SwarmManager.HandleManagement(
            ['-start', '-f', miniSwarmManagementFile])
        os.chdir(srcFolder[1] + '/..')

    elif buildSelection == 'stop-dev':
        os.chdir(srcFolder[0] + '/ServiceDependencies')
        SwarmManager.HandleManagement(['-stop', '-f', miniSwarmManagementFile])
        os.chdir(srcFolder[1] + '/..')

    elif buildSelection == 'help':
        TerminalTools.PrintAvailableCommands(AvailableCommands)

    else:
        print('Please provide a valid build argument: ')
        BuildDocker('help')
Beispiel #2
0
    def test_RunStacks(self):
        cacheFolder = 'tests/cacheFolder'
        shutil.rmtree(cacheFolder, ignore_errors=True)

        DockerComposeTools.DockerComposeBuild(
            ["tests/testBatchStacks/docker-compose.batch.1.0.0.yml"])
        defaultArgs = [
            '--cache', cacheFolder, '--source', 'tests/testBatchStacks',
            '--user', 'dummy:password', '-i',
            'tests/testBatchStacks/swarm.management.yml'
        ]
        self.assertTrue(os.path.isdir('tests/testBatchStacks'))

        args = ['init'] + defaultArgs
        Main.Main(args)
        TestUtilities.AssertInfrastructureExists(True)

        os.environ['SHOULD_FAIL'] = 'false'
        os.environ['SHOULD_FAIL_2'] = 'false'
        args = ['run', 'batch'] + defaultArgs
        Main.Main(args)

        os.environ['SHOULD_FAIL'] = 'true'
        os.environ['SHOULD_FAIL_2'] = 'false'
        args = ['run', 'batch'] + defaultArgs
        self.assertRaises(Exception, Main.Main, args)
Beispiel #3
0
 def test_a_ComposeBuild(self):
     print('COMPOSE BUILD')
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     DockerComposeTools.DockerComposeBuild(
         [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')])
     print('DONE COMPOSE BUILD')
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)
Beispiel #5
0
def BuildSelection(buildSelection, selectionToBuild):
    cwd = BuildTools.TryChangeToDirectoryAndGetCwd(buildSelection)
    composeFiles = buildSelection[BuildTools.FILES_KEY]
    buildComposeFile = 'docker-compose.build.' + selectionToBuild + '.yml'
    DockerComposeTools.MergeComposeFiles(composeFiles, buildComposeFile)
    DockerComposeTools.DockerComposeBuild([buildComposeFile])
    if BuildTools.ADDITIONAL_TAG_KEY in buildSelection:
        DockerComposeTools.TagImages(buildComposeFile, buildSelection[BuildTools.ADDITIONAL_TAG_KEY])
    os.chdir(cwd)
 def test_f_CreateRemoveStack(self):
     print('CREATE STACK')
     stack = 'test-stack-' + str(random.randint(0, 10000))
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     DockerComposeTools.DockerComposeBuild(
         [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')])
     DockerSwarmTools.DeployStack(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml'),
         stack)
     DockerSwarmTools.RemoveStack(stack)
     print('DONE CREATE STACK')
Beispiel #7
0
    def test_Run(self):
        DockerComposeTools.DockerComposeBuild(
            ["tests/testBatchStacks/docker-compose.batch.1.0.0.yml"])
        handler: StackHandler = TestUtilities.CreateStackHandler(
            source="tests/testBatchStacks",
            swmInfrastructureFiles=[
                "tests/testBatchStacks/swarm.management,yml"
            ])
        handler.Init()
        os.environ['SHOULD_FAIL'] = 'false'
        self.assertTrue(handler.Run())

        os.environ['SHOULD_FAIL'] = 'true'
        self.assertFalse(handler.Run(['batch==1.0.0']))
def BuildDocker(buildSelection):
    srcFolder = ['src', '..']
    miniSwarmManagementFile = 'swarm-management.yml'
    migratorComposeFiles = [
        'docker-compose.migrator.yml'
    ]
    generalComposeFiles = [
        'docker-compose.yml'
    ]

    if buildSelection == 'run':
        os.chdir(srcFolder[0])
        DockerComposeTools.DockerComposeUp(migratorComposeFiles)
        DockerComposeTools.DockerComposeUp(generalComposeFiles)
        os.chdir(srcFolder[1])
    
    elif buildSelection == 'build':
        os.chdir(srcFolder[0])
        DockerComposeTools.DockerComposeBuild(generalComposeFiles + migratorComposeFiles)
        os.chdir(srcFolder[1])

    elif buildSelection == 'test':
        os.chdir(srcFolder[0])
        DockerComposeTools.ExecuteComposeTests(
            ['docker-compose.tests.yml'], ['kafkaoncontainers-tests'])
        os.chdir(srcFolder[1])

    elif buildSelection == 'start-dev':
        os.chdir(srcFolder[0] + '/ServiceDependencies')
        SwarmManager.HandleManagement(['-start', '-f', miniSwarmManagementFile])
        os.chdir(srcFolder[1] + '/..')

    elif buildSelection == 'stop-dev':
        os.chdir(srcFolder[0] + '/ServiceDependencies')
        SwarmManager.HandleManagement(['-stop', '-f', miniSwarmManagementFile])
        os.chdir(srcFolder[1] + '/..')

    elif buildSelection == 'help':
        TerminalTools.PrintAvailableCommands(AvailableCommands)

    else:
        print('Please provide a valid build argument: ')
        BuildDocker('help')
def BuildSelection(buildSelection, selectionToBuild):
    cwd = BuildTools.TryChangeToDirectoryAndGetCwd(buildSelection)
    BuildTools.HandleTerminalCommandsSelection(buildSelection)

    if BuildTools.FILES_KEY in buildSelection:
        composeFiles = buildSelection[BuildTools.FILES_KEY]
        buildComposeFile = 'docker-compose.build.' + selectionToBuild + '.yml'
        DockerComposeTools.MergeComposeFiles(composeFiles, buildComposeFile)
        DockerComposeTools.DockerComposeBuild([buildComposeFile])
        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)

    os.chdir(cwd)
Beispiel #10
0
def PublishArtifactSelection(publishSelection):
    DockerComposeTools.DockerComposeBuild(
        publishSelection[BuildTools.FILES_KEY])
    DockerComposeTools.DockerComposeUp(publishSelection[BuildTools.FILES_KEY],
                                       False)