handle more options from config
warn if repo is specified in config, because it doesn't make sense and will be ignored
only override config for ref/image/run/build if specified on the cli
requires both-directions config for run and build, to handle the default being inverted in a config file
MODIFY
repo2docker/__main__.py
repo2docker/__main__.py
@@ -114,6 +114,7 @@ def get_argparser():
argparser.add_argument(
"--ref",
+ default=None,
help=(
"Reference to build instead of default reference. For example"
" branch name or commit for a Git repository."
@@ -129,6 +130,14 @@ def get_argparser():
help="Do not actually build the image. Useful in conjunction with --debug.",
)
+ argparser.add_argument(
+ "--build",
+ dest="build",
+ action="store_true",
+ help="Build the image (default)",
+ )
+ argparser.set_defaults(build=None)
+
argparser.add_argument(
"--build-memory-limit",
help="Total Memory that can be used by the docker build process",
@@ -147,6 +156,14 @@ def get_argparser():
help="Do not run container after it has been built",
)
+ argparser.add_argument(
+ "--run",
+ dest="run",
+ action="store_true",
+ help="Run container after it has been built (default).",
+ )
+ argparser.set_defaults(run=None)
+
argparser.add_argument(
"--publish",
"-p",
@@ -181,6 +198,13 @@ def get_argparser():
action="store_true",
help="Push docker image to repository",
)
+ argparser.add_argument(
+ "--no-push",
+ dest="push",
+ action="store_false",
+ help="Don't push docker image to repository (default).",
+ )
+ argparser.set_defaults(push=None)
argparser.add_argument(
"--volume",
@@ -298,7 +322,13 @@ def make_r2d(argv=None):
key, _, val = a.partition("=")
r2d.extra_build_args[key] = val
+ # repo is a required arg, and should never come from config:
+ if "repo" in r2d.config.Repo2Docker:
+ r2d.log.warning(
+ f"Ignoring Repo2Docker.repo={r2d.repo!r} configuration, using {args.repo!r} from CLI."
+ )
r2d.repo = args.repo
+ if args.ref is not None:
r2d.ref = args.ref
# user wants to mount a local directory into the container for
@@ -320,13 +350,11 @@ def make_r2d(argv=None):
if args.image_name:
r2d.output_image_spec = args.image_name
- else:
- # we will pick a name after fetching the repository
- r2d.output_image_spec = ""
if args.json_logs is not None:
r2d.json_logs = args.json_logs
+ if args.build is not None:
r2d.dry_run = not args.build
if r2d.dry_run:
@@ -334,7 +362,9 @@ def make_r2d(argv=None):
args.run = False
args.push = False
+ if args.run is not None:
r2d.run = args.run
+ if args.push is not None:
r2d.push = args.push
# check against r2d.run and not args.run as r2d.run is false on

handle more options from config

- warn if repo is specified in config, because it doesn't make sense and will be ignored
- only override config for ref/image/run/build if specified on the cli

requires both-directions config for run and build, to handle the default being inverted in a config file