From ea6f932e001a7320f9c9dbf69b0a8bc91445ea48 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Mon, 23 Jan 2023 22:09:56 -0700 Subject: [PATCH 1/2] Implement deploy-system port command --- app/data/compose/docker-compose-test.yml | 2 ++ .../cerc-test-container/Dockerfile | 9 ++++++++- .../cerc-test-container/run.sh | 4 ++-- app/data/stacks/test/README.md | 3 +++ app/data/stacks/test/stack.yml | 7 +++++++ app/deploy_system.py | 20 ++++++++++++++----- 6 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 app/data/stacks/test/README.md create mode 100644 app/data/stacks/test/stack.yml diff --git a/app/data/compose/docker-compose-test.yml b/app/data/compose/docker-compose-test.yml index 058b2b3b..929f6feb 100644 --- a/app/data/compose/docker-compose-test.yml +++ b/app/data/compose/docker-compose-test.yml @@ -3,3 +3,5 @@ services: test: image: cerc/test-container:local restart: always + ports: + - "80" diff --git a/app/data/container-build/cerc-test-container/Dockerfile b/app/data/container-build/cerc-test-container/Dockerfile index 29b42a84..f4ef5506 100644 --- a/app/data/container-build/cerc-test-container/Dockerfile +++ b/app/data/container-build/cerc-test-container/Dockerfile @@ -1,4 +1,11 @@ -FROM alpine:latest +FROM ubuntu:latest + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && export DEBCONF_NOWARNINGS="yes" && \ + apt-get install -y software-properties-common && \ + apt-get install -y nginx && \ + apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +EXPOSE 80 COPY run.sh /app/run.sh diff --git a/app/data/container-build/cerc-test-container/run.sh b/app/data/container-build/cerc-test-container/run.sh index 5f59acab..2488b628 100755 --- a/app/data/container-build/cerc-test-container/run.sh +++ b/app/data/container-build/cerc-test-container/run.sh @@ -12,5 +12,5 @@ else echo `date` > $EXISTSFILENAME fi -# Sleep forever to keep docker happy -while true; do sleep 10; done \ No newline at end of file +# Run nginx which will block here forever +/usr/sbin/nginx -g "daemon off;" \ No newline at end of file diff --git a/app/data/stacks/test/README.md b/app/data/stacks/test/README.md new file mode 100644 index 00000000..aef333fc --- /dev/null +++ b/app/data/stacks/test/README.md @@ -0,0 +1,3 @@ +# Test Stack + +A stack for test/demo purposes. \ No newline at end of file diff --git a/app/data/stacks/test/stack.yml b/app/data/stacks/test/stack.yml new file mode 100644 index 00000000..2903fbd1 --- /dev/null +++ b/app/data/stacks/test/stack.yml @@ -0,0 +1,7 @@ +version: "1.0" +name: test +description: "A test stack" +containers: + - cerc/test-container +pods: + - test diff --git a/app/deploy_system.py b/app/deploy_system.py index 6771e5ee..da2ed069 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -30,9 +30,9 @@ from .util import include_exclude_check, get_parsed_stack_config @click.option("--exclude", help="don\'t start these components") @click.option("--cluster", help="specify a non-default cluster name") @click.argument('command', required=True) # help: command: up|down|ps -@click.argument('services', nargs=-1) # help: command: up|down|ps +@click.argument('extra_args', nargs=-1) # help: command: up|down|ps @click.pass_context -def command(ctx, include, exclude, cluster, command, services): +def command(ctx, include, exclude, cluster, command, extra_args): '''deploy a stack''' # TODO: implement option exclusion and command value constraint lost with the move from argparse to click @@ -87,17 +87,27 @@ def command(ctx, include, exclude, cluster, command, services): # See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/ docker = DockerClient(compose_files=compose_files, compose_project_name=cluster) - services_list = list(services) or None + extra_args_list = list(extra_args) or None if not dry_run: if command == "up": if verbose: - print(f"Running compose up for services: {services_list}") - docker.compose.up(detach=True, services=services_list) + print(f"Running compose up for extra_args: {extra_args_list}") + docker.compose.up(detach=True, services=extra_args_list) elif command == "down": if verbose: print("Running compose down") docker.compose.down() + elif command == "port": + if extra_args_list is None or len(extra_args_list) < 2: + print("Usage: port ") + sys.exit(1) + service_name = extra_args_list[0] + exposed_port = extra_args_list[1] + if verbose: + print("Running compose port") + mapped_port_data = docker.compose.port(service_name, exposed_port) + print(f"{mapped_port_data[0]}:{mapped_port_data[1]}") elif command == "ps": if verbose: print("Running compose ps") From 5f22afc78baa00bacdfb8f7bc5240e71ba1492c7 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Mon, 23 Jan 2023 22:11:24 -0700 Subject: [PATCH 2/2] Add trailing newline --- app/data/container-build/cerc-test-container/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/data/container-build/cerc-test-container/run.sh b/app/data/container-build/cerc-test-container/run.sh index 2488b628..b4757d9a 100755 --- a/app/data/container-build/cerc-test-container/run.sh +++ b/app/data/container-build/cerc-test-container/run.sh @@ -13,4 +13,4 @@ else fi # Run nginx which will block here forever -/usr/sbin/nginx -g "daemon off;" \ No newline at end of file +/usr/sbin/nginx -g "daemon off;"