本文整理汇总了Python中docker.APIClient.push方法的典型用法代码示例。如果您正苦于以下问题:Python APIClient.push方法的具体用法?Python APIClient.push怎么用?Python APIClient.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker.APIClient
的用法示例。
在下文中一共展示了APIClient.push方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseDockerBuilder
# 需要导入模块: from docker import APIClient [as 别名]
# 或者: from docker.APIClient import push [as 别名]
#.........这里部分代码省略.........
def _get_requirements_path(self):
requirements_path = os.path.join(self.build_repo_path, 'polyaxon_requirements.txt')
if os.path.isfile(requirements_path):
return os.path.join(self.folder_name, 'polyaxon_requirements.txt')
return None
def _get_setup_path(self):
setup_file_path = os.path.join(self.build_repo_path, 'polyaxon_setup.sh')
has_setup = os.path.isfile(setup_file_path)
if has_setup:
st = os.stat(setup_file_path)
os.chmod(setup_file_path, st.st_mode | stat.S_IEXEC)
return os.path.join(self.folder_name, 'polyaxon_setup.sh')
return None
def render(self):
docker_template = jinja2.Template(POLYAXON_DOCKER_TEMPLATE)
return docker_template.render(
from_image=self.from_image,
polyaxon_requirements_path=self.polyaxon_requirements_path,
polyaxon_setup_path=self.polyaxon_setup_path,
build_steps=self.build_steps,
env_vars=self.env_vars,
folder_name=self.folder_name,
workdir=self.WORKDIR,
nvidia_bin=settings.MOUNT_PATHS_NVIDIA.get('bin'),
copy_code=self.copy_code
)
def build(self, memory_limit=None):
_logger.debug('Starting build in `%s`', self.build_repo_path)
# Checkout to the correct commit
if self.image_tag != self.LATEST_IMAGE_TAG:
git.checkout_commit(repo_path=self.build_repo_path, commit=self.image_tag)
limits = {
# Always disable memory swap for building, since mostly
# nothing good can come of that.
'memswap': -1
}
if memory_limit:
limits['memory'] = memory_limit
# Create DockerFile
with open(self.dockerfile_path, 'w') as dockerfile:
dockerfile.write(self.render())
check_pulse = 0
for log_line in self.docker.build(
path=self.build_path,
tag=self.get_tagged_image(),
buildargs={},
decode=True,
forcerm=True,
rm=True,
pull=True,
nocache=False,
container_limits=limits,
):
self._handle_logs(log_line)
# Check if we need to stop this process
check_pulse, should_stop = self._check_pulse(check_pulse)
if should_stop:
return False
# Checkout back to master
if self.image_tag != self.LATEST_IMAGE_TAG:
git.checkout_commit(repo_path=self.build_repo_path)
return True
def push(self):
# Build a progress setup for each layer, and only emit per-layer info every 1.5s
layers = {}
last_emit_time = time.time()
check_pulse = 0
for log_line in self.docker.push(self.image_name, tag=self.image_tag, stream=True):
lines = [l for l in log_line.decode('utf-8').split('\r\n') if l]
lines = [json.loads(l) for l in lines]
for progress in lines:
if 'error' in progress:
_logger.error(progress['error'], extra=dict(phase='failed'))
return
if 'id' not in progress:
continue
if 'progressDetail' in progress and progress['progressDetail']:
layers[progress['id']] = progress['progressDetail']
else:
layers[progress['id']] = progress['status']
if time.time() - last_emit_time > 1.5:
_logger.debug('Pushing image\n', extra=dict(progress=layers, phase='pushing'))
last_emit_time = time.time()
self._handle_logs(log_line)
# Check if we need to stop this process
check_pulse, should_stop = self._check_pulse(check_pulse)
if should_stop:
return False
return True
示例2: DockerBuilder
# 需要导入模块: from docker import APIClient [as 别名]
# 或者: from docker.APIClient import push [as 别名]
#.........这里部分代码省略.........
log_lines.append('Push finished: {}'.format(json_line.get('aux')))
else:
log_lines.append(str(json_line))
except json.JSONDecodeError:
log_lines.append('JSON decode error: {}'.format(raw_line))
return log_lines
def _handle_logs(self, log_lines):
publisher.publish_build_job_log(
log_lines=log_lines,
job_uuid=self.job_uuid,
job_name=self.job_name
)
def _handle_log_stream(self, stream):
log_lines = []
last_emit_time = time.time()
try:
for log_line in stream:
log_lines += self._prepare_log_lines(log_line)
publish_cond = (
len(log_lines) == publisher.MESSAGES_COUNT or
(log_lines and time.time() - last_emit_time > publisher.MESSAGES_TIMEOUT)
)
if publish_cond:
self._handle_logs(log_lines)
log_lines = []
last_emit_time = time.time()
if log_lines:
self._handle_logs(log_lines)
except (BuildError, APIError, DockerBuilderError) as e:
self._handle_logs('Build Error {}'.format(e))
return False
return True
def _get_requirements_path(self):
requirements_path = os.path.join(self.repo_path, 'polyaxon_requirements.txt')
if os.path.isfile(requirements_path):
return os.path.join(self.folder_name, 'polyaxon_requirements.txt')
return None
def _get_setup_path(self):
setup_file_path = os.path.join(self.repo_path, 'polyaxon_setup.sh')
has_setup = os.path.isfile(setup_file_path)
if has_setup:
st = os.stat(setup_file_path)
os.chmod(setup_file_path, st.st_mode | stat.S_IEXEC)
return os.path.join(self.folder_name, 'polyaxon_setup.sh')
return None
def render(self):
docker_template = jinja2.Template(POLYAXON_DOCKER_TEMPLATE)
return docker_template.render(
from_image=self.from_image,
polyaxon_requirements_path=self.polyaxon_requirements_path,
polyaxon_setup_path=self.polyaxon_setup_path,
build_steps=self.build_steps,
env_vars=self.env_vars,
folder_name=self.folder_name,
workdir=self.WORKDIR,
nvidia_bin=settings.MOUNT_PATHS_NVIDIA.get('bin'),
copy_code=self.copy_code
)
def build(self, nocache=False, memory_limit=None):
_logger.debug('Starting build in `%s`', self.repo_path)
# Checkout to the correct commit
if self.image_tag != self.LATEST_IMAGE_TAG:
git.checkout_commit(repo_path=self.repo_path, commit=self.image_tag)
limits = {
# Always disable memory swap for building, since mostly
# nothing good can come of that.
'memswap': -1
}
if memory_limit:
limits['memory'] = memory_limit
# Create DockerFile
with open(self.dockerfile_path, 'w') as dockerfile:
rendered_dockerfile = self.render()
celery_app.send_task(
SchedulerCeleryTasks.BUILD_JOBS_SET_DOCKERFILE,
kwargs={'build_job_uuid': self.job_uuid, 'dockerfile': rendered_dockerfile})
dockerfile.write(rendered_dockerfile)
stream = self.docker.build(
path=self.build_path,
tag=self.get_tagged_image(),
forcerm=True,
rm=True,
pull=True,
nocache=nocache,
container_limits=limits)
return self._handle_log_stream(stream=stream)
def push(self):
stream = self.docker.push(self.image_name, tag=self.image_tag, stream=True)
return self._handle_log_stream(stream=stream)