Skip to content

Commit

Permalink
Add load-image command and clarify documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed May 4, 2023
1 parent 99501dd commit 0bd281b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ Usage
Number of layers to squash or ID of the layer (or image ID or image name) to squash from.
In case the provided value is an integer, specified number of layers will be squashed.
Every layer in the image will be squashed if the parameter is not provided.
-t TAG, --tag TAG Specify the tag to be used for the new image. If not
specified no tag will be applied
-t TAG, --tag TAG Specify the tag to be used for the new image. If not specified no tag will be applied
-m MESSAGE, --message MESSAGE
Specify a commit message (comment) for the new image.
-c, --cleanup Remove source image from Docker after squashing
--tmp-dir TMP_DIR Temporary directory to be created and used
--output-path OUTPUT_PATH
Path where the image should be stored after squashing.
If not provided, image will be loaded into Docker
daemon
Path where the image may be stored after squashing.
--load-image [LOAD_IMAGE]
Whether to load the image into Docker daemon after squashing
Default: true

Note that environment variables may be set as documented in `here <docs/environment_variables.adoc>`_.

Expand Down
23 changes: 21 additions & 2 deletions docker_squash/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ def filter(self, record):


class MyParser(argparse.ArgumentParser):
# noinspection PyMethodMayBeStatic
def str2bool(self, v: str) -> bool:
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
raise argparse.ArgumentTypeError("Boolean value expected.")

def error(self, message):
self.print_help()
sys.stderr.write("\nError: %s\n" % message)
Expand Down Expand Up @@ -92,7 +103,15 @@ def run(self):
)
parser.add_argument(
"--output-path",
help="Path where the image should be stored after squashing. If not provided, image will be loaded into Docker daemon",
help="Path where the image may be stored after squashing.",
)
parser.add_argument(
"--load-image",
type=parser.str2bool,
const=True,
nargs="?",
default=True,
help="Whether to load the image into Docker daemon after squashing",
)

args = parser.parse_args()
Expand All @@ -103,7 +122,6 @@ def run(self):
self.log.setLevel(logging.INFO)

self.log.debug("Running version %s", version)

try:
squash.Squash(
log=self.log,
Expand All @@ -112,6 +130,7 @@ def run(self):
tag=args.tag,
comment=args.message,
output_path=args.output_path,
load_image=args.load_image,
tmp_dir=args.tmp_dir,
development=args.development,
cleanup=args.cleanup,
Expand Down

0 comments on commit 0bd281b

Please sign in to comment.