#!/usr/bin/env python3
import sys
import subprocess


if len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv:
    print('  Usage: ./release <image> [tag]...')
    print('Example: ./release sonar-scanner 3.2.0 3.2 3')
    sys.exit()

_, image, *tags = sys.argv

if not tags:
    tags = ['latest']

subprocess.check_call([
    'docker', 'build', image,
    *(f'--tag=kiwicom/{image}:{tag}' for tag in tags),
])
for tag in tags:
    subprocess.check_call(['docker', 'push', f'kiwicom/{image}:{tag}'])
