mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-30 18:52:38 +02:00
KEEP: Workaround for Podman v3
This commit is contained in:
parent
8d1be59e3f
commit
41871a3825
3 changed files with 30 additions and 5 deletions
|
@ -95,18 +95,26 @@ def list_image_tags() -> List[str]:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def add_image_tag(image_id: str, new_tag: str) -> None:
|
||||||
|
"""Add a tag to the Dangerzone image."""
|
||||||
|
log.debug(f"Adding tag '{new_tag}' to image '{image_id}'")
|
||||||
|
subprocess.check_output(
|
||||||
|
[get_runtime(), "tag", image_id, new_tag],
|
||||||
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def delete_image_tag(tag: str) -> None:
|
def delete_image_tag(tag: str) -> None:
|
||||||
"""Delete a Dangerzone image tag."""
|
"""Delete a Dangerzone image tag."""
|
||||||
name = CONTAINER_NAME + ":" + tag
|
log.warning(f"Deleting old container image: {tag}")
|
||||||
log.warning(f"Deleting old container image: {name}")
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
[get_runtime(), "rmi", "--force", name],
|
[get_runtime(), "rmi", "--force", tag],
|
||||||
startupinfo=get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(
|
log.warning(
|
||||||
f"Couldn't delete old container image '{name}', so leaving it there."
|
f"Couldn't delete old container image '{tag}', so leaving it there."
|
||||||
f" Original error: {e}"
|
f" Original error: {e}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -122,7 +130,7 @@ def load_image_tarball() -> None:
|
||||||
tarball_path = get_resource_path("container.tar")
|
tarball_path = get_resource_path("container.tar")
|
||||||
with open(tarball_path) as f:
|
with open(tarball_path) as f:
|
||||||
try:
|
try:
|
||||||
subprocess.run(
|
res = subprocess.run(
|
||||||
[get_runtime(), "load"],
|
[get_runtime(), "load"],
|
||||||
stdin=f,
|
stdin=f,
|
||||||
startupinfo=get_subprocess_startupinfo(),
|
startupinfo=get_subprocess_startupinfo(),
|
||||||
|
@ -138,4 +146,16 @@ def load_image_tarball() -> None:
|
||||||
f"Could not install container image: {error}"
|
f"Could not install container image: {error}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if get_runtime_name() == "podman" and get_runtime_version() == (3, 4):
|
||||||
|
expected_tag = get_expected_tag()
|
||||||
|
bad_tag = f"localhost/{expected_tag}:latest"
|
||||||
|
good_tag = f"{CONTAINER_NAME}:{expected_tag}"
|
||||||
|
|
||||||
|
log.debug(
|
||||||
|
f"Dangerzone images loaded in Podman v3.4 usually have an invalid tag."
|
||||||
|
" Fixing it..."
|
||||||
|
)
|
||||||
|
add_image_tag(bad_tag, good_tag)
|
||||||
|
delete_image_tag(bad_tag)
|
||||||
|
|
||||||
log.info("Successfully installed container image")
|
log.info("Successfully installed container image")
|
||||||
|
|
|
@ -97,6 +97,7 @@ class Container(IsolationProvider):
|
||||||
f"Could not find a Dangerzone container image with tag '{expected_tag}'"
|
f"Could not find a Dangerzone container image with tag '{expected_tag}'"
|
||||||
)
|
)
|
||||||
for tag in old_tags:
|
for tag in old_tags:
|
||||||
|
tag = container_utils.CONTAINER_NAME + ":" + tag
|
||||||
container_utils.delete_image_tag(tag)
|
container_utils.delete_image_tag(tag)
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -83,6 +83,10 @@ class TestContainer(IsolationProviderTest):
|
||||||
self, mocker: MockerFixture, provider: Container, fp: FakeProcess
|
self, mocker: MockerFixture, provider: Container, fp: FakeProcess
|
||||||
) -> None:
|
) -> None:
|
||||||
"""When an image keep being not installed, it should return False"""
|
"""When an image keep being not installed, it should return False"""
|
||||||
|
fp.register_subprocess(
|
||||||
|
["podman", "version", "-f", "{{.Client.Version}}"],
|
||||||
|
stdout="4.0.0",
|
||||||
|
)
|
||||||
|
|
||||||
fp.register_subprocess(
|
fp.register_subprocess(
|
||||||
[container_utils.get_runtime(), "image", "ls"],
|
[container_utils.get_runtime(), "image", "ls"],
|
||||||
|
|
Loading…
Reference in a new issue