本文整理汇总了Python中atomic_reactor.core.DockerTasker类的典型用法代码示例。如果您正苦于以下问题:Python DockerTasker类的具体用法?Python DockerTasker怎么用?Python DockerTasker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DockerTasker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_image_info_by_name_tag_in_name
def test_get_image_info_by_name_tag_in_name():
if MOCK:
mock_docker()
t = DockerTasker()
response = t.get_image_info_by_image_name(input_image_name)
assert len(response) == 1
示例2: test_get_image_info_by_name_tag_in_name_nonexisten
def test_get_image_info_by_name_tag_in_name_nonexisten(temp_image_name):
if MOCK:
mock_docker()
t = DockerTasker()
response = t.get_image_info_by_image_name(temp_image_name)
assert len(response) == 0
示例3: test_get_image_info_by_id_nonexistent
def test_get_image_info_by_id_nonexistent():
if MOCK:
mock_docker()
t = DockerTasker()
response = t.get_image_info_by_image_id("asd")
assert response is None
示例4: test_get_version
def test_get_version():
if MOCK:
mock_docker()
t = DockerTasker()
response = t.get_info()
assert isinstance(response, dict)
示例5: test_image_doesnt_exist
def test_image_doesnt_exist():
image = "lerknglekrnglekrnglekrnglekrng"
if MOCK:
mock_docker(should_raise_error={'inspect_image': [image]})
t = DockerTasker()
assert t.image_exists(image) is False
示例6: test_inspect_image
def test_inspect_image():
if MOCK:
mock_docker()
t = DockerTasker()
inspect_data = t.inspect_image(input_image_name)
assert isinstance(inspect_data, dict)
示例7: test_tag_by_labels_plugin
def test_tag_by_labels_plugin(tmpdir, args):
if MOCK:
mock_docker()
tasker = DockerTasker()
workflow = DockerBuildWorkflow({"provider": "git", "uri": "asd"}, "test-image")
version = "1.0"
release = "1"
workflow.built_image_inspect = {
INSPECT_CONFIG: {
"Labels": {
"name": TEST_IMAGE,
"version": version,
"release": release
}
}
}
workflow.push_conf.add_docker_registry(LOCALHOST_REGISTRY, insecure=True)
image = ImageName(repo=TEST_IMAGE,
tag="%s_%s" % (version, release),
registry=LOCALHOST_REGISTRY)
setattr(workflow, 'builder', X)
runner = PostBuildPluginsRunner(
tasker,
workflow,
[{
'name': TagByLabelsPlugin.key,
'args': args,
}]
)
output = runner.run()
assert TagByLabelsPlugin.key in output.keys()
images = [i.to_str() for i in workflow.tag_conf.images]
primary_images = [i.to_str() for i in workflow.tag_conf.primary_images]
unique_images = [i.to_str() for i in workflow.tag_conf.unique_images]
if args.get('unique_tag_only'):
assert len(workflow.tag_conf.images) == 1
assert len(primary_images) == 0
else:
assert len(workflow.tag_conf.images) == 4
assert len(primary_images) == 3
assert ("%s:%s-%s" % (TEST_IMAGE, version, release)) in images
assert ("%s:%s" % (TEST_IMAGE, version)) in images
assert ("%s:latest" % (TEST_IMAGE, )) in images
assert ("%s:%s-%s" % (TEST_IMAGE, version, release)) in primary_images
assert ("%s:%s" % (TEST_IMAGE, version)) in primary_images
assert ("%s:latest" % (TEST_IMAGE, )) in primary_images
assert len(unique_images) == 1
assert ("%s:%s" % (TEST_IMAGE, "unique_tag_123")) in images
assert ("%s:%s" % (TEST_IMAGE, "unique_tag_123")) in unique_images
tasker.remove_image(image)
示例8: test_get_image_info_by_id
def test_get_image_info_by_id():
if MOCK:
mock_docker(provided_image_repotags=input_image_name.to_str())
t = DockerTasker()
image_id = t.get_image_info_by_image_name(input_image_name)[0]['Id']
response = t.get_image_info_by_image_id(image_id)
assert isinstance(response, dict)
示例9: test_get_image_info_by_name_tag_in_name_library
def test_get_image_info_by_name_tag_in_name_library():
if MOCK:
mock_docker()
t = DockerTasker()
image_name = ImageName.parse("library/busybox")
response = t.get_image_info_by_image_name(image_name)
assert len(response) == 1
示例10: test_tag_image_same_name
def test_tag_image_same_name(temp_image_name):
if MOCK:
mock_docker()
t = DockerTasker()
temp_image_name.registry = "somewhere.example.com"
temp_image_name.tag = "1"
flexmock(t.d).should_receive('tag').never()
img = t.tag_image(temp_image_name, temp_image_name.copy())
示例11: test_build_image_from_git
def test_build_image_from_git(temp_image_name):
if MOCK:
mock_docker()
t = DockerTasker()
response = t.build_image_from_git(DOCKERFILE_GIT, temp_image_name, use_cache=True)
list(response)
assert response is not None
assert t.image_exists(temp_image_name)
t.remove_image(temp_image_name)
示例12: test_pull_base_image_plugin
def test_pull_base_image_plugin(df_base, parent_registry, expected_w_reg, expected_wo_reg):
if MOCK:
mock_docker(remember_images=True)
tasker = DockerTasker()
workflow = DockerBuildWorkflow(MOCK_SOURCE, 'test-image')
workflow.builder = MockBuilder()
workflow.builder.base_image = ImageName.parse(df_base)
assert not tasker.image_exists(BASE_IMAGE)
assert not tasker.image_exists(BASE_IMAGE_W_REGISTRY)
runner = PreBuildPluginsRunner(
tasker,
workflow,
[{
'name': PullBaseImagePlugin.key,
'args': {'parent_registry': parent_registry, 'parent_registry_insecure': True}
}]
)
runner.run()
assert tasker.image_exists(BASE_IMAGE) == expected_wo_reg
assert tasker.image_exists(BASE_IMAGE_W_REGISTRY) == expected_w_reg
try:
tasker.remove_image(BASE_IMAGE)
tasker.remove_image(BASE_IMAGE_W_REGISTRY)
except:
pass
示例13: test_image_creation_local_repo
def test_image_creation_local_repo():
if MOCK:
mock_docker()
b = BuildImageBuilder(reactor_local_path=PARENT_DIR)
df_dir_path = os.path.join(PARENT_DIR, 'images', 'privileged-builder')
b.create_image(df_dir_path, TEST_BUILD_IMAGE)
dt = DockerTasker()
assert dt.image_exists(TEST_BUILD_IMAGE)
dt.remove_image(TEST_BUILD_IMAGE)
示例14: test_tag_and_push
def test_tag_and_push(temp_image_name):
if MOCK:
mock_docker()
t = DockerTasker()
temp_image_name.registry = LOCALHOST_REGISTRY
temp_image_name.tag = "1"
output = t.tag_and_push_image(INPUT_IMAGE, temp_image_name, insecure=True)
assert output is not None
assert t.image_exists(temp_image_name)
t.remove_image(temp_image_name)
示例15: test_tag_and_push_plugin
def test_tag_and_push_plugin(tmpdir, image_name, logs, should_raise, use_secret):
if MOCK:
mock_docker()
flexmock(docker.Client, push=lambda iid, **kwargs: iter(logs),
login=lambda username, registry, dockercfg_path: {'Status': 'Login Succeeded'})
tasker = DockerTasker()
workflow = DockerBuildWorkflow({"provider": "git", "uri": "asd"}, TEST_IMAGE)
workflow.tag_conf.add_primary_image(image_name)
setattr(workflow, 'builder', X)
secret_path = None
if use_secret:
temp_dir = mkdtemp()
with open(os.path.join(temp_dir, ".dockercfg"), "w+") as dockerconfig:
dockerconfig_contents = {
LOCALHOST_REGISTRY: {
"username": "user", "email": "[email protected]", "password": "mypassword"}}
dockerconfig.write(json.dumps(dockerconfig_contents))
dockerconfig.flush()
secret_path = temp_dir
runner = PostBuildPluginsRunner(
tasker,
workflow,
[{
'name': TagAndPushPlugin.key,
'args': {
'registries': {
LOCALHOST_REGISTRY: {
'insecure': True,
'secret': secret_path
}
}
},
}]
)
if should_raise:
with pytest.raises(Exception):
runner.run()
else:
output = runner.run()
image = output[TagAndPushPlugin.key][0]
tasker.remove_image(image)
assert len(workflow.push_conf.docker_registries) > 0
if MOCK:
# we only test this when mocking docker because we don't expect
# running actual docker against v2 registry
assert workflow.push_conf.docker_registries[0].digests[image_name] == DIGEST1