Ejemplo n.º 1
0
 def test_GetMergedYamlData(self):
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     files = [
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml'),
         os.path.join(TestTools.TEST_SAMPLE_FOLDER,
                      'docker-compose.override.yml')
     ]
     yamlData = YamlTools.GetYamlData(files)
     self.assertTrue(
         'my-service' in YamlTools.GetProperties('services', yamlData))
     self.assertTrue('my_repo/my.service:1.0.0' == yamlData['services']
                     ['my-service']['image'])
     self.assertTrue('new-my-service' == yamlData['services']['my-service']
                     ['container_name'])
     self.assertTrue(
         len(yamlData['services']['my-service']['networks']) == 2)
     self.assertTrue(
         'new_network' in yamlData['services']['my-service']['networks'])
     self.assertTrue('backend_network' in yamlData['services']['my-service']
                     ['networks'])
     YamlTools.DumpYamlDataToFile(
         yamlData,
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'output',
                      'docker-compose.merged.yml'))
Ejemplo n.º 2
0
 def test_c_ComposeRemove(self):
     print('COMPOSE REMOVE')
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     DockerComposeTools.DockerComposeRemove(
         [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')])
     print('DONE COMPOSE REMOVE')
Ejemplo n.º 3
0
 def test_f_ComposeTest(self):
     print('COMPOSE TEST')
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     DockerComposeTools.ExecuteComposeTests(
         [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')],
         ['my-service'])
     print('DONE COMPOSE TEST')
Ejemplo n.º 4
0
 def test_d_TagImages(self):
     print('COMPOSE TAG')
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     DockerComposeTools.TagImages(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml'),
         '1.0.0')
     print('DONE COMPOSE TAG')
Ejemplo n.º 5
0
def LoadEnvironmentVariables(
        arguments, defaultYamlFiles=DEFAULT_SWARM_MANAGEMENT_YAML_FILES):
    yamlData = LoadYamlDataFromFiles(arguments, defaultYamlFiles, True)
    environmentFiles = GetEnvironmnetVariablesFiles(arguments, yamlData)
    for environmentFile in environmentFiles:
        if os.path.isfile(environmentFile):
            TerminalTools.LoadEnvironmentVariables(environmentFile)
        elif '=' in environmentFile:
            key, value = environmentFile.split('=')
            os.environ[key] = value
Ejemplo n.º 6
0
 def test_e_SaveImages(self):
     print('COMPOSE SAVE')
     folder = os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'output')
     print(folder)
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     DockerComposeTools.SaveImages(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml'),
         folder)
     self.assertTrue(
         os.path.isfile(os.path.join(folder, 'my.service-1.0.0.tar')))
     print('DONE COMPOSE SAVE')
Ejemplo n.º 7
0
def DeployStack(composeFile,
                stackName,
                environmentVariablesFiles=[],
                withRegistryAuth=False):
    for environmentVariablesFile in environmentVariablesFiles:
        TerminalTools.LoadEnvironmentVariables(environmentVariablesFile)
    print("Deploying stack: " + stackName)
    dockerCommand = "docker stack deploy -c " + composeFile
    if withRegistryAuth:
        dockerCommand += " --with-registry-auth"
    dockerCommand += " " + stackName
    TerminalTools.ExecuteTerminalCommands([dockerCommand], True)
 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')
Ejemplo n.º 9
0
 def test_GetYamlData(self):
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     yamlData = YamlTools.GetYamlData(
         [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')])
     self.assertTrue(
         'my-service' in YamlTools.GetProperties('services', yamlData))
     self.assertTrue('my_repo/my.service:1.0.0' == yamlData['services']
                     ['my-service']['image'])
     self.assertTrue('env_value' == yamlData['services']['my-service']
                     ['environment']['SOME_VARIABLE'])
     self.assertTrue('default_value' == yamlData['services']['my-service']
                     ['environment']['SOME_VARIABLE_2'])
Ejemplo n.º 10
0
 def test_g_ComposeTestWithContainerNamesNotSet(self):
     print('COMPOSE TEST UNKNOWN NAME')
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     yamlData = YamlTools.GetYamlData([
         os.path.join(TestTools.TEST_SAMPLE_FOLDER,
                      'docker-compose.test.yml')
     ])
     DockerComposeTools.AddContainerNames(yamlData)
     YamlTools.DumpYamlDataToFile(
         yamlData,
         os.path.join(TestTools.TEST_SAMPLE_FOLDER,
                      'docker-compose.test.temp.yml'))
     DockerComposeTools.ExecuteComposeTests([
         os.path.join(TestTools.TEST_SAMPLE_FOLDER,
                      'docker-compose.test.temp.yml')
     ])
     print('DONE COMPOSE TEST UNKNOWN NAME')
Ejemplo n.º 11
0
 def test_h_AddDigestsToImageTags(self):
     print('COMPOSE ADD DIGESTS')
     DockerImageTools.PullImage('nginx')
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     yamlData = YamlTools.GetYamlData(
         [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')],
         replaceEnvironmentVariablesMatches=False)
     DockerComposeTools.AddDigestsToImageTags(yamlData)
     for service in yamlData['services']:
         if 'my.service' in yamlData['services'][service]['image']:
             self.assertEqual('my_repo/my.service:1.0.0',
                              yamlData['services'][service]['image'])
         else:
             self.assertTrue(
                 'nginx@sha256:' in yamlData['services'][service]['image'])
         self.assertTrue(yamlData['services'][service]['environment']
                         ['SOME_VARIABLE'] == '${SOME_ENV_VARIABLE}')
     print('DONE COMPOSE ADD DIGESTS')
Ejemplo n.º 12
0
def LoadEnvironmentVariables(
        arguments, defaultYamlFiles=DEFAULT_SWARM_MANAGEMENT_YAML_FILES):
    yamlData = LoadYamlDataFromFiles(arguments, defaultYamlFiles, True)
    environmentFiles = GetEnvironmnetVariablesFiles(arguments, yamlData)
    for environmentFile in environmentFiles:
        TerminalTools.LoadEnvironmentVariables(environmentFile)
Ejemplo n.º 13
0
 def test_LoadEnvironmentVariables(self):
     TerminalTools.LoadEnvironmentVariables(
         os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env'))
     self.assertTrue('REPO' in os.environ)