Skip to content

Commit

Permalink
added the ability to use Debian based distributions by adding the apt…
Browse files Browse the repository at this point in the history
…-get package manager (#695)
  • Loading branch information
stephengaito committed Mar 18, 2021
1 parent 4247459 commit 7063df8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cekit/descriptor/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
install:
seq:
- {type: any}
manager: {type: str, enum: ['yum', 'dnf', 'microdnf', 'apk']}""")
manager: {type: str, enum: ['yum', 'dnf', 'microdnf', 'apk', 'apt-get']}""")


repository_schema = yaml.safe_load("""
Expand Down
17 changes: 16 additions & 1 deletion cekit/template_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class TemplateHelper(object):

SUPPORTED_PACKAGE_MANAGERS = ['yum', 'dnf', 'microdnf', 'apk']
SUPPORTED_PACKAGE_MANAGERS = ['yum', 'dnf', 'microdnf', 'apk', 'apt-get']

def __init__(self, module_registry):
self._module_registry = module_registry
Expand Down Expand Up @@ -92,6 +92,19 @@ def package_manager_flags(self, pkg_mgr):
default = "--setopt=tsflags=nodocs"
if "apk" in pkg_mgr:
return ""
if "apt-get" in pkg_mgr:
#
# This is a HACK...
#
# Debian based apt-get needs an *update* step
# *before* its "install" step...
#
# We really *should* add an additional step to the
# main template repo_install and pkg_install macros
#
# However this works at the moment...
#
return "update && apt-get --no-install-recommends"
elif "microdnf" in pkg_mgr:
return "--setopt=install_weak_deps=0 " + default
else:
Expand All @@ -106,5 +119,7 @@ def package_manager_install(self, pkg_mgr):
def package_manager_query(self, pkg_mgr):
if "apk" in pkg_mgr:
return "apk info -e"
elif "apt-get" in pkg_mgr:
return "dpkg-query --list"
else:
return "rpm -q"
13 changes: 12 additions & 1 deletion docs/descriptor/includes/packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ as the package manager that is used to manage packages in this image.
install:
- python3
.. code-block:: yaml
:caption: Example package section for APT-based distro
packages:
manager: apt-get
install:
- python3-minimal
Packages to install
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -62,7 +70,7 @@ Required
It is possible to define package manager used in the image
used to install packages as part of the build process.

Currently available options are ``yum``, ``dnf``, ``microdnf`` and ``apk``.
Currently available options are ``yum``, ``dnf``, ``microdnf``, ``apt-get`` and ``apk``.

.. note::
If you do not specify this key the default value is ``yum``.
Expand All @@ -74,6 +82,9 @@ Currently available options are ``yum``, ``dnf``, ``microdnf`` and ``apk``.
.. note::
For ``yum``, ``dnf`` and ``microdnf`` the flag ``--setopt=tsflags=nodocs`` is automatically added. For ``microdnf``, the flag ``--setopt=install_weak_deps=0`` is also added.

-- note::
For ``apt-get`` the flag ``--no-install-recommends`` is also added.

.. code-block:: yaml
packages:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_dockerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ def test_supported_package_managers_apk(tmpdir, caplog):
assert "Package manager apk does not support defining repositories, skipping all repositories" in caplog.text


def test_supported_package_managers_apt(tmpdir, caplog):
target = str(tmpdir.mkdir('target'))

generate(
target,
['-v', 'build', '--dry-run', 'podman'],
descriptor={
'packages': {
'manager': 'apt-get',
'install': ['a'],
'repositories': [{'name': 'foo',
'rpm': 'foo-repo.rpm'}]
}
})
regex_dockerfile(target, "RUN apt-get update && apt-get --no-install-recommends install -y a")
regex_dockerfile(target, "dpkg-query --list a")
assert "Package manager apt-get does not support defining repositories, skipping all repositories" in caplog.text


# https://github.com/cekit/cekit/issues/406
def test_dockerfile_do_not_copy_modules_if_no_modules(tmpdir):
target = str(tmpdir.mkdir('target'))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,27 @@ def test_run_alpine(tmpdir):

run_cekit(image_dir, parameters=['-v', 'build', 'podman'], env={'BUILDAH_LAYERS': 'false'})

@pytest.mark.skipif(platform.system() == 'Darwin', reason="Disabled on macOS, cannot run Podman")
def test_run_debian_slim(tmpdir):
image_dir = str(tmpdir.mkdir('source'))

copy_repos(image_dir)

with open(os.path.join(image_dir, 'bar.jar'), 'w') as fd:
fd.write('foo')

img_desc = image_descriptor.copy()
img_desc['from'] = 'debian:stable-slim'
img_desc['packages'] = {
'install': ['python3-minimal'],
'manager': 'apt-get'
}

with open(os.path.join(image_dir, 'image.yaml'), 'w') as fd:
yaml.dump(img_desc, fd, default_flow_style=False)

run_cekit(image_dir, parameters=['-v', 'build', 'podman'], env={'BUILDAH_LAYERS': 'false'})


def test_execution_order(tmpdir):
image_dir = str(tmpdir.mkdir('source'))
Expand Down

0 comments on commit 7063df8

Please sign in to comment.