mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Allow setting a tag for the container image
Allow setting a tag for the container image, when building it with the `build-image.py` script. This should be used for development purposes only, since the proper image name should be dictated by the script.
This commit is contained in:
parent
3ebc454b61
commit
ab10d5b6dd
1 changed files with 29 additions and 14 deletions
|
@ -27,6 +27,29 @@ def str2bool(v):
|
||||||
raise argparse.ArgumentTypeError("Boolean value expected.")
|
raise argparse.ArgumentTypeError("Boolean value expected.")
|
||||||
|
|
||||||
|
|
||||||
|
def determine_git_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():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -55,6 +78,11 @@ def main():
|
||||||
const=True,
|
const=True,
|
||||||
help="Use the builder's cache to speed up the builds",
|
help="Use the builder's cache to speed up the builds",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--tag",
|
||||||
|
default=None,
|
||||||
|
help="Provide a custom tag for the image (for development only)",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
tarball_path = Path("share") / "container.tar.gz"
|
tarball_path = Path("share") / "container.tar.gz"
|
||||||
|
@ -62,20 +90,7 @@ def main():
|
||||||
|
|
||||||
print(f"Building for architecture '{ARCH}'")
|
print(f"Building for architecture '{ARCH}'")
|
||||||
|
|
||||||
# Designate a unique tag for this image, depending on the Git commit it was created
|
tag = args.tag or determine_git_tag()
|
||||||
# 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.
|
|
||||||
)
|
|
||||||
image_name_tagged = IMAGE_NAME + ":" + tag
|
image_name_tagged = IMAGE_NAME + ":" + tag
|
||||||
|
|
||||||
print(f"Will tag the container image as '{image_name_tagged}'")
|
print(f"Will tag the container image as '{image_name_tagged}'")
|
||||||
|
|
Loading…
Reference in a new issue