Example #1
0
def test_cache_fallback(twin_simple_targets, docker_client):
    image1, image2 = twin_simple_targets

    run_docker_make('-f data/simple.yml simple-target'
                    ' --cache-repo fakerepo --cache-tag faketag')
    final_image = docker_client.images.get('simple-target')
    assert final_image.id == image2.id
Example #2
0
def test_paths_relative_interpreted_relative_to_definition_file(img2):
    run_docker_make("-f data/include.yml target_include")
    helpers.assert_file_content(
        "target_include",
        "/opt/testfile.txt",
        "this is a file used in tests for relative path resolution",
    )
Example #3
0
def test_secret_files(experimental_daemon, hassecrets):
    run_docker_make('-f data/secret-squash.yml has-secrets')
    foundfiles = helpers.find_files_in_layers('has-secrets', [
        '/root/secret1', '/root/secretdir/secretfile', '/root/copy-of-secret1'
    ])
    assert not foundfiles['/root/secret1']
    assert not foundfiles['/root/secretdir/secretfile']
    assert foundfiles['/root/copy-of-secret1']
Example #4
0
def test_explicit_all(alltest):
    run_docker_make("-f data/explicit_all.yml --all")
    for s in "t1 t3".split():
        helpers.assert_file_content(s, "/opt/%s" % s, s)
    client = helpers.get_client()
    for s in "t2 t4".split():
        with pytest.raises(docker.errors.ImageNotFound):
            client.images.get(s)
Example #5
0
def test_explicit_cache_from(twin_simple_targets, docker_client, clean8):
    image1, image2 = twin_simple_targets
    image1.tag('img1repo/simple-target', tag='img1tag')
    image2.tag('img2repo/simple-target', tag='img2tag')

    run_docker_make('-f data/simple.yml simple-target'
                    ' --cache-repo img1repo --cache-tag img1tag')
    final_image = docker_client.images.get('simple-target')
    assert final_image.id == image1.id
Example #6
0
def test_explicit_cache_from(twin_simple_targets, docker_client, clean8):
    image1, image2 = twin_simple_targets
    image1.tag("img1repo/simple-target", tag="img1tag")
    image2.tag("img2repo/simple-target", tag="img2tag")

    run_docker_make(
        "-f data/simple.yml simple-target --cache-repo img1repo --cache-tag img1tag"
    )
    final_image = docker_client.images.get("simple-target")
    assert final_image.id == image1.id
Example #7
0
def test_secret_files(experimental_daemon, hassecrets):
    run_docker_make("-f data/secret-squash.yml has-secrets")
    foundfiles = helpers.find_files_in_layers(
        "has-secrets",
        [
            "/root/secret1", "/root/secretdir/secretfile",
            "/root/copy-of-secret1"
        ],
    )
    assert not foundfiles["/root/secret1"]
    assert not foundfiles["/root/secretdir/secretfile"]
    assert foundfiles["/root/copy-of-secret1"]
Example #8
0
def test_squashed_secrets(experimental_daemon, squashimgs):
    run_docker_make(
        "-f data/secret-squash.yml invisible-secret visible-secret")
    files_to_find = ["/opt/a", "/root/c", "/root/copy-c"]

    visfiles = helpers.find_files_in_layers("visible-secret", files_to_find)
    assert visfiles["/opt/a"]
    assert not visfiles["/root/c"]
    assert not visfiles["/root/copy-c"]

    invisfiles = helpers.find_files_in_layers("invisible-secret",
                                              files_to_find)
    assert invisfiles["/opt/a"]
    assert not invisfiles["/root/c"]
    assert invisfiles["/root/copy-c"]
Example #9
0
def test_squashed_secrets(experimental_daemon, squashimgs):
    run_docker_make(
        '-f data/secret-squash.yml invisible-secret visible-secret')
    files_to_find = ['/opt/a', '/root/c', '/root/copy-c']

    visfiles = helpers.find_files_in_layers('visible-secret', files_to_find)
    assert visfiles['/opt/a']
    assert not visfiles['/root/c']
    assert not visfiles['/root/copy-c']

    invisfiles = helpers.find_files_in_layers('invisible-secret',
                                              files_to_find)
    assert invisfiles['/opt/a']
    assert not invisfiles['/root/c']
    assert invisfiles['/root/copy-c']
Example #10
0
def test_handle_missing_squash_cache(experimental_daemon, squashcache):
    run_docker_make("-f data/secret-squash.yml cache-test invisible-secret")
    client = helpers.get_client()
    cachelayer = client.images.get("invisible-secret")
    firstimg = client.images.get("cache-test")
    for _id in ("cache-test", firstimg.id, "invisible_secret", cachelayer.id):
        try:
            client.images.remove(_id)
        except docker.errors.ImageNotFound:
            pass

    # Make sure the image can rebuild even if original layers are missing
    run_docker_make("-f data/secret-squash.yml cache-test")

    # Sanity check - makes sure that the first image was in fact removed and not used for cache
    assert client.images.get("cache-test").id != firstimg.id
Example #11
0
def test_paths_relative_interpreted_relative_to_definition_file(img2):
    run_docker_make('-f data/include.yml target_include')
    assert_file_content(
        'target_include', '/opt/testfile.txt',
        'this is a file used in tests for relative path resolution')
Example #12
0
def test_multiple_bases(img1):
    run_docker_make('-f data/multibase.yml target2_bases target3_bases')
    assert_file_content('target2_bases', '/opt/success', 'success2')
    assert_file_content('target3_bases', '/opt/success', 'success3')
Example #13
0
def test_keep_build_tags(twostep, docker_client):
    run_docker_make('-f data/twostep.yml target-twostep --keep-build-tags')
    docker_client.images.get('dmkbuild_target-twostep_1')
    docker_client.images.get('dmkbuild_target-twostep_2')
Example #14
0
def test_build_args(buildargs):
    run_docker_make(
        '-f data/build-args.yml --build-arg FILENAME=hello-world.txt target-buildargs'
    )
    assert_file_content('target-buildargs', 'hello-world.txt', 'hello world')
Example #15
0
def test_multiple_bases(img1):
    run_docker_make("-f data/multibase.yml target2_bases target3_bases")
    helpers.assert_file_content("target2_bases", "/opt/success", "success2")
    helpers.assert_file_content("target3_bases", "/opt/success", "success3")
Example #16
0
def test_regular_ignore(img5):
    run_docker_make("-f data/ignores.yml target_regular_ignore")
    _check_files("target_regular_ignore", a=False, b=False)
Example #17
0
def test_keep_build_tags(twostep, docker_client):
    run_docker_make("-f data/twostep.yml target-twostep --keep-build-tags")
    assert docker_client.images.list("1.target-twostep.dmk")
    assert docker_client.images.list("2.target-twostep.dmk")
Example #18
0
def test_dockerfile_write(tmpdir):
    tmpdir = str(tmpdir)
    run_docker_make('-f data/write.yml -p -n --dockerfile-dir %s writetarget' %
                    tmpdir)
    assert os.path.isfile(os.path.join(tmpdir, 'Dockerfile.writetarget'))
Example #19
0
def test_error_if_copy_with_secrets(copy_with_secrets):
    with pytest.raises(dockermake.errors.ParsingFailure):
        run_docker_make("-f data/copy_with_secrets.yml copy_with_secrets")
Example #20
0
def test_regular_ignore(img5):
    run_docker_make('-f data/ignores.yml target_regular_ignore')
    _check_files('target_regular_ignore', a=False, b=False)
Example #21
0
def test_implicit_all_with_abstract_steps(abstract_steps):
    run_docker_make("-f data/abstract-steps.yml --all")
    client = helpers.get_client()
    client.images.get("definite")
    with pytest.raises(docker.errors.ImageNotFound):
        client.images.get("abstract")
Example #22
0
def test_build_args(buildargs):
    run_docker_make(
        "-f data/build-args.yml --build-arg FILENAME=hello-world.txt target-buildargs"
    )
    helpers.assert_file_content("target-buildargs", "hello-world.txt",
                                "hello world")
Example #23
0
def test_ignore_string(img3):
    run_docker_make('-f data/ignores.yml target_ignore_string')
    _check_files('target_ignore_string', b=False)
Example #24
0
def test_ignore_directory(img6):
    run_docker_make("-f data/ignores.yml target_ignore_directory")
    _check_files("target_ignore_directory", d=False)
Example #25
0
def test_ignorefile(img4):
    run_docker_make('-f data/ignores.yml target_ignorefile')
    _check_files('target_ignorefile', c=False)
Example #26
0
def test_implicit_all(alltest):
    run_docker_make("-f data/implicit_all.yml --all")
    for s in "t1 t2 t3 t4".split():
        helpers.assert_file_content(s, "/opt/%s" % s, s)
Example #27
0
def test_ignore_directory(img6):
    run_docker_make('-f data/ignores.yml target_ignore_directory')
    _check_files('target_ignore_directory', d=False)
Example #28
0
def test_ignore_string(img3):
    run_docker_make("-f data/ignores.yml target_ignore_string")
    _check_files("target_ignore_string", b=False)
Example #29
0
def twin_simple_targets(img7, docker_client):
    run_docker_make('-f data/simple.yml simple-target')
    image1 = docker_client.images.get('simple-target')
    run_docker_make('-f data/simple.yml simple-target --no-cache')
    image2 = docker_client.images.get('simple-target')
    return image1, image2
Example #30
0
def test_ignorefile(img4):
    run_docker_make("-f data/ignores.yml target_ignorefile")
    _check_files("target_ignorefile", c=False)