Commit 8eb572c2 authored by Jonathan Osorio Alcalá's avatar Jonathan Osorio Alcalá
Browse files

[REF] gitlab_tools: add 'DOCKER_IMAGE_REPO' for the new tag format.

parent de3374b7
Pipeline #145463 passed with stage
in 11 seconds
......@@ -62,7 +62,10 @@ def build_image(**kwargs):
if config.get('push_image'):
# TODO: if we decide to build and push every image, just move the _IMAGE_TAG outside the if
if config.get('ci_commit_ref_name') == config['version']:
common.push_image(config, config['instance_image'], 'latest')
tag_latest = 'latest'
if config.get('docker_image_repo'):
tag_latest = '%s-%s-latest' % (config['main_app'], config['version'])
common.push_image(config, config['instance_image'], tag_latest)
is_latest = True
common.push_image(config, config['instance_image'], config['image_tag'])
common.notify_orchest(config, is_latest=is_latest)
......
......@@ -81,9 +81,12 @@ def run_build_image(config):
sys.exit(1)
image_sha = images[0].get('Id')
short_id = image_sha.split(':')[1][:10]
config.update({
'image_tag': short_id,
})
tag = short_id
if config.get('docker_image_repo'):
tag = "%s-%s-%s" % (config['main_app'], config['version'], short_id)
if config.get('ci_commit_ref_name') != config['version']:
tag = "%s-%s-dev%s" % (config['main_app'], config['version'], short_id)
config.update({'image_tag': tag})
def clear_images(config):
......@@ -116,14 +119,15 @@ def reciveSignal(signalNumber, frame):
def push_image(config, image_name, image_tag):
_logger.info('Pushing image %s to %s:%s', image_name, config['image_repo'], image_tag)
_cli.tag(image_name, config['image_repo'], tag=image_tag)
img_repo = config.get('docker_image_repo') or config['image_repo']
_logger.info('Pushing image %s to %s:%s', image_name, img_repo, image_tag)
_cli.tag(image_name, img_repo, tag=image_tag)
if is_docker_login(config):
_logger.info('Logging in to push: %s', config['docker_repo'])
_cli.login(config['docker_user'], config['docker_password'], registry=config['docker_repo'])
for attempt in range(4):
try:
for result in _cli.push(config['image_repo'], tag=image_tag, stream=True):
for result in _cli.push(img_repo, tag=image_tag, stream=True):
result = json.loads(utils.decode(result))
if result.get('error'):
_logger.error(result.get('error'))
......@@ -140,7 +144,8 @@ def push_image(config, image_name, image_tag):
def notify_orchest(config, is_latest=False):
image_name = '{image}:{tag}'.format(image=config['image_repo'], tag=config['image_tag'])
img_repo = config.get('docker_image_repo') or config['image_repo']
image_name = '{image}:{tag}'.format(image=img_repo, tag=config['image_tag'])
res = requests.post(
config['orchest_registry'], data=json.dumps({
'image_name': image_name, 'is_latest': is_latest, 'branch_name': config['ci_commit_ref_name'],
......@@ -317,7 +322,8 @@ def save_imagename(config):
makedirs(config["ci_commit_ref_name"])
filename = path.join(config["ci_commit_ref_name"], "image_name.env")
with open(filename, "w") as f:
f.write("export IMAGE_REPO={}\n".format(config['image_repo']))
img = config.get('docker_image_repo') or config['image_repo']
f.write("export IMAGE_REPO={}\n".format(img))
f.write("export IMAGE_TAG={}\n".format(config['image_tag']))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment