Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Dec 18, 2024
1 parent 9dd3f21 commit 26d46c8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
16 changes: 3 additions & 13 deletions tasks/coconut/ovmf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from invoke import task
from os.path import join
from tasks.util.env import BIN_DIR, PROJ_ROOT
from tasks.util.docker import copy_from_container, build_image_and_run, stop_container
from tasks.util.env import BIN_DIR
from tasks.util.docker import copy_from_ctr_image

# refer to
# https://github.com/coconut-svsm/svsm/blob/main/Documentation/docs/installation/INSTALL.md
Expand All @@ -11,16 +11,6 @@

@task
def build(ctx):
tmp_ctr_name = "tmp-ovmf-svsm-run"

build_image_and_run(
OVMF_IMAGE_TAG,
join(PROJ_ROOT, "docker", "coconut", "ovmf.dockerfile"),
tmp_ctr_name,
)

ctr_path = "/root/edk2/Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd"
host_path = join(BIN_DIR, "ovmf-svsm.fd")
copy_from_container(tmp_ctr_name, ctr_path, host_path)

stop_container(tmp_ctr_name)
copy_from_ctr_image(OVMF_IMAGE_TAG, ctr_path, host_path)
11 changes: 5 additions & 6 deletions tasks/coconut/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from os.path import join
from subprocess import run
from tasks.util.env import BIN_DIR, PROJ_ROOT, KATA_ROOT
from tasks.util.docker import copy_from_container, build_image_and_run, stop_container
from tasks.util.docker import copy_from_ctr_image, build_image_and_run

# refer to
# https://github.com/coconut-svsm/svsm/blob/main/Documentation/docs/installation/INSTALL.md
Expand All @@ -15,21 +15,20 @@
def build(ctx):
tmp_ctr_name = "tmp-qemu-igvm-run"

# TODO: fix me
build_image_and_run(
QEMU_IMAGE_TAG,
join(PROJ_ROOT, "docker", "coconut", "qemu.dockerfile"),
tmp_ctr_name,
{"QEMU_DATADIR": DATA_DIR},
)

copy_from_container(
tmp_ctr_name,
copy_from_ctr_image(
QEMU_IMAGE_TAG,
"/root/bin/qemu-svsm/bin/qemu-system-x86_64",
join(BIN_DIR, "qemu-system-x86_64-igvm"),
)
copy_from_container(tmp_ctr_name, f"{DATA_DIR}/.", DATA_DIR)

stop_container(tmp_ctr_name)
# copy_from_container(tmp_ctr_name, f"{DATA_DIR}/.", DATA_DIR)


@task
Expand Down
7 changes: 4 additions & 3 deletions tasks/coconut/svsm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from invoke import task
from os.path import join
from tasks.util.env import BIN_DIR, PROJ_ROOT
from tasks.util.docker import build_image_and_run, copy_from_container, stop_container
from tasks.util.docker import build_image_and_run, copy_from_ctr_image, stop_container

# refer to
# https://github.com/coconut-svsm/svsm/blob/main/Documentation/docs/installation/INSTALL.md
Expand All @@ -27,9 +27,10 @@ def build(ctx):
"coconut-qemu.igvm",
"../target/x86_64-unknown-none/debug/svsm",
]
# FIXME: sure it is the right tag?
for file_name in files_to_copy:
copy_from_container(
tmp_ctr_name, join(ctr_path, file_name), join(host_path, file_name)
copy_from_ctr_image(
QEMU_IMAGE_TAG, join(ctr_path, file_name), join(host_path, file_name)
)

stop_container(tmp_ctr_name)
8 changes: 5 additions & 3 deletions tasks/containerd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from invoke import task
from os import makedirs, stat
from os import stat
from os.path import join
from subprocess import CalledProcessError, run
from subprocess import run
from tasks.util.containerd import is_containerd_active, restart_containerd
from tasks.util.docker import copy_from_ctr_image, is_ctr_running
from tasks.util.env import (
Expand Down Expand Up @@ -105,7 +105,9 @@ def install(ctx, debug=False, clean=False):

host_binaries = [join(host_base_path, binary) for binary in binary_names]
ctr_binaries = [join(ctr_base_path, binary) for binary in binary_names]
copy_from_ctr_image(CONTAINERD_IMAGE_TAG, ctr_binaries, host_binaries, requires_sudo=True)
copy_from_ctr_image(
CONTAINERD_IMAGE_TAG, ctr_binaries, host_binaries, requires_sudo=True
)

# Clean-up all runtime files for a clean start
if clean:
Expand Down
1 change: 1 addition & 0 deletions tasks/util/containerd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from subprocess import run
from time import sleep


def is_containerd_active():
out = (
run("sudo systemctl is-active containerd", shell=True, capture_output=True)
Expand Down
12 changes: 10 additions & 2 deletions tasks/util/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ def copy_from_ctr_image(ctr_image, ctr_paths, host_paths, requires_sudo=False):
Copy from a container image without actually running the container
"""
tmp_ctr_name = "tmp-build-ctr"
result = run(f"docker create --name {tmp_ctr_name} {ctr_image}", shell=True, capture_output=True)
result = run(
f"docker create --name {tmp_ctr_name} {ctr_image}",
shell=True,
capture_output=True,
)
assert result.returncode == 0, print(result.stderr.decode("utf-8").strip())

for ctr_path, host_path in zip(ctr_paths, host_paths):
try:
prefix = "sudo " if requires_sudo else ""
result = run(f"{prefix}docker cp {tmp_ctr_name}:{ctr_path} {host_path}", shell=True, capture_output=True)
result = run(
f"{prefix}docker cp {tmp_ctr_name}:{ctr_path} {host_path}",
shell=True,
capture_output=True,
)
assert result.returncode == 0
except AssertionError:
stderr = result.stderr.decode("utf-8").strip()
Expand Down
1 change: 1 addition & 0 deletions tasks/util/kata.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def stop_kata_workon_ctr():
assert result.returncode == 0


# TODO: differentiate between a hot-replace and a regular replace
def copy_from_kata_workon_ctr(ctr_path, host_path, sudo=False, debug=False):
ctr_started = run_kata_workon_ctr()

Expand Down

0 comments on commit 26d46c8

Please sign in to comment.