Merge pull request #2877 from coreos-inc/joseph.schorr/QS-24/step-parsing

Fix parsing of Dockerfile steps in newer versions of Docker
This commit is contained in:
josephschorr 2017-10-11 10:57:33 -04:00 committed by GitHub
commit ab304cb834
3 changed files with 33 additions and 3 deletions

View file

@ -11,6 +11,7 @@ from trollius import From, Return
from buildman.server import BuildJobResult
from buildman.component.basecomponent import BaseComponent
from buildman.component.buildparse import extract_current_step
from buildman.jobutil.buildjob import BuildJobLoadException
from buildman.jobutil.buildstatus import StatusHandler
from buildman.jobutil.workererror import WorkerError
@ -269,9 +270,7 @@ class BuildComponent(BaseComponent):
current_status_string = str(fully_unwrapped.encode('utf-8'))
if current_status_string and phase == BUILD_PHASE.BUILDING:
step_increment = re.search(r'Step ([0-9]+) :', current_status_string)
if step_increment:
current_step = int(step_increment.group(1))
current_step = extract_current_step(current_status_string)
# Parse and update the phase and the status_dict. The status dictionary contains
# the pull/push progress, as well as the current step index.

View file

@ -0,0 +1,15 @@
import re
def extract_current_step(current_status_string):
""" Attempts to extract the current step numeric identifier from the given status string. Returns the step
number or None if none.
"""
# Older format: `Step 12 :`
# Newer format: `Step 4/13 :`
step_increment = re.search(r'Step ([0-9]+)/([0-9]+) :', current_status_string)
if step_increment:
return int(step_increment.group(1))
step_increment = re.search(r'Step ([0-9]+) :', current_status_string)
if step_increment:
return int(step_increment.group(1))

View file

@ -0,0 +1,16 @@
import pytest
from buildman.component.buildparse import extract_current_step
@pytest.mark.parametrize('input,expected_step', [
("", None),
("Step a :", None),
("Step 1 :", 1),
("Step 1 : ", 1),
("Step 1/2 : ", 1),
("Step 2/17 : ", 2),
("Step 4/13 : ARG somearg=foo", 4),
])
def test_extract_current_step(input, expected_step):
assert extract_current_step(input) == expected_step