-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.py
72 lines (65 loc) · 1.99 KB
/
cli.py
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
from faasmtools.build import FAASM_LOCAL_DIR
from invoke import task
from os import environ, makedirs
from os.path import exists
from shutil import rmtree
from subprocess import run
from tasks.env import (
DEV_FAASM_LOCAL,
EXAMPLES_BUILD_IMAGE_NAME,
PROJ_ROOT,
get_faasm_version,
get_version,
)
@task(default=True)
def cli(ctx, service, clean=False, sgx=False):
"""
Get a shell into one of the containers: `build` or `run`
"""
if clean:
# Clean existing build
if exists(DEV_FAASM_LOCAL):
rmtree(DEV_FAASM_LOCAL)
makedirs(DEV_FAASM_LOCAL)
# Populate the local mounts with the existing content
tmp_ctr_name = "examples-build"
docker_cmd = "docker run -i -d --name {} {}:{}".format(
tmp_ctr_name, EXAMPLES_BUILD_IMAGE_NAME, get_version()
)
run(docker_cmd, shell=True, check=True)
run(
"docker cp examples-build:{}/. {}".format(
FAASM_LOCAL_DIR, DEV_FAASM_LOCAL
),
shell=True,
check=True,
)
run("docker rm -f {}".format(tmp_ctr_name), shell=True, check=True)
build_env = environ.copy()
build_env.update(
{
"EXAMPLES_RUN_VERSION": get_faasm_version(),
"EXAMPLES_BUILD_VERSION": get_version(),
"SGX_CLI_SUFFIX": "-sgx-sim" if sgx else "",
}
)
docker_cmd = "docker compose up -d --no-recreate"
run(docker_cmd, shell=True, check=True, cwd=PROJ_ROOT, env=build_env)
docker_cmd = "docker compose exec -it {} bash".format(service)
run(docker_cmd, shell=True, check=True, cwd=PROJ_ROOT, env=build_env)
@task()
def stop(ctx):
build_env = environ.copy()
build_env.update(
{
"EXAMPLES_RUN_VERSION": get_faasm_version(),
"EXAMPLES_BUILD_VERSION": get_version(),
}
)
run(
"docker compose down",
shell=True,
check=True,
cwd=PROJ_ROOT,
env=build_env,
)