Skip to content

Commit

Permalink
Sanity checks for bake's shard args.
Browse files Browse the repository at this point in the history
  • Loading branch information
razvan committed Oct 16, 2023
1 parent df3d010 commit b2fa095
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/image_tools/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def bake_args() -> Namespace:
required=True,
type=check_image_version_format,
)
parser.add_argument("-p", "--product", help="Product to build images for", action='append')
parser.add_argument("--shard-count", type=int, default=1)
parser.add_argument("--shard-index", type=int, default=0)
parser.add_argument("-p", "--product",
help="Product to build images for", action='append')
parser.add_argument("--shard-count", type=positive_int, default=1)
parser.add_argument("--shard-index", type=positive_int, default=0)
parser.add_argument("-u", "--push", help="Push images",
action="store_true")
parser.add_argument("-d", "--dry", help="Dry run.", action="store_true")
Expand All @@ -55,7 +56,23 @@ def bake_args() -> Namespace:
help="Image registry to publish to. Default: docker.stackable.tech",
default="docker.stackable.tech",
)
return parser.parse_args()
result = parser.parse_args()

if result.shard_index is not None and result.shard_index >= result.shard_count:
raise ValueError("shard index [{}] cannot be greater or equal than shard count [{}]".format(
result.shard_index, result.shard_count))
return result


def positive_int(value) -> int:
try:
ivalue = int(value)
if ivalue < 0:
raise ValueError
return ivalue
except ValueError:
raise ValueError(
f"Invalid value [{value}]. Must be an integer greater than or equal to zero.")


def check_image_version_format(image_version) -> str:
Expand Down

0 comments on commit b2fa095

Please sign in to comment.