-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
69 lines (55 loc) · 1.37 KB
/
cli.py
File metadata and controls
69 lines (55 loc) · 1.37 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pexpect
import typer
from pathlib import Path
import os, pwd
app = typer.Typer()
DOCKER_IMAGE = "yosoufe/vamr"
def bash_cmd(command: str):
"""
run a bash command
"""
typer.echo(f"executing: {command}")
child = pexpect.spawn(command)
child.interact()
child.close(True)
return child.signalstatus
@app.command()
def build():
"""
build the docker image
"""
bash_cmd(f"docker build . -t {DOCKER_IMAGE}")
@app.command()
def run():
"""
run the docker image
"""
bash_cmd("xhost +")
bash_cmd("docker run "
"--name vamr "
"-it "
"--device /dev/video0 "
"--network host "
"-e DISPLAY "
"--privileged "
"--runtime=nvidia "
"--gpus all "
"--rm "
# "-v /etc/passwd:/etc/passwd "
# f"-u {pwd.getpwnam(os.getenv('USER')).pw_uid}:{pwd.getpwnam(os.getenv('USER')).pw_gid} "
f"-v {Path(__file__).parent.resolve()}:/code "
f"{DOCKER_IMAGE}")
@app.command()
def push():
"""
push the docker image to docker hub as yosoufe/opencv_cuda
"""
bash_cmd(f"docker push {DOCKER_IMAGE}")
@app.command()
def pull():
"""
pull the docker image from the docker hub
"""
bash_cmd(f'docker pull {DOCKER_IMAGE}')
if __name__ == "__main__":
app()