Added automatic install to disk

This commit is contained in:
Cian Hughes
2023-10-27 12:31:31 +01:00
parent 202d3d355f
commit 258d31c170
3 changed files with 48 additions and 31 deletions

View File

@@ -14,6 +14,7 @@ import typer
from config import (
CLEANUP_IMAGES,
CLIENT,
CWD_MOUNT,
CWD_MOUNTDIR,
DOCKERFILE_DIR,
FUELIGNITION_BUILD_DIR,
@@ -23,7 +24,6 @@ from config import (
SELENIUM_INIT_MESSAGE,
)
from debug import debug_mode
import docker
def create_driver():
@@ -104,7 +104,7 @@ def build_fuelignition():
dockerfile = "Dockerfile"
if root_container:
dockerfile = DOCKERFILE_DIR / "fuel-ignition.dockerfile"
image = CLIENT.images.build(
image, _ = CLIENT.images.build(
path=str(FUELIGNITION_BUILD_DIR),
dockerfile=str(dockerfile),
tag="fuel-ignition",
@@ -128,13 +128,7 @@ def json_to_img(fuelignition_json: str, img_path: str) -> None:
detach=True,
remove=True,
ports={4444: 4444, 7900: 7900},
mounts=[
docker.types.Mount(
target=str(CWD_MOUNTDIR),
source=str(ROOT_DIR),
type="bind",
)
],
mounts=[CWD_MOUNT,],
)
fuelignition_image = build_fuelignition()
fuelignition_container = CLIENT.containers.run(

View File

@@ -18,8 +18,13 @@ def apply_config(config: dict) -> None:
config["ROOT_DIR"] = Path(config["ROOT_DIR"]).absolute()
config["BUILD_DIR"] = Path(config["BUILD_DIR"]).absolute()
config["DOCKERFILE_DIR"] = Path(config["DOCKERFILE_DIR"]).absolute()
config["CWD_MOUNTDIR"] = Path(config["CWD_MOUNTDIR"])
config["FUELIGNITION_BUILD_DIR"] = config["BUILD_DIR"] / config["FUELIGNITION_BUILD_DIR"]
config["CWD_MOUNTDIR"] = Path(config["CWD_MOUNTDIR"])
config["CWD_MOUNT"] = docker.types.Mount(
target=str(config["CWD_MOUNTDIR"]),
source=str(config["ROOT_DIR"]),
type="bind",
)
globals().update(config)

View File

@@ -1,4 +1,5 @@
from fnmatch import fnmatch
from pathlib import Path
from typing import Annotated
import typer
@@ -6,13 +7,13 @@ import typer
from config import (
CLEANUP_IMAGES,
CLIENT,
CWD_MOUNT,
CWD_MOUNTDIR,
DOCKERFILE_DIR,
ROOT_DIR,
)
from create_img import create_img
from debug import debug_mode
import docker
from docker.types import Mount
def filter_validation_response(response: str) -> str:
@@ -28,7 +29,7 @@ def filter_validation_response(response: str) -> str:
def validation_result() -> str:
dockerfile = DOCKERFILE_DIR / "validate.dockerfile"
image = CLIENT.images.build(
image, _ = CLIENT.images.build(
path=".",
dockerfile=str(dockerfile),
tag="validate",
@@ -39,13 +40,7 @@ def validation_result() -> str:
)
response = CLIENT.containers.run(
image,
mounts=[
docker.types.Mount(
target=str(CWD_MOUNTDIR),
source=str(ROOT_DIR),
type="bind",
)
],
mounts=[CWD_MOUNT,],
remove=True,
)
if CLEANUP_IMAGES:
@@ -59,7 +54,36 @@ def validate() -> (bool, str):
return (not bool(response), response)
def write_disk(disk: str) -> None:
CLIENT.containers.run(
"alpine",
mounts=[CWD_MOUNT, Mount("/ignition_disk", disk, type="bind")],
privileged=True,
command=f"dd if={CWD_MOUNTDIR}/build/ignition.img of=/ignition_disk"
)
def create_ignition_disk(
disk: str,
hostname: str,
password: str,
switch_ip_address: str,
switch_port: int,
swarm_token: str,
debug: bool = False,
) -> None:
create_img(hostname, password, switch_ip_address, switch_port, swarm_token)
valid, response = validate()
if not valid:
print(response)
raise typer.Exit(1)
else:
print("Valid ignition image created!")
write_disk(disk)
def main(
disk: Annotated[str, typer.Option(help="Path to the disk to write to", prompt=True)],
hostname: Annotated[str, typer.Option(help="Hostname for the new node", prompt=True)],
password: Annotated[
str,
@@ -80,17 +104,11 @@ def main(
debug: Annotated[bool, typer.Option(help="Enable debug mode")] = False,
) -> None:
debug_mode(debug)
# f = create_img
# if debug:
# f = ss(f) # noqa: F821, # type: ignore #? ss is installed in debug_mode
# f(hostname, password, switch_ip_address, switch_port, swarm_token)
create_img(hostname, password, switch_ip_address, switch_port, swarm_token)
valid, response = validate()
if not valid:
print(response)
raise typer.Exit(1)
else:
print("Valid ignition image created!")
Path("build").mkdir(exist_ok=True, parents=True)
f = create_ignition_disk
if debug:
f = ss(f) # noqa: F821, # type: ignore #? ss is installed in debug_mode
f(disk, hostname, password, switch_ip_address, switch_port, swarm_token)
if __name__ == "__main__":