Added support for deep extern cloning
This commit is contained in:
parent
5805d1ddf3
commit
1a7c2c475a
5 changed files with 55 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# This script is meant to be place at the root of any cutekit project.
|
# This script is meant to be place at the root of any cutekit project.
|
||||||
# It will make sure that the virtual environment is set up and that the
|
# It will make sure that the virtual environment is set up and that the
|
||||||
|
|
|
@ -120,9 +120,29 @@ def usage(args: Optional[Args] = None):
|
||||||
def error(msg: str) -> None:
|
def error(msg: str) -> None:
|
||||||
print(f"{vt100.RED}Error:{vt100.RESET} {msg}\n", file=sys.stderr)
|
print(f"{vt100.RED}Error:{vt100.RESET} {msg}\n", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def warning(msg: str) -> None:
|
def warning(msg: str) -> None:
|
||||||
print(f"{vt100.YELLOW}Warning:{vt100.RESET} {msg}\n", file=sys.stderr)
|
print(f"{vt100.YELLOW}Warning:{vt100.RESET} {msg}\n", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def ask(msg: str, default: Optional[bool] = None) -> bool:
|
||||||
|
if default is None:
|
||||||
|
msg = f"{msg} [y/n] "
|
||||||
|
elif default:
|
||||||
|
msg = f"{msg} [Y/n] "
|
||||||
|
else:
|
||||||
|
msg = f"{msg} [y/N] "
|
||||||
|
|
||||||
|
while True:
|
||||||
|
result = input(msg).lower()
|
||||||
|
if result in ("y", "yes"):
|
||||||
|
return True
|
||||||
|
elif result in ("n", "no"):
|
||||||
|
return False
|
||||||
|
elif result == "" and default is not None:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
@command("h", "help", "Show this help message")
|
@command("h", "help", "Show this help message")
|
||||||
def helpCmd(args: Args):
|
def helpCmd(args: Args):
|
||||||
usage()
|
usage()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# This script makes sure that the virtual environment is
|
# This script makes sure that the virtual environment is
|
||||||
# set up and that the plugins requirements are installed.
|
# set up and that the plugins requirements are installed.
|
||||||
|
|
|
@ -7,6 +7,7 @@ from enum import Enum
|
||||||
from typing import Any, Generator, Optional, Type, cast
|
from typing import Any, Generator, Optional, Type, cast
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dataclasses_json import DataClassJsonMixin
|
from dataclasses_json import DataClassJsonMixin
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from cutekit import const, shell
|
from cutekit import const, shell
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ _project: Optional["Project"] = None
|
||||||
class Extern(DataClassJsonMixin):
|
class Extern(DataClassJsonMixin):
|
||||||
git: str
|
git: str
|
||||||
tag: str
|
tag: str
|
||||||
|
depth: Optional[Union[int, str]] = None
|
||||||
|
|
||||||
|
|
||||||
@dt.dataclass
|
@dt.dataclass
|
||||||
|
@ -150,17 +152,26 @@ class Project(Manifest):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f"Installing {extSpec}-{ext.tag} from {ext.git}...")
|
print(f"Installing {extSpec}-{ext.tag} from {ext.git}...")
|
||||||
shell.popen(
|
cmd = [
|
||||||
"git",
|
"git",
|
||||||
"clone",
|
"clone",
|
||||||
"--quiet",
|
"--quiet",
|
||||||
"--depth",
|
|
||||||
"1",
|
|
||||||
"--branch",
|
"--branch",
|
||||||
ext.tag,
|
ext.tag,
|
||||||
ext.git,
|
ext.git,
|
||||||
extPath,
|
extPath,
|
||||||
)
|
]
|
||||||
|
|
||||||
|
if ext.depth is None:
|
||||||
|
cmd += ["--depth", "1"]
|
||||||
|
elif isinstance(ext.depth, int):
|
||||||
|
cmd += ["--depth", str(ext.depth)]
|
||||||
|
elif ext.depth == "deep":
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"Invalid depth '{ext.depth}'")
|
||||||
|
|
||||||
|
shell.exec(*cmd, quiet=True)
|
||||||
project = Project.at(Path(extPath))
|
project = Project.at(Path(extPath))
|
||||||
if project is not None:
|
if project is not None:
|
||||||
Project.fetchs(project.extern)
|
Project.fetchs(project.extern)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
|
from typing import Optional
|
||||||
import docker # type: ignore
|
import docker # type: ignore
|
||||||
import os
|
import os
|
||||||
import dataclasses as dt
|
import dataclasses as dt
|
||||||
|
@ -52,7 +53,7 @@ IMAGES: dict[str, Image] = {
|
||||||
"alpine:3.18",
|
"alpine:3.18",
|
||||||
[
|
[
|
||||||
"apk update",
|
"apk update",
|
||||||
"apk add python3 python3-dev py3-pip py3-venv build-base linux-headers ninja make automake gcc g++",
|
"apk add python3 python3-dev py3-pip py3-virtualenv build-base linux-headers ninja make automake gcc g++ bash",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
"arch": Image(
|
"arch": Image(
|
||||||
|
@ -114,6 +115,12 @@ def _(args: cli.Args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def tryDecode(data: Optional[bytes], default: str = "") -> str:
|
||||||
|
if data is None:
|
||||||
|
return default
|
||||||
|
return data.decode()
|
||||||
|
|
||||||
|
|
||||||
@cli.command("c", "pod/create", "Create a new pod")
|
@cli.command("c", "pod/create", "Create a new pod")
|
||||||
def _(args: cli.Args):
|
def _(args: cli.Args):
|
||||||
"""
|
"""
|
||||||
|
@ -129,7 +136,11 @@ def _(args: cli.Args):
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
try:
|
try:
|
||||||
client.containers.get(name)
|
existing = client.containers.get(name)
|
||||||
|
if cli.ask(f"Pod '{name[len(podPrefix):]}' already exists, kill it?", False):
|
||||||
|
existing.stop()
|
||||||
|
existing.remove()
|
||||||
|
else:
|
||||||
raise RuntimeError(f"Pod '{name[len(podPrefix):]}' already exists")
|
raise RuntimeError(f"Pod '{name[len(podPrefix):]}' already exists")
|
||||||
except docker.errors.NotFound:
|
except docker.errors.NotFound:
|
||||||
pass
|
pass
|
||||||
|
@ -153,9 +164,11 @@ def _(args: cli.Args):
|
||||||
print(f"Initializing pod '{name[len(podPrefix) :]}'...")
|
print(f"Initializing pod '{name[len(podPrefix) :]}'...")
|
||||||
for cmd in image.setup:
|
for cmd in image.setup:
|
||||||
print(vt100.p(cmd))
|
print(vt100.p(cmd))
|
||||||
exitCode, ouput = container.exec_run(f"/bin/bash -c '{cmd}'", demux=True)
|
exitCode, output = container.exec_run(f"/bin/sh -c '{cmd}'", demux=True)
|
||||||
if exitCode != 0:
|
if exitCode != 0:
|
||||||
raise RuntimeError(f"Failed to initialize pod with command '{cmd}'")
|
raise RuntimeError(
|
||||||
|
f"Failed to initialize pod with command '{cmd}':\n\nSTDOUT:\n{vt100.indent(vt100.wordwrap(tryDecode(output[0], '<empty>')))}\nSTDERR:\n{vt100.indent(vt100.wordwrap(tryDecode(output[1], '<empty>')))}"
|
||||||
|
)
|
||||||
|
|
||||||
print(f"Created pod '{name[len(podPrefix) :]}' from image '{image.image}'")
|
print(f"Created pod '{name[len(podPrefix) :]}' from image '{image.image}'")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue