Skip to content
Snippets Groups Projects
Commit 2e829acd authored by Jenkins's avatar Jenkins Committed by Gerrit Code Review
Browse files

Merge "Add retries to build.py"

parents d3d7777e 4bce5cca
No related branches found
No related tags found
No related merge requests found
...@@ -12,11 +12,7 @@ ...@@ -12,11 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# TODO(SamYaple): Allow image pushing
# TODO(SamYaple): Single image building w/ optional parent building # TODO(SamYaple): Single image building w/ optional parent building
# TODO(SamYaple): Build only missing images
# TODO(SamYaple): Execute the source install script that will pull
# down and create tarball
# TODO(jpeeler): Add clean up handler for SIGINT # TODO(jpeeler): Add clean up handler for SIGINT
import argparse import argparse
...@@ -33,7 +29,6 @@ import sys ...@@ -33,7 +29,6 @@ import sys
import tempfile import tempfile
from threading import Thread from threading import Thread
import time import time
import traceback
import docker import docker
import jinja2 import jinja2
...@@ -47,11 +42,12 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) ...@@ -47,11 +42,12 @@ signal.signal(signal.SIGINT, signal.SIG_DFL)
class WorkerThread(Thread): class WorkerThread(Thread):
def __init__(self, queue, nocache, keep, threads): def __init__(self, queue, args):
self.queue = queue self.queue = queue
self.nocache = nocache self.nocache = args['no_cache']
self.forcerm = not keep self.forcerm = not args['keep']
self.threads = threads self.retries = args['retries']
self.threads = args['threads']
self.dc = docker.Client(**docker.utils.kwargs_from_env()) self.dc = docker.Client(**docker.utils.kwargs_from_env())
Thread.__init__(self) Thread.__init__(self)
...@@ -60,13 +56,14 @@ class WorkerThread(Thread): ...@@ -60,13 +56,14 @@ class WorkerThread(Thread):
while True: while True:
try: try:
data = self.queue.get(block=False) data = self.queue.get(block=False)
self.builder(data)
for _ in range(self.retries):
self.builder(data)
if data['status'] in ['built', 'parent_error']:
break
self.queue.task_done() self.queue.task_done()
except Queue.Empty: except Queue.Empty:
break break
except Exception:
traceback.print_exc()
self.queue.task_done()
def process_source(self, source, dest_dir): def process_source(self, source, dest_dir):
if source.get('type') == 'url': if source.get('type') == 'url':
...@@ -87,8 +84,8 @@ class WorkerThread(Thread): ...@@ -87,8 +84,8 @@ class WorkerThread(Thread):
LOG.info('Processing: {}'.format(image['name'])) LOG.info('Processing: {}'.format(image['name']))
image['status'] = "building" image['status'] = "building"
if (image['parent'] is not None and if image['parent'] is not None and \
image['parent']['status'] == "error"): image['parent']['status'] in ['error', 'parent_error']:
image['status'] = "parent_error" image['status'] = "parent_error"
return return
...@@ -116,7 +113,7 @@ class WorkerThread(Thread): ...@@ -116,7 +113,7 @@ class WorkerThread(Thread):
if 'errorDetail' in stream: if 'errorDetail' in stream:
image['status'] = "error" image['status'] = "error"
LOG.error(stream['errorDetail']['message']) LOG.error(stream['errorDetail']['message'])
raise Exception(stream['errorDetail']['message']) return
image['status'] = "built" image['status'] = "built"
...@@ -166,6 +163,10 @@ def argParser(): ...@@ -166,6 +163,10 @@ def argParser():
' logging.)', ' logging.)',
type=int, type=int,
default=8) default=8)
parser.add_argument('-r', '--retries',
help='The number of times to retry while building',
type=int,
default=3)
parser.add_argument('--template', parser.add_argument('--template',
help='Create dockerfiles from templates', help='Create dockerfiles from templates',
action='store_true', action='store_true',
...@@ -340,6 +341,7 @@ class KollaWorker(object): ...@@ -340,6 +341,7 @@ class KollaWorker(object):
image['name'] + ':' + self.tag image['name'] + ':' + self.tag
image['path'] = path image['path'] = path
image['parent'] = content.split(' ')[1].split('\n')[0] image['parent'] = content.split(' ')[1].split('\n')[0]
if self.namespace not in image['parent']: if self.namespace not in image['parent']:
image['parent'] = None image['parent'] = None
...@@ -418,8 +420,7 @@ def main(): ...@@ -418,8 +420,7 @@ def main():
# Returns a list of Queues for us to loop through # Returns a list of Queues for us to loop through
for pool in pools: for pool in pools:
for x in xrange(args['threads']): for x in xrange(args['threads']):
WorkerThread(pool, args['no_cache'], args['keep'], WorkerThread(pool, args).start()
args['threads']).start()
# block until queue is empty # block until queue is empty
pool.join() pool.join()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment