mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-15 20:50:42 +00:00
This PR adds infrastructure to automatically cache docker images used in CI builds in a container registry. Currently, build images are pulled from a container registry for some builds and built every time for others. The container registry requires maintenance to keep the images up to date and building images every time wastes build agent resources. With this change, a given build image can be looked up in a cache container registry and if present, pulled, and otherwise, built and pushed. The uniqueness of a build image is determined by a hash digest of the dockerfile, docker build context directory, and certain "docker build" options. This digest is part of the image tag in the cache container repository. The cache container registry will need to be cleaned up periodically. This is not automated yet.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
import logging
|
|
import os
|
|
import subprocess
|
|
|
|
|
|
_log = logging.getLogger("util.run")
|
|
|
|
|
|
def run(*args, cwd=None, capture=False, shell=False, env=None, check=True,
|
|
quiet=False):
|
|
"""Runs a subprocess.
|
|
|
|
Args:
|
|
*args: The subprocess arguments.
|
|
cwd: The working directory. If None, specifies the current directory.
|
|
capture: Whether to capture stdout and stderr.
|
|
shell: Whether to run using the shell.
|
|
env: The environment variables as a dict. If None, inherits the current
|
|
environment.
|
|
check: Whether to raise an error if the return code is not zero.
|
|
quiet: If true, do not print output from the subprocess.
|
|
|
|
Returns:
|
|
A subprocess.CompletedProcess instance.
|
|
"""
|
|
cmd = [*args]
|
|
|
|
_log.info("Running subprocess in '{0}'\n{1}".format(
|
|
cwd or os.getcwd(), cmd))
|
|
|
|
output = \
|
|
subprocess.PIPE if capture else (subprocess.DEVNULL if quiet else None)
|
|
completed_process = subprocess.run(
|
|
cmd, cwd=cwd, check=check, stdout=output, stderr=output, env=env,
|
|
shell=shell)
|
|
|
|
_log.debug("Subprocess completed. Return code: {}".format(
|
|
completed_process.returncode))
|
|
|
|
return completed_process
|