-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a79cd67
commit ced93c0
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import tempfile | ||
from typing import List | ||
|
||
from nanolayer.utils.invoker import Invoker | ||
from nanolayer.utils.linux_information_desk import LinuxInformationDesk | ||
|
||
|
||
class ApkInstaller: | ||
@classmethod | ||
def is_alpine(cls) -> bool: | ||
return ( | ||
LinuxInformationDesk.get_release_id() | ||
== LinuxInformationDesk.LinuxReleaseID.alpine | ||
) | ||
|
||
@classmethod | ||
def delete(cls, packages: List[str]) -> None: | ||
assert cls.is_alpine(), "apk should be used on alpine linux distribution" | ||
Invoker.invoke(command=f"apk del {' '.join(packages)}") | ||
|
||
@classmethod | ||
def install( | ||
cls, | ||
packages: List[str], | ||
) -> None: | ||
assert cls.is_alpine(), "apk should be used on alpine linux distribution" | ||
|
||
with tempfile.TemporaryDirectory() as tempdir: | ||
Invoker.invoke(command=f"cp -p -R /var/cache/apk {tempdir}") | ||
|
||
try: | ||
Invoker.invoke(command="apk update") | ||
|
||
Invoker.invoke(command=f"apk add --no-cache {' '.join(packages)}") | ||
|
||
finally: | ||
# Note: not using dir/* syntax as that doesnt work on 'sh' shell (alpine) | ||
Invoker.invoke( | ||
command=f"rm -r /var/cache/apk && mv {tempdir}/apk /var/cache/apk" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters