-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_in_docker.py
More file actions
44 lines (35 loc) · 1.3 KB
/
run_in_docker.py
File metadata and controls
44 lines (35 loc) · 1.3 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
#!/usr/bin/env python
import subprocess
import pathlib
import argparse
import random
# By appending "|| true" execution is allowed to continue even when 0 isn't returned.
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Run or update a docker container for a bot"
)
parser.add_argument(
"--mount", type=pathlib.Path, metavar='m', required=True,
help="An absolute path to a folder that contains configuration"
" and storage to be used by the bot. This becomes the argument that"
" is passed to the bot when running it.")
parser.add_argument('-s', '--skipdelete',
action='store_true')
args = parser.parse_args()
mount_src = args.mount.absolute()
mount_dest = "/config"
project_path = pathlib.Path(pathlib.Path(__file__).parent).absolute()
env_file = str(mount_src / ".env")
print("Deleting")
if not args.skipdelete:
subprocess.run(
args=["docker", "compose", "--env-file", env_file, "down", "--rmi", "all"],
check=True,
cwd=project_path
)
print("Running")
subprocess.run(
args=["docker", "compose", "--env-file", env_file, "up", "-d"],
check=True,
cwd=project_path
)