Fix ImageManager inconsistencies

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-10-12 06:39:56 -07:00
parent 297bee897b
commit bd67b90869
2 changed files with 13 additions and 16 deletions

View File

@ -266,7 +266,7 @@ def finalize(args):
raise ScriptError('No PR found for {}'.format(args.release))
if not check_pr_mergeable(pr_data):
raise ScriptError('Can not finalize release with an unmergeable PR')
if not img_manager.check_images(args.release):
if not img_manager.check_images():
raise ScriptError('Missing release image')
br_name = branch_name(args.release)
if not repository.branch_exists(br_name):

View File

@ -27,13 +27,12 @@ class ImageManager(object):
def build_images(self, repository, files):
print("Building release images...")
repository.write_git_sha()
docker_client = docker.APIClient(**docker.utils.kwargs_from_env())
distdir = os.path.join(REPO_ROOT, 'dist')
os.makedirs(distdir, exist_ok=True)
shutil.copy(files['docker-compose-Linux-x86_64'][0], distdir)
os.chmod(os.path.join(distdir, 'docker-compose-Linux-x86_64'), 0o755)
print('Building docker/compose image')
logstream = docker_client.build(
logstream = self.docker_client.build(
REPO_ROOT, tag='docker/compose:{}'.format(self.version), dockerfile='Dockerfile.run',
decode=True
)
@ -44,7 +43,7 @@ class ImageManager(object):
print(chunk['stream'], end='')
print('Building test image (for UCP e2e)')
logstream = docker_client.build(
logstream = self.docker_client.build(
REPO_ROOT, tag='docker-compose-tests:tmp', decode=True
)
for chunk in logstream:
@ -53,13 +52,15 @@ class ImageManager(object):
if 'stream' in chunk:
print(chunk['stream'], end='')
container = docker_client.create_container(
container = self.docker_client.create_container(
'docker-compose-tests:tmp', entrypoint='tox'
)
docker_client.commit(container, 'docker/compose-tests', 'latest')
docker_client.tag('docker/compose-tests:latest', 'docker/compose-tests:{}'.format(self.version))
docker_client.remove_container(container, force=True)
docker_client.remove_image('docker-compose-tests:tmp', force=True)
self.docker_client.commit(container, 'docker/compose-tests', 'latest')
self.docker_client.tag(
'docker/compose-tests:latest', 'docker/compose-tests:{}'.format(self.version)
)
self.docker_client.remove_container(container, force=True)
self.docker_client.remove_image('docker-compose-tests:tmp', force=True)
@property
def image_names(self):
@ -69,23 +70,19 @@ class ImageManager(object):
'docker/compose:{}'.format(self.version)
]
def check_images(self, version):
docker_client = docker.APIClient(**docker.utils.kwargs_from_env())
def check_images(self):
for name in self.image_names:
try:
docker_client.inspect_image(name)
self.docker_client.inspect_image(name)
except docker.errors.ImageNotFound:
print('Expected image {} was not found'.format(name))
return False
return True
def push_images(self):
docker_client = docker.APIClient(**docker.utils.kwargs_from_env())
for name in self.image_names:
print('Pushing {} to Docker Hub'.format(name))
logstream = docker_client.push(name, stream=True, decode=True)
logstream = self.docker_client.push(name, stream=True, decode=True)
for chunk in logstream:
if 'status' in chunk:
print(chunk['status'])