summaryrefslogtreecommitdiff
path: root/scripts/image-build/build-vyos-image
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/image-build/build-vyos-image')
-rwxr-xr-xscripts/image-build/build-vyos-image59
1 files changed, 30 insertions, 29 deletions
diff --git a/scripts/image-build/build-vyos-image b/scripts/image-build/build-vyos-image
index 68b1f743..61431c16 100755
--- a/scripts/image-build/build-vyos-image
+++ b/scripts/image-build/build-vyos-image
@@ -31,14 +31,6 @@ import argparse
import datetime
import functools
-# Add the vyos-1x submodule directory to the Python path
-# so that we can import modules from it.
-VYOS1X_DIR = os.path.join(os.getcwd(), 'vyos-1x/python')
-if not os.path.exists(VYOS1X_DIR):
- print("E: vyos-1x subdirectory does not exist, did you initialize submodules?")
-else:
- sys.path.append(VYOS1X_DIR)
-
# Import third-party modules
try:
import tomli
@@ -49,6 +41,36 @@ except ModuleNotFoundError as e:
print(f"E: Cannot load required library {e}")
print("E: Please make sure the following Python3 modules are installed: tomli jinja2 git psutil")
+# Initialize Git object from our repository
+try:
+ repo = git.Repo('.', search_parent_directories=True)
+ repo.git.submodule('update', '--init')
+
+ # Retrieve the Git commit ID of the repository, 14 charaters will be sufficient
+ build_git = repo.head.object.hexsha[:14]
+ # If somone played around with the source tree and the build is "dirty", mark it
+ if repo.is_dirty():
+ build_git += "-dirty"
+
+ # Retrieve git branch name or current tag
+ # Building a tagged release might leave us checking out a git tag that is not the tip of a named branch (detached HEAD)
+ # Check if the current HEAD is associated with a tag and use its name instead of an unavailable branch name.
+ git_branch = next((tag.name for tag in repo.tags if tag.commit == repo.head.commit), None)
+ if git_branch is None:
+ git_branch = repo.active_branch.name
+except Exception as e:
+ print(f'W: Could not retrieve information from git: {repr(e)}')
+ build_git = ""
+ git_branch = ""
+
+# Add the vyos-1x submodule directory to the Python path
+# so that we can import modules from it.
+VYOS1X_DIR = os.path.join(os.getcwd(), 'vyos-1x/python')
+if not os.path.exists(VYOS1X_DIR):
+ print("E: vyos-1x subdirectory does not exist, did you initialize submodules?")
+else:
+ sys.path.append(VYOS1X_DIR)
+
# Import local modules from scripts/image-build
# They rely on modules from vyos-1x
import utils
@@ -340,27 +362,6 @@ if __name__ == "__main__":
# Assign a (hopefully) unique identifier to the build (UUID)
build_uuid = str(uuid.uuid4())
- # Initialize Git object from our repository
- try:
- repo = git.Repo('.', search_parent_directories=True)
-
- # Retrieve the Git commit ID of the repository, 14 charaters will be sufficient
- build_git = repo.head.object.hexsha[:14]
- # If somone played around with the source tree and the build is "dirty", mark it
- if repo.is_dirty():
- build_git += "-dirty"
-
- # Retrieve git branch name or current tag
- # Building a tagged release might leave us checking out a git tag that is not the tip of a named branch (detached HEAD)
- # Check if the current HEAD is associated with a tag and use its name instead of an unavailable branch name.
- git_branch = next((tag.name for tag in repo.tags if tag.commit == repo.head.commit), None)
- if git_branch is None:
- git_branch = repo.active_branch.name
- except Exception as e:
- print(f'W: Could not retrieve information from git: {repr(e)}')
- build_git = ""
- git_branch = ""
-
# Create the build version string
if build_config['build_type'] == 'development':
try: