def main(factory: str, sha: str, targets_json: str, machines: [], platforms: [], app_root_dir: str, publish_tool: str, apps_version: str, target_tag: str, target_version: str, new_targets_file: str): convert_docker_apps() status('Searching for Compose Apps in {}'.format(app_root_dir)) apps = ComposeApps(app_root_dir) status('Found Compose Apps: {}'.format(apps.str)) status('Validating Compose Apps') apps.validate() status('Compose Apps has been validated: {}'.format(apps.str)) apps_to_add_to_target = AppsPublisher(factory, publish_tool).publish( apps, apps_version) status( 'Creating Targets that refer to the published Apps; tag: {}, version: {}, machines: {}, platforms: {} ' .format(target_tag, target_version, ','.join(machines) if machines else '[]', ','.join(platforms) if platforms else '[]')) new_targets = create_target(targets_json, apps_to_add_to_target, target_tag, sha, machines, platforms, target_version, new_targets_file) if len(new_targets) == 0: logger.error('Failed to create Targets for the published Apps') return 1 return 0
class ComposeAppsTest(unittest.TestCase): ComposeAppDesc = ''' services: nginx-01: image: hub.foundries.io/test_factory/nginx ports: - ${PORT-9999}:80 restart: always nginx-02: image: nginx:1.19.2-alpine ports: - ${PORT-8888}:80 restart: always python-www: image: hub.foundries.io/test_factory/app-07:latest ports: - 9987:80 restart: always volumes: - .:/var/http version: '3.2' ''' def setUp(self): self.apps_root_dir = tempfile.mkdtemp() self.app_name = 'app1' os.mkdir(os.path.join(self.apps_root_dir, self.app_name)) with open(os.path.join(self.apps_root_dir, self.app_name, ComposeApps.App.ComposeFile), 'w') as compose_file: yaml_data = yaml.safe_load(self.ComposeAppDesc) yaml.dump(yaml_data, compose_file) self.apps = ComposeApps(self.apps_root_dir) def tearDown(self): shutil.rmtree(self.apps_root_dir) def test_compose_apps_init(self): self.assertEqual(len(self.apps), 1) self.apps.validate() self.assertEqual(self.apps.str, self.app_name) self.assertEqual(len(self.apps), 1) def test_compose_apps_app_init(self): app = self.apps[0] app.validate() self.assertEqual(len(app.services()), 3) def test_compose_apps_app_images(self): app = self.apps[0] expected_images = ['hub.foundries.io/test_factory/nginx', 'nginx:1.19.2-alpine', 'hub.foundries.io/test_factory/app-07:latest'] for image in app.images(): self.assertIn(image, expected_images)