diff --git a/build-tag-push.py b/build-tag-push.py index 1dfafe22..55fbdb9d 100755 --- a/build-tag-push.py +++ b/build-tag-push.py @@ -65,4 +65,5 @@ for service_name, popen_object in push_operations.items(): with open(output_file, "w") as f: yaml.safe_dump(stack, f, default_flow_style=False) -print("Wrote new compose file: {}".format(output_file)) +print("Wrote new compose file.") +print("COMPOSE_FILE={}".format(output_file)) diff --git a/configure-ambassadors.py b/configure-ambassadors.py index 50979378..2efa1f1e 100755 --- a/configure-ambassadors.py +++ b/configure-ambassadors.py @@ -5,7 +5,8 @@ import subprocess import sys import yaml -stack = yaml.load(open(sys.argv[1])) +compose_file = os.environ.get("COMPOSE_FILE") or sys.argv[1] +stack = yaml.load(open(compose_file)) project_name = os.path.basename(os.path.realpath(".")) diff --git a/create-ambassadors.py b/create-ambassadors.py index 6c2e7870..666e0ead 100755 --- a/create-ambassadors.py +++ b/create-ambassadors.py @@ -5,7 +5,8 @@ import subprocess import sys import yaml -stack = yaml.load(open(sys.argv[1])) +compose_file = os.environ.get("COMPOSE_FILE") or sys.argv[1] +stack = yaml.load(open(compose_file)) project_name = os.path.basename(os.path.realpath(".")) diff --git a/link-to-ambassadors.py b/link-to-ambassadors.py index f3e2d0b3..824e781e 100755 --- a/link-to-ambassadors.py +++ b/link-to-ambassadors.py @@ -1,13 +1,30 @@ #!/usr/bin/env python +import os import sys import yaml -# You can specify 1 or 2 parameters: +# You can specify up to 2 parameters: +# - with 0 parameter, we will look for the COMPOSE_FILE env var # - with 1 parameter, the same file will be used for in and out # - with 2 parameters, the 1st is the input, the 2nd the output -input_file = sys.argv[1] -output_file = sys.argv[-1] +if len(sys.argv)==1: + if "COMPOSE_FILE" not in os.environ: + print("Please specify 1 or 2 file names, or set COMPOSE_FILE.") + sys.exit(1) + compose_file = os.environ["COMPOSE_FILE"] + if compose_file == "docker-compose.yml": + print("Refusing to operate directly on docker-compose.yml.") + print("Specify it on the command-line if that's what you want.") + sys.exit(1) + input_file, output_file = compose_file, compose_file +elif len(sys.argv)==2: + input_file, output_file = sys.argv[1], sys.argv[1] +elif len(sys.argv)==3: + input_file, output_file = sys.argv[1], sys.argv[2] +else: + print("Too many arguments. Please specify up to 2 file names.") + sys.exit(1) stack = yaml.load(open(input_file))