Skip to content

Commit

Permalink
Merge pull request #229 from rnc/ISSUE195
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed May 4, 2023
2 parents 1e6ae47 + 0bd281b commit 9bcdecf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 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
2 changes: 1 addition & 1 deletion docker_squash/squash.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run(self):
docker_version = self.docker.version()
self.log.info(
"docker-squash version %s, Docker %s, API %s..."
% (version, docker_version["GitCommit"], docker_version["ApiVersion"])
% (version, docker_version["Version"], docker_version["ApiVersion"])
)

if self.image is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unit_squash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setUp(self):
self.log = mock.Mock()
self.docker_client = mock.Mock()
self.docker_client.version.return_value = {
"GitCommit": "commit/9.9.9",
"Version": "20.10.23",
"ApiVersion": "9.99",
}

Expand Down

0 comments on commit 9bcdecf

Please sign in to comment.