-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepo-ops.py
More file actions
executable file
·65 lines (55 loc) · 2.71 KB
/
repo-ops.py
File metadata and controls
executable file
·65 lines (55 loc) · 2.71 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
#! /usr/bin/env python3
import argparse
from repo_helpers.Repo_Helper import Repo_Helper as docktools
import os.path
helper = docktools()
packages = \
{
'repo_helper' :{
"dir" : os.path.join(helper.repo_root(), "repo_helpers"),
"relative_dir" : "repo_helpers",
"testcommand" : "pytest -s -v tests/test_helper.py",
"mount_dir" : "/workspace/"
},
'ssh-keys' :{
"dir" : os.path.join(helper.repo_root(), "ssh"),
"relative_dir" : "ssh",
"testcommand" : "pytest -s -v tests/test-ssh-keys.py",
"mount_dir" : "/workspace/"
}
}
def main():
"""Main function to build Docker images and run containers"""
parser = argparse.ArgumentParser(description="Builds and run different images and containers in this repo")
ops = ["build", "run", "test"]
parser.add_argument("--package", "-p", help="selects a package", choices=packages, default=None, required=True)
parser.add_argument("--operations", "-o", help="selects the operations", choices=ops, nargs="+")
parser.add_argument("--keep_running",
help="keeps the container running for debugging, if any started",
action="store_true",
default=False)
args = parser.parse_args()
helper = docktools(None)
#todo: operations must be: build package, test package, release package,
# not build container, run container
for op in args.operations:
if op == "build":
helper.build_docker_image(dockerfile=packages[args.package]["dir"], image_name=args.package)
elif op == "run":
helper.start_container(image_name=args.package, container_name=args.package, mount_dir=packages[args.package]["mount_dir"])
elif op == "test":
requirements_file = os.path.join(packages[args.package]["mount_dir"], packages[args.package]["relative_dir"], "requirements.txt")
print(requirements_file)
venv_dir=f".venv_{args.package}"
helper.create_venv_in_container(container_name=args.package, venv_dir=venv_dir)
helper.exec_in_container_venv(command=f"pip install -r {requirements_file}", container_name=args.package, venv_path=venv_dir)
helper.exec_in_container_venv(command=packages[args.package]["testcommand"], container_name=args.package, venv_path=venv_dir)
if args.keep_running == False:
if helper.get_containers(args.package) != []:
helper.stop_container(args.package)
helper.remove_container(args.package)
else:
print(f"keeping the container {args.package} running, you can enter it with:")
print(f"docker exec -it {args.package} bash")
if __name__ == "__main__":
main()