Implement deploy-system port command

Former-commit-id: ea6f932e00
This commit is contained in:
David Boreham 2023-01-23 22:09:56 -07:00
parent 3d7d23b68b
commit 629e484c30
6 changed files with 37 additions and 8 deletions

View File

@ -3,3 +3,5 @@ services:
test: test:
image: cerc/test-container:local image: cerc/test-container:local
restart: always restart: always
ports:
- "80"

View File

@ -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 COPY run.sh /app/run.sh

View File

@ -12,5 +12,5 @@ else
echo `date` > $EXISTSFILENAME echo `date` > $EXISTSFILENAME
fi fi
# Sleep forever to keep docker happy # Run nginx which will block here forever
while true; do sleep 10; done /usr/sbin/nginx -g "daemon off;"

View File

@ -0,0 +1,3 @@
# Test Stack
A stack for test/demo purposes.

View File

@ -0,0 +1,7 @@
version: "1.0"
name: test
description: "A test stack"
containers:
- cerc/test-container
pods:
- test

View File

@ -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("--exclude", help="don\'t start these components")
@click.option("--cluster", help="specify a non-default cluster name") @click.option("--cluster", help="specify a non-default cluster name")
@click.argument('command', required=True) # help: command: up|down|ps @click.argument('command', required=True) # help: command: up|down|ps
@click.argument('services', nargs=-1) # help: command: up|down|ps <service1> <service2> @click.argument('extra_args', nargs=-1) # help: command: up|down|ps <service1> <service2>
@click.pass_context @click.pass_context
def command(ctx, include, exclude, cluster, command, services): def command(ctx, include, exclude, cluster, command, extra_args):
'''deploy a stack''' '''deploy a stack'''
# TODO: implement option exclusion and command value constraint lost with the move from argparse to click # 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/ # See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/
docker = DockerClient(compose_files=compose_files, compose_project_name=cluster) 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 not dry_run:
if command == "up": if command == "up":
if verbose: if verbose:
print(f"Running compose up for services: {services_list}") print(f"Running compose up for extra_args: {extra_args_list}")
docker.compose.up(detach=True, services=services_list) docker.compose.up(detach=True, services=extra_args_list)
elif command == "down": elif command == "down":
if verbose: if verbose:
print("Running compose down") print("Running compose down")
docker.compose.down() docker.compose.down()
elif command == "port":
if extra_args_list is None or len(extra_args_list) < 2:
print("Usage: port <service> <exposed-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": elif command == "ps":
if verbose: if verbose:
print("Running compose ps") print("Running compose ps")