Add --port option to run-webapp. (#667)

* Add --port option to run-webapp

* Fixed merge

* lint
This commit was merged in pull request #667.
This commit is contained in:
2023-11-29 11:32:28 -06:00
committed by GitHub
parent 113c0bfbf1
commit 03a3645b3c
4 changed files with 14 additions and 8 deletions
+10 -4
View File
@@ -27,13 +27,16 @@ from dotenv import dotenv_values
from stack_orchestrator import constants
from stack_orchestrator.deploy.deployer_factory import getDeployer
WEBAPP_PORT = 3000
@click.command()
@click.option("--image", help="image to deploy", required=True)
@click.option("--env-file", help="environment file for webapp")
@click.option("--port", help="port to use (default random)")
@click.pass_context
def command(ctx, image, env_file):
'''build the specified webapp container'''
def command(ctx, image, env_file, port):
'''run the specified webapp container'''
env = {}
if env_file:
@@ -49,10 +52,13 @@ def command(ctx, image, env_file):
compose_project_name=cluster,
compose_env_file=None)
container = deployer.run(image, command=[], user=None, volumes=[], entrypoint=None, env=env, detach=True)
ports = []
if port:
ports = [(port, WEBAPP_PORT)]
container = deployer.run(image, command=[], user=None, volumes=[], entrypoint=None, env=env, ports=ports, detach=True)
# Make configurable?
webappPort = "3000/tcp"
webappPort = f"{WEBAPP_PORT}/tcp"
# TODO: This assumes a Docker container object...
if webappPort in container.network_settings.ports:
mapping = container.network_settings.ports[webappPort][0]