MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / create_app_compose

Method create_app_compose

vmm/src/vmm-cli.py:782–829  ·  view source on GitHub ↗

Create a new app compose file.

(self, args)

Source from the content-addressed store, hash-verified

780 return compose_hash[:40]
781
782 def create_app_compose(self, args) -> None:
783 """Create a new app compose file."""
784 envs = parse_env_file(args.env_file) or {}
785
786 # Validate: --env-file requires --kms
787 if envs and not args.kms:
788 raise Exception(
789 "--env-file requires --kms to enable KMS for environment variable decryption"
790 )
791
792 app_compose = {
793 "manifest_version": 2,
794 "name": args.name,
795 "runner": "docker-compose",
796 "docker_compose_file": open(args.docker_compose, "rb")
797 .read()
798 .decode("utf-8"),
799 "kms_enabled": args.kms,
800 "gateway_enabled": args.gateway,
801 "local_key_provider_enabled": args.local_key_provider,
802 "key_provider_id": args.key_provider_id or "",
803 "public_logs": args.public_logs,
804 "public_sysinfo": args.public_sysinfo,
805 "allowed_envs": [k for k in envs.keys()],
806 "no_instance_id": args.no_instance_id,
807 "secure_time": args.secure_time,
808 }
809 if args.key_provider:
810 app_compose["key_provider"] = args.key_provider
811 if args.prelaunch_script:
812 app_compose["pre_launch_script"] = (
813 open(args.prelaunch_script, "rb").read().decode("utf-8")
814 )
815 if args.swap is not None:
816 swap_bytes = max(0, int(round(args.swap)) * 1024 * 1024)
817 if swap_bytes > 0:
818 app_compose["swap_size"] = swap_bytes
819 else:
820 app_compose.pop("swap_size", None)
821
822 compose_file = json.dumps(app_compose, indent=4, ensure_ascii=False).encode(
823 "utf-8"
824 )
825 compose_hash = hashlib.sha256(compose_file).hexdigest()
826 with open(args.output, "wb") as f:
827 f.write(compose_file)
828 print(f"App compose file created at: {args.output}")
829 print(f"Compose hash: {compose_hash}")
830
831 def create_vm(self, args) -> None:
832 """Create a new VM."""

Callers 1

mainFunction · 0.95

Calls 3

parse_env_fileFunction · 0.85
writeMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected