Add scripts to deploy apps via docker compose
This commit is contained in:
1 parent
2840ac284d
commit
4c93d20ce6
3 files changed
+121
No files matched your search
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
tools_path=$(dirname $(readlink -f $0))
|
||||
eval "$tools_path/ensure_venv.sh" 1> /dev/stdout 2> /dev/stderr
|
||||
eval "$tools_path/venv_exec.sh python $tools_path/py/deploy.py $@" 1> /dev/stdout 2> /dev/stderr
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
tools_path=$(dirname $(readlink -f $0))
|
||||
eval "$tools_path/ensure_venv.sh" 1> /dev/stdout 2> /dev/stderr
|
||||
eval "$tools_path/venv_exec.sh python $tools_path/py/deploy_api_server.py $@" 1> /dev/stdout 2> /dev/stderr
|
||||
@@ -0,0 +1,111 @@
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
import publish_api_server
|
||||
import publish_data_stream
|
||||
import publish_sparkd
|
||||
|
||||
|
||||
from core.argparse_utils import add_toggle_opt
|
||||
|
||||
|
||||
def _get_arg_parser():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Deploy sparkd, pubsub, md-publisher, webapp, and api server"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cmake-jobs",
|
||||
type=int,
|
||||
help="The number of cmake parallel jobs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--clean",
|
||||
action="store_true",
|
||||
help="Perform a clean build (remove artifacts from previous build)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--verbosity",
|
||||
metavar="{0-5}",
|
||||
choices=range(1, 6),
|
||||
type=int,
|
||||
help="The output verbosity level",
|
||||
)
|
||||
add_toggle_opt(parser, "build", help="Whether or not to build the services first")
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Preview the build commands without running them",
|
||||
)
|
||||
all_services = ["sparkd", "api-server", "pubsub", "md-publisher", "webapp"]
|
||||
parser.add_argument("services", nargs="*")
|
||||
parser.set_defaults(
|
||||
configuration="release",
|
||||
services=all_services,
|
||||
build=True,
|
||||
clean=False,
|
||||
verbosity=2,
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def deploy(args):
|
||||
def run(cmd):
|
||||
print(cmd)
|
||||
if args.dry_run:
|
||||
return
|
||||
subprocess.run(cmd, shell=True).check_returncode()
|
||||
|
||||
services: list[str] = args.services or []
|
||||
if args.build:
|
||||
build_all = len(services) == 0
|
||||
if build_all or "sparkd" in services:
|
||||
publish_sparkd.publish(
|
||||
publish_sparkd.PublishArgs(
|
||||
configuration="release",
|
||||
cmake_jobs=args.cmake_jobs,
|
||||
clean=args.clean,
|
||||
verbosity=args.verbosity,
|
||||
dry_run=args.dry_run,
|
||||
)
|
||||
)
|
||||
if build_all or any(
|
||||
[x in services for x in ["pubsub", "md-publisher", "webapp"]]
|
||||
):
|
||||
publish_data_stream.publish(
|
||||
publish_data_stream.PublishArgs(
|
||||
configuration="release",
|
||||
cmake_jobs=args.cmake_jobs,
|
||||
clean=args.clean,
|
||||
verbosity=args.verbosity,
|
||||
dry_run=args.dry_run,
|
||||
)
|
||||
)
|
||||
if build_all or "api-server" in services:
|
||||
publish_api_server.publish(
|
||||
publish_api_server.PublishArgs(
|
||||
configuration="release",
|
||||
cmake_jobs=args.cmake_jobs,
|
||||
clean=args.clean,
|
||||
verbosity=args.verbosity,
|
||||
dry_run=args.dry_run,
|
||||
)
|
||||
)
|
||||
service_args = " ".join(services)
|
||||
run(f"sudo docker compose down {service_args}")
|
||||
run(f"sudo docker compose build {service_args}")
|
||||
run(f"sudo docker compose up {service_args} -d")
|
||||
run(f"sudo docker compose logs {service_args} --follow")
|
||||
|
||||
|
||||
def _main():
|
||||
parser = _get_arg_parser()
|
||||
args = parser.parse_args()
|
||||
deploy(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
_main()
|
||||
except Exception as e:
|
||||
print(f"deploy.py failed: {e}")
|
||||
exit(1)
|
||||
Reference in new issue
Block a user