Skip to content

Commit

Permalink
Reorganizing objects created in CLI
Browse files Browse the repository at this point in the history
Summary: Moving some imports to be inside of if statements when possible to move closer to only creating instances when needed

Differential Revision: D38009745

fbshipit-source-id: 8658466064ce7173d2ad8b52872c6d69855f82c6
  • Loading branch information
Arnav Sacheti authored and facebook-github-bot committed Jul 21, 2022
1 parent 83a5ea8 commit 1269ceb
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions onedocker/script/cli/onedocker_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
container_svc = None
onedocker_package_repo = None
onedocker_checksum_repo = None
attestation_svc = None
log_svc = None
task_definition = None
repository_path = None

DEFAULT_BINARY_VERSION = "latest"
DEFAULT_TIMEOUT = 18000
Expand All @@ -65,6 +62,7 @@ def _upload(
)
if enable_attestation:
logger.info(f"Generating checksums for package {package_name}: {version}")
attestation_svc = AttestationService()
formatted_checksum_info = attestation_svc.track_binary(
binary_path=package_dir,
package_name=package_name,
Expand Down Expand Up @@ -171,12 +169,8 @@ def _build_log_service(config: Dict[str, Any]) -> LogService:
return log_class(**config["constructor"])


def _build_exe_s3_path(repository_path: str, package_name: str, version: str) -> str:
return f"{repository_path}{package_name}/{version}/{package_name.split('/')[-1]}"


def main() -> None:
global container_svc, onedocker_svc, onedocker_package_repo, onedocker_checksum_repo, log_svc, logger, task_definition, repository_path, attestation_svc
global container_svc, onedocker_svc, onedocker_package_repo, onedocker_checksum_repo, log_svc, logger
s = schema.Schema(
{
"upload": bool,
Expand Down Expand Up @@ -208,30 +202,39 @@ def main() -> None:
version = (
arguments["--version"] if arguments["--version"] else DEFAULT_BINARY_VERSION
)
enable_attestation = arguments["--enable_attestation"]

config = yaml.load(Path(arguments["--config"])).get("onedocker-cli")
task_definition = config["setting"]["task_definition"]
repository_path = config["setting"]["repository_path"]
checksum_repository_path = config["setting"].get("checksum_repository_path", "")

attestation_svc = AttestationService()
storage_svc = _build_storage_service(config["dependency"]["StorageService"])
container_svc = _build_container_service(config["dependency"]["ContainerService"])
onedocker_svc = OneDockerService(container_svc, task_definition)
onedocker_package_repo = OneDockerPackageRepository(storage_svc, repository_path)
onedocker_checksum_repo = OneDockerChecksumRepository(
storage_svc, checksum_repository_path
)
log_svc = _build_log_service(config["dependency"]["LogService"])

status = "enabled" if enable_attestation else "disabled"
logger.info(f"Package tracking for package {package_name}: {version} is {status}")
onedocker_package_repo = OneDockerPackageRepository(storage_svc, repository_path)

if arguments["upload"]:
enable_attestation = arguments["--enable_attestation"]
status = "enabled" if enable_attestation else "disabled"
logger.info(
f"Package tracking for package {package_name}: {version} is {status}"
)
checksum_repository_path = (
config["setting"].get("checksum_repository_path")
if enable_attestation
else ""
)

onedocker_checksum_repo = OneDockerChecksumRepository(
storage_svc, checksum_repository_path
)

_upload(package_dir, package_name, version, enable_attestation)
elif arguments["test"]:
timeout = arguments["--timeout"] if arguments["--timeout"] else DEFAULT_TIMEOUT

log_svc = _build_log_service(config["dependency"]["LogService"])

_test(package_name, version, arguments["--cmd_args"], timeout)
elif arguments["show"]:
_show(package_name, arguments["--version"])
Expand Down

0 comments on commit 1269ceb

Please sign in to comment.