Skip to content

Commit

Permalink
FIXUP: Improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrgio committed Jan 14, 2025
1 parent aa710e8 commit 92d8a4c
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions install/common/build-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ def str2bool(v):
raise argparse.ArgumentTypeError("Boolean value expected.")


def determine_tag():
# Designate a unique tag for this image, depending on the Git commit it was created
# from:
# 1. If created from a Git tag (e.g., 0.8.0), the image tag will be `0.8.0`.
# 2. If created from a commit, it will be something like `0.8.0-31-g6bdaa7a`.
# 3. If the contents of the Git repo are dirty, we will append a unique identifier
# for this run, something like `0.8.0-31-g6bdaa7a-fdcb` or `0.8.0-fdcb`.
dirty_ident = secrets.token_hex(2)
return (
subprocess.check_output(
[
"git",
"describe",
"--long",
"--first-parent",
f"--dirty=-{dirty_ident}",
],
)
.decode()
.strip()[1:] # remove the "v" prefix of the tag.
)


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -67,30 +90,7 @@ def main():

print(f"Building for architecture '{ARCH}'")

if args.tag:
tag = args.tag
else:
# Designate a unique tag for this image, depending on the Git commit it was created
# from:
# 1. If created from a Git tag (e.g., 0.8.0), the image tag will be `0.8.0`.
# 2. If created from a commit, it will be something like `0.8.0-31-g6bdaa7a`.
# 3. If the contents of the Git repo are dirty, we will append a unique identifier
# for this run, something like `0.8.0-31-g6bdaa7a-fdcb` or `0.8.0-fdcb`.
dirty_ident = secrets.token_hex(2)
tag = (
subprocess.check_output(
[
"git",
"describe",
"--long",
"--first-parent",
f"--dirty=-{dirty_ident}",
],
)
.decode()
.strip()[1:] # remove the "v" prefix of the tag.
)

tag = args.tag or determine_tag()
image_name_tagged = IMAGE_NAME + ":" + tag

print(f"Will tag the container image as '{image_name_tagged}'")
Expand Down

0 comments on commit 92d8a4c

Please sign in to comment.