-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.py
62 lines (53 loc) · 1.74 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
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_version,
)
@task(default=True)
def cli(ctx, clean=False):
"""
Get a shell into the examples build container
"""
service = "build"
if not exists(DEV_FAASM_LOCAL) or clean:
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_BUILD_VERSION": get_version()})
docker_cmd = "docker compose up -d --no-recreate {}".format(service)
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_BUILD_VERSION": get_version()})
run(
"docker compose down",
shell=True,
check=True,
cwd=PROJ_ROOT,
env=build_env,
)