def test_docker_build_image_fails():
    template = ("""
        FROM bioconda/bioconda-utils-build-env
        RUN nonexistent command
        """)
    with pytest.raises(sp.CalledProcessError):
        docker_utils.RecipeBuilder(dockerfile_template=template)
def single_build(request, recipes_fixture):
    """
    Builds the "one" recipe.
    """
    if request.param:
        logger.error("Making recipe builder")
        docker_builder = docker_utils.RecipeBuilder(
            use_host_conda_bld=True, docker_base_image=DOCKER_BASE_IMAGE)
        mulled_test = True
        logger.error("DONE")
    else:
        docker_builder = None
        mulled_test = False
    logger.error("Fixture: Building 'one' %s",
                 "within docker" if docker_builder else "locally")
    build.build(
        recipe=recipes_fixture.recipe_dirs['one'],
        pkg_paths=recipes_fixture.pkgs['one'],
        docker_builder=docker_builder,
        mulled_test=mulled_test,
    )
    logger.error("Fixture: Building 'one' %s -- DONE",
                 "within docker" if docker_builder else "locally")
    yield recipes_fixture.pkgs['one']
    for pkg in recipes_fixture.pkgs['one']:
        ensure_missing(pkg)
def multi_build(request, recipes_fixture, config_fixture):
    """
    Builds the "one", "two", and "three" recipes.
    """
    if request.param:
        docker_builder = docker_utils.RecipeBuilder(
            use_host_conda_bld=True, docker_base_image=DOCKER_BASE_IMAGE)
        mulled_test = True
    else:
        docker_builder = None
        mulled_test = False
    logger.error("Fixture: Building one/two/three %s",
                 "within docker" if docker_builder else "locally")
    build.build_recipes(recipes_fixture.basedir,
                        config_fixture,
                        recipes_fixture.recipe_dirnames,
                        docker_builder=docker_builder,
                        mulled_test=mulled_test)
    logger.error("Fixture: Building one/two/three %s -- DONE",
                 "within docker" if docker_builder else "locally")
    built_packages = recipes_fixture.pkgs
    yield built_packages
    for pkgs in built_packages.values():
        for pkg in pkgs:
            ensure_missing(pkg)
def test_docker_build_image_fails():
    template = (f"""
        FROM {DOCKER_BASE_IMAGE}
        RUN nonexistent command
        """)
    with pytest.raises(sp.CalledProcessError):
        docker_utils.RecipeBuilder(dockerfile_template=template,
                                   build_image=True)
Exemple #5
0
def test_docker_build_image_fails():
    template = ("""
        FROM {self.image}
        RUN nonexistent command
        """)
    with pytest.raises(sp.CalledProcessError):
        docker_builder = docker_utils.RecipeBuilder(
            dockerfile_template=template)
Exemple #6
0
def test_docker_builder_build(recipes_fixture):
    """
    Tests just the build_recipe method of a RecipeBuilder object.
    """
    docker_builder = docker_utils.RecipeBuilder(use_host_conda_bld=True)
    pkg = os.path.basename(recipes_fixture.pkgs['one'])
    docker_builder.build_recipe(
        recipes_fixture.recipe_dirs['one'], build_args='', pkg=pkg, env={})
    assert os.path.exists(recipes_fixture.pkgs['one'])
def test_docker_build_fails(recipes_fixture):
    "test for expected failure when a recipe fails to build"
    docker_builder = docker_utils.RecipeBuilder(build_script_template="exit 1")
    assert docker_builder.build_script_template == 'exit 1'
    result = build.build_recipes(
        recipes_fixture.basedir,
        config={},
        docker_builder=docker_builder,
        mulled_test=True,
    )
    assert not result
def test_docker_builder_build(recipes_fixture):
    """
    Tests just the build_recipe method of a RecipeBuilder object.
    """
    docker_builder = docker_utils.RecipeBuilder(
        use_host_conda_bld=True, docker_base_image=DOCKER_BASE_IMAGE)
    pkgs = recipes_fixture.pkgs['one']
    docker_builder.build_recipe(recipes_fixture.recipe_dirs['one'],
                                build_args='',
                                env={})
    for pkg in pkgs:
        assert os.path.exists(pkg)
def test_docker_build_fails(recipes_fixture, config_fixture):
    """
    Test for expected failure when a recipe fails to build
    """
    docker_builder = docker_utils.RecipeBuilder(
        docker_base_image=DOCKER_BASE_IMAGE, build_script_template="exit 1")
    assert docker_builder.build_script_template == 'exit 1'
    result = build.build_recipes(recipes_fixture.basedir,
                                 config_fixture,
                                 recipes_fixture.recipe_dirnames,
                                 docker_builder=docker_builder,
                                 mulled_test=True)
    assert not result
Exemple #10
0
def test_docker_build_fails(recipes_fixture, config_fixture):
    "test for expected failure when a recipe fails to build"
    docker_builder = docker_utils.RecipeBuilder(
        docker_base_image="bioconda-utils-build-env:latest",
        build_script_template="exit 1")
    assert docker_builder.build_script_template == 'exit 1'
    result = build.build_recipes(
        recipes_fixture.basedir,
        config=config_fixture,
        docker_builder=docker_builder,
        mulled_test=True,
    )
    assert not result
Exemple #11
0
def multi_build(request, recipes_fixture):
    """
    Builds the "one", "two", and "three" recipes.
    """
    if request.param:
        docker_builder = docker_utils.RecipeBuilder(use_host_conda_bld=True)
    else:
        docker_builder = None
    build.build_recipes(
        recipe_folder=recipes_fixture.basedir,
        docker_builder=docker_builder,
        config={},
    )
    built_packages = recipes_fixture.pkgs
    yield built_packages
    for v in built_packages.values():
        ensure_missing(v)
def single_build(request, recipes_fixture):
    """
    Builds the "one" recipe.
    """
    env_matrix = list(utils.EnvMatrix(tmp_env_matrix()))[0]
    if request.param:
        docker_builder = docker_utils.RecipeBuilder(use_host_conda_bld=True)
    else:
        docker_builder = None
    build.build(
        recipe=recipes_fixture.recipe_dirs['one'],
        recipe_folder='.',
        docker_builder=docker_builder,
        env=env_matrix,
    )
    built_package = recipes_fixture.pkgs['one']
    yield built_package
    ensure_missing(built_package)
Exemple #13
0
def test_build_container_no_default_gcc(tmpdir):
    r = Recipes(
        """
        one:
          meta.yaml: |
            package:
              name: one
              version: 0.1
            test:
              commands:
                - gcc --version
        """, from_string=True)
    r.write_recipes()

    # Tests with the repository's Dockerfile instead of already uploaded images.
    # Copy repository to image build directory so everything is in docker context.
    image_build_dir = os.path.join(tmpdir, "repo")
    src_repo_dir = os.path.join(os.path.dirname(__file__), "..")
    shutil.copytree(src_repo_dir, image_build_dir)
    # Dockerfile will be recreated by RecipeBuilder => extract template and delete file
    dockerfile = os.path.join(image_build_dir, "Dockerfile")
    with open(dockerfile) as f:
        dockerfile_template = f.read().replace("{", "{{").replace("}", "}}")
    os.remove(dockerfile)

    docker_builder = docker_utils.RecipeBuilder(
        dockerfile_template=dockerfile_template,
        use_host_conda_bld=True,
        image_build_dir=image_build_dir,
    )

    pkg_paths = utils.built_package_paths(r.recipe_dirs['one'])
    build_result = build.build(
        recipe=r.recipe_dirs['one'],
        pkg_paths=pkg_paths,
        docker_builder=docker_builder,
        mulled_test=False,
    )
    assert build_result.success

    for k, v in r.recipe_dirs.items():
        for i in utils.built_package_paths(v):
            assert os.path.exists(i)
            ensure_missing(i)
Exemple #14
0
def single_build(request, recipes_fixture):
    """
    Builds the "one" recipe.
    """
    if request.param:
        docker_builder = docker_utils.RecipeBuilder(use_host_conda_bld=True)
        mulled_test = True
    else:
        docker_builder = None
        mulled_test = False
    build.build(
        recipe=recipes_fixture.recipe_dirs['one'],
        recipe_folder='.',
        pkg_paths=recipes_fixture.pkgs['one'],
        docker_builder=docker_builder,
        mulled_test=mulled_test,
    )
    yield recipes_fixture.pkgs['one']
    for pkg in recipes_fixture.pkgs['one']:
        ensure_missing(pkg)
Exemple #15
0
def test_docker_bioconda_utils_version():
    """
    Test for same bioconda-utils version in build container.
    """
    docker_builder = docker_utils.RecipeBuilder(
        build_script_template=('''
#! /usr/bin/env bash
python -c '
import bioconda_utils
with open("{self.container_staging}/version", "w") as version_file:
    version_file.write(bioconda_utils.__version__)
'
'''),
        docker_base_image=DOCKER_BASE_IMAGE,
    )
    temp_dir = docker_builder.pkg_dir
    # Set recipe_dir to any temporary directory, e.g., docker_builder.pkg_dir.
    docker_builder.build_recipe(temp_dir, build_args='', env={})
    with open(os.path.join(temp_dir, 'version')) as container_version_file:
        assert container_version_file.read() == __version__
Exemple #16
0
def multi_build(request, recipes_fixture, config_fixture):
    """
    Builds the "one", "two", and "three" recipes.
    """
    if request.param:
        docker_builder = docker_utils.RecipeBuilder(use_host_conda_bld=True)
        mulled_test = True
    else:
        docker_builder = None
        mulled_test = False
    build.build_recipes(
        recipe_folder=recipes_fixture.basedir,
        docker_builder=docker_builder,
        config=config_fixture,
        mulled_test=mulled_test,
    )
    built_packages = recipes_fixture.pkgs
    yield built_packages
    for pkgs in built_packages.values():
        for pkg in pkgs:
            ensure_missing(pkg)
Exemple #17
0
def test_conda_as_dep(config_fixture, mulled_test):
    docker_builder = None
    if mulled_test:
        docker_builder = docker_utils.RecipeBuilder(
            use_host_conda_bld=True,
            docker_base_image=DOCKER_BASE_IMAGE,
        )
    r = Recipes("""
        one:
          meta.yaml: |
            package:
              name: bioconda_utils_test_conda_as_dep
              version: 0.1
            requirements:
              host:
                - conda
              run:
                - conda
            test:
              commands:
                - test -e "${PREFIX}/bin/conda"
        """,
                from_string=True)
    r.write_recipes()
    build_result = build.build_recipes(
        r.basedir,
        config_fixture,
        r.recipe_dirnames,
        testonly=False,
        force=False,
        docker_builder=docker_builder,
        mulled_test=mulled_test,
    )
    assert build_result

    for k, v in r.recipe_dirs.items():
        for i in utils.built_package_paths(v):
            assert os.path.exists(i)
            ensure_missing(i)
Exemple #18
0
def test_build_container_default_gcc(tmpdir):
    r = Recipes("""
        one:
          meta.yaml: |
            package:
              name: one
              version: 0.1
            test:
              commands:
                - gcc --version
                - 'gcc --version | grep "gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)"'
        """,
                from_string=True)
    r.write_recipes()

    # Tests with the repository's Dockerfile instead of already uploaded images.
    # Copy repository to image build directory so everything is in docker context.
    image_build_dir = os.path.join(tmpdir, "repo")
    src_repo_dir = os.path.join(os.path.dirname(__file__), "..")
    shutil.copytree(src_repo_dir, image_build_dir)
    # Dockerfile will be recreated by RecipeBuilder => extract template and delete file
    dockerfile = os.path.join(image_build_dir, "Dockerfile")
    with open(dockerfile) as f:
        dockerfile_template = f.read().replace("{", "{{").replace("}", "}}")
    os.remove(dockerfile)

    docker_builder = docker_utils.RecipeBuilder(
        dockerfile_template=dockerfile_template,
        use_host_conda_bld=True,
        image_build_dir=image_build_dir,
    )
    build_result = build.build(
        recipe=r.recipe_dirs['one'],
        recipe_folder='.',
        env={},
        docker_builder=docker_builder,
        mulled_test=False,
    )
    assert build_result.success