Commit 03118c0f authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

Fix silent failures and improve deployment reliability

- Abort immediately on build or dockerize failures in meepctl instead of returning silently.
- Refactor output formatting for single dependency deployment.
- Remove invalid sg docker wrapper from pyinfra dockerize task to fix GID mismatch issues.
- Disable IPv6 sysctl settings in pyinfra kernel tasks to prevent image pull blackholes.
- Change default Pyinfra deploy tasks to not force deployments.
parent a463781a
Loading
Loading
Loading
Loading
+71 −0
Original line number Diff line number Diff line
from pyinfra import host
from pyinfra.operations import files, server, systemd
from pyinfra.facts.server import Command

disable_swap = host.data.get('disable_swap', True)

if disable_swap:
    # Disable swap at runtime if enabled.
    # We check if there's any swap configured first.
    swap_total = host.get_fact(Command, "free -m | awk '/Swap/ {print $2}'")
    
    if swap_total and swap_total.strip() != "0":
        server.shell(
            name="Disable swap at runtime if enabled",
            commands=["swapoff -a"],
            _sudo=True
        )

    # Comment out any active swap entries in fstab
    files.replace(
        name="Comment out any active swap entries in fstab",
        path="/etc/fstab",
        text=r'^([^#].*\s+swap\s+.*)$',
        replace=r'# \1',
        _sudo=True
    )

# Ensure kernel modules are present
modules = ["overlay", "br_netfilter"]
for mod in modules:
    server.modprobe(
        name=f"Ensure kernel module {mod} is present",
        module=mod,
        present=True,
        _sudo=True
    )

# Persist kernel modules
files.template(
    name="Persist kernel modules",
    src="templates/k8s.conf.j2", # We will create a template or just write a file
    dest="/etc/modules-load.d/k8s.conf",
    mode="0644",
    _sudo=True
)


# Configure sysctl for Kubernetes networking
sysctl_vars = [
    ("net.bridge.bridge-nf-call-iptables", 1),
    ("net.bridge.bridge-nf-call-ip6tables", 1),
    ("net.ipv4.ip_forward", 1),
    ("net.ipv6.conf.all.disable_ipv6", 1),
    ("net.ipv6.conf.default.disable_ipv6", 1),
    ("net.ipv6.conf.lo.disable_ipv6", 1),
]

for name, value in sysctl_vars:
    server.sysctl(
        name=f"Configure sysctl {name}",
        key=name,
        value=value,
        persist=True,
        _sudo=True
    )

# Reload systemd (if needed)
systemd.daemon_reload(
    name="Reload systemd",
    _sudo=True
)
+4 −4
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ def configure_sandbox_secrets(mec_sandbox_dir, target_home, node_version):
    # if not host.get_fact(File, path=f"{target_home}/.meep/.01_secrets_configured"):
    prefix = _build_env_prefix(target_home, node_version)
    yield StringCommand(f"{prefix} python3 {mec_sandbox_dir}/config/configure-secrets.py set {mec_sandbox_dir}/config/secrets.yaml")
    yield StringCommand(f"mkdir -p {target_home}/.meep && touch {target_home}/.meep/.01_secrets_configured")
    # yield StringCommand(f"mkdir -p {target_home}/.meep && touch {target_home}/.meep/.01_secrets_configured")


@operation()
@@ -116,7 +116,7 @@ def deploy_dep(mec_sandbox_dir, target_home, node_version, force=True):
    # if not host.get_fact(File, path=f"{target_home}/.meep/.02_deps_deployed"):
    prefix = _build_env_prefix(target_home, node_version)
    force_flag = "-f " if force else ""
    yield StringCommand(f"{prefix} meepctl deploy dep all {force_flag}|| true")
    yield StringCommand(f"{prefix} meepctl deploy dep all {force_flag} > /dev/tty 2>&1 || true")
    # yield StringCommand(f"mkdir -p {target_home}/.meep && touch {target_home}/.meep/.02_deps_deployed")


@@ -129,7 +129,7 @@ def build_all(mec_sandbox_dir, target_home, node_version, nolint=True, build_cac
    prefix = _build_env_prefix(target_home, node_version)
    nolint_flag = "--nolint " if nolint else ""
    build_cache_flag = "--no-cache " if build_cache else ""
    yield StringCommand(f"{prefix} meepctl build {build_cache_flag } {nolint_flag}all")
    yield StringCommand(f"{prefix} meepctl build {build_cache_flag } {nolint_flag}all > /dev/tty 2>&1")
    # yield StringCommand(f"mkdir -p {target_home}/.meep && touch {target_home}/.meep/.03_binaries_built")


@@ -140,7 +140,7 @@ def dockerize_all(mec_sandbox_dir, target_home, node_version):
    """
    # if not host.get_fact(File, path=f"{target_home}/.meep/.04_images_dockerized"):
    prefix = _build_env_prefix(target_home, node_version)
    yield StringCommand(f"{prefix} sg docker -c 'meepctl dockerize all'")
    yield StringCommand(f"{prefix} cd {mec_sandbox_dir} && meepctl dockerize all")
    # yield StringCommand(f"mkdir -p {target_home}/.meep && touch {target_home}/.meep/.04_images_dockerized")


+3 −5
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ meep.deploy_dep(
    mec_sandbox_dir=mec_sandbox_dir,
    target_home=target_home,
    node_version=node_version,
    force=True,
    force=False,
)

meep.build_all(
@@ -139,7 +139,7 @@ meep.build_all(
    target_home=target_home,
    node_version=node_version,
    nolint=True,
    build_cache=False
    build_cache=False,
)

meep.dockerize_all(
@@ -149,14 +149,12 @@ meep.dockerize_all(
    node_version=node_version,
)



meep.deploy_core(
    name="Deploy MEC Sandbox core platform (meepctl deploy core all -f)",
    mec_sandbox_dir=mec_sandbox_dir,
    target_home=target_home,
    node_version=node_version,
    force=True,
    force=False,
)

meep.import_scenarios(
+3 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ sysctl_vars = [
    ("net.bridge.bridge-nf-call-iptables", 1),
    ("net.bridge.bridge-nf-call-ip6tables", 1),
    ("net.ipv4.ip_forward", 1),
    ("net.ipv6.conf.all.disable_ipv6", 1),
    ("net.ipv6.conf.default.disable_ipv6", 1),
    ("net.ipv6.conf.lo.disable_ipv6", 1),
]

for name, value in sysctl_vars:
+1 −0
Original line number Diff line number Diff line
@@ -201,6 +201,7 @@ func buildFrontend(targetName string, repo string, cobraCmd *cobra.Command) {
	if err != nil {
		fmt.Println(utils.FormatError("Error: " + err.Error()))
		fmt.Println(out)
		os.Exit(1)
	}

	if len(locDeps) > 0 {
Loading