Added support for deep extern cloning
This commit is contained in:
parent
5805d1ddf3
commit
1a7c2c475a
|
@ -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.
|
||||
# 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:
|
||||
print(f"{vt100.RED}Error:{vt100.RESET} {msg}\n", file=sys.stderr)
|
||||
|
||||
|
||||
def warning(msg: str) -> None:
|
||||
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")
|
||||
def helpCmd(args: Args):
|
||||
usage()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script makes sure that the virtual environment is
|
||||
# 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 pathlib import Path
|
||||
from dataclasses_json import DataClassJsonMixin
|
||||
from typing import Union
|
||||
|
||||
from cutekit import const, shell
|
||||
|
||||
|
@ -96,6 +97,7 @@ _project: Optional["Project"] = None
|
|||
class Extern(DataClassJsonMixin):
|
||||
git: str
|
||||
tag: str
|
||||
depth: Optional[Union[int, str]] = None
|
||||
|
||||
|
||||
@dt.dataclass
|
||||
|
@ -150,17 +152,26 @@ class Project(Manifest):
|
|||
continue
|
||||
|
||||
print(f"Installing {extSpec}-{ext.tag} from {ext.git}...")
|
||||
shell.popen(
|
||||
cmd = [
|
||||
"git",
|
||||
"clone",
|
||||
"--quiet",
|
||||
"--depth",
|
||||
"1",
|
||||
"--branch",
|
||||
ext.tag,
|
||||
ext.git,
|
||||
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))
|
||||
if project is not None:
|
||||
Project.fetchs(project.extern)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
from typing import Optional
|
||||
import docker # type: ignore
|
||||
import os
|
||||
import dataclasses as dt
|
||||
|
@ -52,7 +53,7 @@ IMAGES: dict[str, Image] = {
|
|||
"alpine:3.18",
|
||||
[
|
||||
"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(
|
||||
|
@ -114,6 +115,12 @@ def _(args: cli.Args):
|
|||
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")
|
||||
def _(args: cli.Args):
|
||||
"""
|
||||
|
@ -129,8 +136,12 @@ def _(args: cli.Args):
|
|||
|
||||
client = docker.from_env()
|
||||
try:
|
||||
client.containers.get(name)
|
||||
raise RuntimeError(f"Pod '{name[len(podPrefix):]}' already exists")
|
||||
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")
|
||||
except docker.errors.NotFound:
|
||||
pass
|
||||
|
||||
|
@ -153,9 +164,11 @@ def _(args: cli.Args):
|
|||
print(f"Initializing pod '{name[len(podPrefix) :]}'...")
|
||||
for cmd in image.setup:
|
||||
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:
|
||||
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}'")
|
||||
|
||||
|
|
Loading…
Reference in a new issue