-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathdocker.py
More file actions
72 lines (53 loc) · 1.82 KB
/
Copy pathdocker.py
File metadata and controls
72 lines (53 loc) · 1.82 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
70
71
72
import logging
import os
import subprocess
from pathlib import Path
from multiversx_sdk_cli.errors import KnownError
logger = logging.getLogger("docker")
def is_docker_installed():
try:
result = subprocess.run(["docker", "--version"], capture_output=True, text=True)
output = result.stdout
if "Docker version" in output:
return True
else:
return False
except Exception:
logger.error("Something went wrong when checking if docker is installed!")
def run_docker(
image: str,
project_path: Path,
contract: str,
output_path: Path,
no_wasm_opt: bool,
docker_interactive: bool,
docker_tty: bool,
no_default_platform: bool,
):
docker_mount_args: list[str] = ["--volume", f"{output_path}:/output"]
if project_path:
docker_mount_args.extend(["--volume", f"{project_path}:/project"])
docker_args = ["docker", "run"]
if not (no_default_platform):
docker_args += ["--platform", "linux/amd64"]
if docker_interactive:
docker_args += ["--interactive"]
if docker_tty:
docker_args += ["--tty"]
docker_args += docker_mount_args
docker_args += ["--user", f"{str(os.getuid())}:{str(os.getgid())}"]
docker_args += ["--rm", image]
entrypoint_args: list[str] = []
if project_path:
entrypoint_args.extend(["--project", "project"])
if no_wasm_opt:
entrypoint_args.append("--no-wasm-opt")
if contract:
entrypoint_args.extend(["--contract", contract])
args = docker_args + entrypoint_args
logger.info(f"Docker running with args: {args}")
try:
result = subprocess.run(args)
result.check_returncode()
except subprocess.CalledProcessError as error:
raise KnownError(f"Docker run failed with error code: {error.returncode}")