decomposer: generate files for Create a production-suitable Dockerfile and minimal Docker Compose configuration for packaging and running the completed FastAPI endpoint monitoring service.
This commit is contained in:
40
src/containerizer/cli.py
Normal file
40
src/containerizer/cli.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
from .generate import containerize, dumps
|
||||
from .verify import verify_with_docker
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Containerize an existing FastAPI service")
|
||||
parser.add_argument("--input", default="-", help="contract JSON file, or - for stdin")
|
||||
parser.add_argument("--service-dir", required=True, help="existing FastAPI repository root")
|
||||
parser.add_argument("--output", default="-", help="result JSON file, or - for stdout")
|
||||
parser.add_argument("--verify-docker", action="store_true",
|
||||
help="actually build, start, probe (when configured), and stop Compose")
|
||||
args = parser.parse_args()
|
||||
raw = sys.stdin.read() if args.input == "-" else open(args.input).read()
|
||||
payload = json.loads(raw)
|
||||
result = containerize(payload, args.service_dir)
|
||||
if args.verify_docker:
|
||||
spec = payload["service_specification"]
|
||||
cfg = spec.get("container", {})
|
||||
port = cfg.get("port", spec.get("port", 8000))
|
||||
health = cfg.get("health_endpoint", spec.get("health_endpoint"))
|
||||
result["container_artifacts"]["docker_verification"] = verify_with_docker(
|
||||
args.service_dir, port, health)
|
||||
else:
|
||||
result["container_artifacts"]["docker_verification"] = {
|
||||
"executed": False, "passed": None,
|
||||
"reason": "--verify-docker was not requested",
|
||||
}
|
||||
text = dumps(result)
|
||||
if args.output == "-":
|
||||
sys.stdout.write(text)
|
||||
else:
|
||||
open(args.output, "w").write(text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user