-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbocker
executable file
·46 lines (37 loc) · 1.17 KB
/
bocker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
import re
import click
import sys
from commands.pull_command import run_pull
from commands.run_command import run_run
IMAGE_TAG_PATTERN = r'(?P<image>[^/:]+)(:)?(?P<tag>[^/:]*)'
@click.group()
def cli():
pass
@click.command()
@click.argument('image_name')
def pull(image_name):
match = re.match(IMAGE_TAG_PATTERN, image_name)
if not match:
print('invalid args')
sys.exit(1)
image = match.group('image')
tag = match.group('tag') if match.group('tag') else 'latest'
run_pull(image, tag)
@click.command()
@click.argument('image_name', required=True)
@click.option('--cpus', help='Number of CPUs', default=None, type=float)
@click.option('--memory',help='Memory limit in bytes.', default=None)
@click.argument('command', required=True, nargs=-1)
def run(image_name, cpus, memory, command):
match = re.match(IMAGE_TAG_PATTERN, image_name)
if not match:
print('invalid args')
sys.exit(1)
image = match.group('image')
tag = match.group('tag') if match.group('tag') else 'latest'
run_run(image, tag, cpus, memory, command)
cli.add_command(pull)
cli.add_command(run)
if __name__ == '__main__':
cli()