Skip to content

Commit

Permalink
Merge pull request #50 from devcontainers-contrib/danielbraun89/issue49
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbraun89 authored Aug 22, 2023
2 parents d4282ea + aa31a6f commit a79cd67
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 75 deletions.
18 changes: 0 additions & 18 deletions nanolayer/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,11 @@ def install_apt_get_packages(
None, help="comma separated list of ppas to make use of"
),
force_ppas_on_non_ubuntu: bool = False,
clean_ppas: bool = True,
clean_cache: bool = True,
preserve_apt_list: bool = True,
) -> None:
AptGetInstaller.install(
packages=packages.split(","),
ppas=ppas.split(",") if ppas else None,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu,
clean_ppas=clean_ppas,
clean_cache=clean_cache,
preserve_apt_list=preserve_apt_list,
)


Expand All @@ -102,17 +96,11 @@ def install_apt_packages(
None, help="comma separated list of ppas to make use of"
),
force_ppas_on_non_ubuntu: bool = False,
clean_ppas: bool = True,
clean_cache: bool = True,
preserve_apt_list: bool = True,
) -> None:
AptInstaller.install(
packages=packages.split(","),
ppas=ppas.split(",") if ppas else None,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu,
clean_ppas=clean_ppas,
clean_cache=clean_cache,
preserve_apt_list=preserve_apt_list,
)


Expand All @@ -125,17 +113,11 @@ def install_aptitude_packages(
None, help="comma separated list of ppas to make use of"
),
force_ppas_on_non_ubuntu: bool = False,
clean_ppas: bool = True,
clean_cache: bool = True,
preserve_apt_list: bool = True,
) -> None:
AptitudeInstaller.install(
packages=packages.split(","),
ppas=ppas.split(",") if ppas else None,
force_ppas_on_non_ubuntu=force_ppas_on_non_ubuntu,
clean_ppas=clean_ppas,
clean_cache=clean_cache,
preserve_apt_list=preserve_apt_list,
)


Expand Down
30 changes: 16 additions & 14 deletions nanolayer/installers/apt/apt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def install(
packages: List[str],
ppas: Optional[List[str]] = None,
force_ppas_on_non_ubuntu: bool = False,
clean_ppas: bool = True,
clean_cache: bool = True,
preserve_apt_list: bool = True,
) -> None:
assert (
cls.is_debian_like()
Expand All @@ -41,8 +38,8 @@ def install(
installed_ppas: List[str] = []

with tempfile.TemporaryDirectory() as tempdir:
if preserve_apt_list:
Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}")
# preserving previuse cache
Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}")

try:
Invoker.invoke(command="apt update -y")
Expand All @@ -62,13 +59,18 @@ def install(
)

finally:
if clean_ppas:
AptGetInstaller._clean_ppas(
ppas=installed_ppas,
purge_packages=support_packages_installed,
)
# remove ppa indexes
AptGetInstaller._clean_ppas(
ppas=installed_ppas,
purge_packages=support_packages_installed,
)

# remove archives cache
Invoker.invoke(command="apt clean")

if clean_cache:
Invoker.invoke(command="apt clean")
if preserve_apt_list:
Invoker.invoke(command=f"mv {tempdir} /var/lib/apt/lists")
# restore lists cache
# Note: The reason for not using the dir/* syntax is because
# that doesnt work on ash based shell (alpine)
Invoker.invoke(
command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists"
)
39 changes: 17 additions & 22 deletions nanolayer/installers/apt_get/apt_get_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class AptGetInstaller:
PPA_SUPPORT_PACKAGES = ("software-properties-common",)
PPA_SUPPORT_PACKAGES_DEBIAN = ("python3-launchpadlib",)

class AptGetInstallerError(Exception):
pass

@staticmethod
def normalize_ppas(ppas: List[str]) -> List[str]:
# normalize ppas to have the ppa: initials
Expand Down Expand Up @@ -102,9 +99,6 @@ def install(
packages: List[str],
ppas: Optional[List[str]] = None,
force_ppas_on_non_ubuntu: bool = False,
clean_ppas: bool = True,
clean_cache: bool = True,
preserve_apt_list: bool = True,
) -> None:
if ppas is None:
ppas = []
Expand All @@ -117,8 +111,8 @@ def install(
installed_ppas: List[str] = []

with tempfile.TemporaryDirectory() as tempdir:
if preserve_apt_list:
Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}")
# preserving previuse cache
Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}")

try:
Invoker.invoke(command="apt-get update -y")
Expand All @@ -132,17 +126,18 @@ def install(
)

finally:
if ppas and clean_ppas:
cls._clean_ppas(
ppas=installed_ppas,
purge_packages=support_packages_installed,
)

if clean_cache:
Invoker.invoke(command="apt-get clean")

if preserve_apt_list:
# Note: not using dir/* syntax as that doesnt work on 'sh' shell (alpine)
Invoker.invoke(
command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists"
)
# remove ppa indexes
cls._clean_ppas(
ppas=installed_ppas,
purge_packages=support_packages_installed,
)

# remove archives cache
Invoker.invoke(command="apt-get clean")

# restore lists cache
# Note: The reason for not using the dir/* syntax is because
# that doesnt work on ash based shell (alpine)
Invoker.invoke(
command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists"
)
32 changes: 14 additions & 18 deletions nanolayer/installers/aptitude/aptitude_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ def install(
packages: List[str],
ppas: Optional[List[str]] = None,
force_ppas_on_non_ubuntu: bool = False,
clean_ppas: bool = True,
clean_cache: bool = True,
preserve_apt_list: bool = True,
remove_installer_if_not_exists: bool = True,
) -> None:
assert (
cls.is_debian_like()
Expand All @@ -35,17 +31,15 @@ def install(

with tempfile.TemporaryDirectory() as tempdir:
try:
if preserve_apt_list:
Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}")
# preserving previuse cache
Invoker.invoke(command=f"cp -p -R /var/lib/apt/lists {tempdir}")

Invoker.invoke(command="apt-get update -y")

# ensure aptitude existance
if Invoker.invoke("dpkg -s aptitude", raise_on_failure=False) != 0:
AptGetInstaller.install(
packages=["aptitude"],
clean_cache=clean_cache,
preserve_apt_list=preserve_apt_list,
)
aptitude_installed = True

Expand All @@ -62,17 +56,19 @@ def install(
Invoker.invoke(command=f"aptitude install -y {' '.join(packages)}")

finally:
if clean_ppas:
AptGetInstaller._clean_ppas(
ppas=installed_ppas,
purge_packages=support_packages_installed,
)
AptGetInstaller._clean_ppas(
ppas=installed_ppas,
purge_packages=support_packages_installed,
)

if clean_cache:
Invoker.invoke(command="aptitude clean")
Invoker.invoke(command="aptitude clean")

if aptitude_installed and remove_installer_if_not_exists:
if aptitude_installed:
Invoker.invoke(command="apt-get -y purge aptitude --auto-remove")

if preserve_apt_list:
Invoker.invoke(command=f"mv {tempdir} /var/lib/apt/lists")
# restore lists cache
# Note: The reason for not using the dir/* syntax is because
# that doesnt work on ash based shell (alpine)
Invoker.invoke(
command=f"rm -r /var/lib/apt/lists && mv {tempdir}/lists /var/lib/apt/lists"
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@


class OCIFeatureInstaller:
class FeatureInstallationException(Exception):
pass

class NoPremissions(PermissionError):
pass

Expand Down

0 comments on commit a79cd67

Please sign in to comment.