示例#1
0
def generic_build_params():
    return BuildParams.from_dict({
        "source_type": "dockerfile",
        "source_url": "https://raw.githubusercontent.com/mihaTrajbaric/image-builder-test-files/master/no_context/Dockerfile",
        "target_image_name": "tests/no_context",
        "target_image_tag": "latest"
    })
 def test_dockerfile_2(self):
     build_params = {
         "source_type": "dockerfile",
         "source_url": "https://link/to/Dockerfile",
         "target_image_name": "my_image_name",
         "target_image_tag": "my_image_tag"
     }
     valid, message = validate(BuildParams.from_dict(build_params))
     assert valid
     assert message == ''
示例#3
0
def json_to_yaml(test_path: Path, registry_ip: str):
    """
    transforms json test to yaml test
    """
    json_test = json.load(test_path.open('r'))

    yaml_test = transform_build_params(BuildParams.from_dict(json_test))
    yaml_test['target']['registry_ip'] = registry_ip
    yaml_test['custom_workdir'] = 'workdir'

    return yaml_test
 def test_tar(self):
     build_params = {
         "source_type": "tar",
         "source_url": "https://link/to/my_image.tar",
         "source_username": "******",
         "source_password": "******",
         "target_image_name": "my_image_name",
         "target_image_tag": "my_image_tag"
     }
     valid, message = validate(BuildParams.from_dict(build_params))
     assert valid
     assert message == ''
示例#5
0
def generic_invocation():
    now = datetime.datetime.now(tz=datetime.timezone.utc)
    inv = Invocation()
    inv.invocation_id = uuid.uuid4()
    inv.build_params = BuildParams.from_dict({
        "source_type": "dockerfile",
        "source_url": "https://raw.githubusercontent.com/mihaTrajbaric/image-builder-test-files/master/no_context/Dockerfile",
        "target_image_name": "tests/no_context",
        "target_image_tag": "latest"
    })
    inv.state = InvocationState.PENDING
    inv.timestamp_submission = now.isoformat()
    inv.response = None
    return inv
def post_build():
    """Request building image

    :rtype: Invocation
    """
    build_params = BuildParams.from_dict(connexion.request.get_json())
    valid, message = validate(build_params)
    if not valid:
        return message, 400

    logger.debug(json.dumps(build_params.to_dict(), indent=2))

    inv = invocation_service.invoke(build_params)

    return BuildingStarted(inv.invocation_id), 202
 def test_git(self):
     build_params = {
         "source_type": "git",
         "source_repo": {
             "url": "https://url/to/repo.git",
             "username": "******",
             "password": "******",
             "dockerfile": "path/to/Dockerfile",
             "workdir": "."
         },
         "target_image_name": "my_image_name",
         "target_image_tag": "my_image_tag"
     }
     valid, message = validate(BuildParams.from_dict(build_params))
     assert valid
     assert message == ''
 def test_dockerfile_1(self):
     build_params = {
         "source_type": "dockerfile",
         "source_url": "https://link/to/Dockerfile",
         "source_username": "******",
         "source_password": "******",
         "build_context": {
             "url": "https://url/to/git/repo/with/build_context.git",
             "username": "******",
             "password": "******"
         },
         "target_image_name": "my_image_name",
         "target_image_tag": "my_image_tag"
     }
     valid, message = validate(BuildParams.from_dict(build_params))
     assert valid
     assert message == ''
示例#9
0
def json_to_yaml(json_dir: Path,
                 yaml_dir: Path,
                 registry_ip: str = 'localhost:5000'):
    """
    Converts JSON build params (for API) from json_dir to YAML input files (for TOSCA) and saves them to yaml_dir
    """
    Settings.registry_ip = registry_ip
    json_files = [path for path in json_dir.rglob('*') if path.is_file()]
    print('Converting...')
    for file_path in json_files:
        build_params = json.load(file_path.open('r'))
        transformed = transform_build_params(
            BuildParams.from_dict(build_params))
        new_path = Path(
            str(file_path).replace(str(json_dir),
                                   str(yaml_dir)).replace('.json', '.yaml'))
        print(f'{file_path.relative_to(json_dir)}')
        if not new_path.parent.exists():
            os.makedirs(new_path.parent, exist_ok=True)
        yaml.dump(transformed, new_path.open('w'))
    print('done.')
示例#10
0
 def test_fail(self):
     build_params = {
         "source_type":
         "git",
         "build_context": {
             "url": "build_context_url",
             "username": "******",
             "password": "******",
             "subdir": "build_context_workdir"
         },
         "source_password":
         "******",
         "source_repo": {
             "url": "repo_url",
             "username": "******",
             "password": "******",
             "workdir": "docker_workdir",
             "dockerfile": "git_dockerfile"
         },
         "source_url":
         "source_url",
         "source_username":
         "******",
         "target_image_name":
         "target_image_name",
         "target_image_tag":
         "latest",
         "target_images": [{
             "base": "base",
             "image": "image",
             "tag": "tag"
         }, {
             "base": "base",
             "image": "image",
             "tag": "tag"
         }]
     }
     valid, message = validate(BuildParams.from_dict(build_params))
     assert not valid
     assert message != ''