Exemple #1
0
def test_galaxy_requirements(exec_env_definition_file,
                             galaxy_requirements_file, path_spec, tmpdir):
    galaxy_requirements_content = {
        'collections': [{
            'name': 'geerlingguy.php_roles',
            'version': '0.9.3',
            'source': 'https://galaxy.ansible.com'
        }]
    }

    galaxy_requirements_path = galaxy_requirements_file(
        galaxy_requirements_content)

    exec_env_content = {
        'version': 1,
        'dependencies': {
            'galaxy':
            str(galaxy_requirements_path)
            if path_spec == 'absolute' else '../galaxy/requirements.yml'
        }
    }

    exec_env_path = exec_env_definition_file(content=exec_env_content)

    aee = AnsibleBuilder(filename=exec_env_path,
                         build_context=tmpdir.mkdir('bc'))
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert f'ADD {CONTEXT_BUILD_OUTPUTS_DIR}/requirements.yml' in content
Exemple #2
0
def test_base_image_via_definition_file(exec_env_definition_file, tmpdir):
    content = {'version': 1, 'base_image': 'my-other-custom-image'}
    path = exec_env_definition_file(content=content)
    aee = AnsibleBuilder(filename=path, build_context=tmpdir.mkdir('bc'))
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert 'my-other-custom-image' in content
Exemple #3
0
def test_ansible_config_for_galaxy(exec_env_definition_file, tmpdir):
    if not os.path.exists('test/data/ansible-test.cfg'):
        pytest.skip('Test is only valid when ran from ansible-builder root')

    ansible_config_path = 'test/data/ansible-test.cfg'
    content = {'version': 1, 'ansible_config': ansible_config_path}
    path = exec_env_definition_file(content=content)
    aee = AnsibleBuilder(filename=path, build_context=tmpdir.mkdir('bc'))
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert f'ADD {CONTEXT_BUILD_OUTPUTS_DIR}/ansible.cfg ~/.ansible.cfg' in content
Exemple #4
0
def test_use_dockerfile_with_podman(exec_env_definition_file, tmpdir):
    path = exec_env_definition_file(content={'version': 1})
    aee = AnsibleBuilder(
        filename=path, build_context=tmpdir.mkdir('bc'),
        container_runtime='podman', output_filename='Dockerfile'
    )
    aee.build()

    assert aee.containerfile.path.endswith('Dockerfile')

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert 'FROM' in content
Exemple #5
0
def test_ansible_config_for_galaxy(exec_env_definition_file, tmp_path):
    if not os.path.exists('test/data/ansible-test.cfg'):
        pytest.skip('Test is only valid when ran from ansible-builder root')

    ansible_config_path = 'test/data/ansible-test.cfg'
    content = {'version': 1, 'ansible_config': ansible_config_path}
    path = exec_env_definition_file(content=content)
    aee = AnsibleBuilder(filename=path, build_context=tmp_path.joinpath('bc'))
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert f'ADD {constants.user_content_subfolder}/ansible.cfg ~/.ansible.cfg' in content
Exemple #6
0
def test_base_image_via_definition_file_build_arg(exec_env_definition_file,
                                                  tmp_path):
    content = {
        'version': 1,
        'build_arg_defaults': {
            'EE_BASE_IMAGE': 'my-other-custom-image'
        }
    }
    path = exec_env_definition_file(content=content)
    aee = AnsibleBuilder(filename=path, build_context=tmp_path.joinpath('bc'))
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert 'EE_BASE_IMAGE=my-other-custom-image' in content
Exemple #7
0
def test_base_image_via_build_args(exec_env_definition_file, tmpdir):
    content = {'version': 1}
    path = exec_env_definition_file(content=content)
    aee = AnsibleBuilder(filename=path, build_context=tmpdir.mkdir('bc'))
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert 'ansible-runner' in content

    aee = AnsibleBuilder(
        filename=path, build_args={'ANSIBLE_RUNNER_IMAGE': 'my-custom-image'},
        build_context=tmpdir.mkdir('bc2')
    )
    aee.build()

    with open(aee.containerfile.path) as f:
        content = f.read()

    assert 'ANSIBLE_RUNNER_IMAGE' in content  # TODO: should we make user value default?