mirror of
https://github.com/truenas/scale-build.git
synced 2025-12-20 02:49:28 +00:00
Allow specifying env variable for providing identity file path for a package
This commit is contained in:
@@ -2,6 +2,7 @@ from os import environ, cpu_count
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
|
||||
IDENTITY_FILE_PATH_OVERRIDE_SUFFIX = '_OVERRIDE_IDENTITY_FILE_PATH'
|
||||
_VERS = '22.12-MASTER'
|
||||
|
||||
|
||||
@@ -29,9 +30,10 @@ BUILD_TIME = int(time())
|
||||
BUILD_TIME_OBJ = datetime.fromtimestamp(BUILD_TIME)
|
||||
BUILDER_DIR = get_env_variable('BUILDER_DIR', './', str)
|
||||
BRANCH_OUT_NAME = get_env_variable('NEW_BRANCH_NAME', '', str)
|
||||
BRANCH_OVERRIDES = {k[:-(len('_OVERRIDE'))]: v for k, v in environ.items() if k.endswith('_OVERRIDE')}
|
||||
BRANCH_OVERRIDES = {}
|
||||
FORCE_CLEANUP_WITH_EPOCH_CHANGE = get_env_variable('FORCE_CLEANUP_WITH_EPOCH_CHANGE', 0, bool)
|
||||
GITHUB_TOKEN = get_env_variable('GITHUB_TOKEN', '', str)
|
||||
PACKAGE_IDENTITY_FILE_PATH_OVERRIDES = {}
|
||||
PARALLEL_BUILD = get_env_variable('PARALLEL_BUILDS', (max(cpu_count(), 8) / 4), int)
|
||||
PKG_DEBUG = get_env_variable('PKG_DEBUG', 0, bool)
|
||||
SIGNING_KEY = get_env_variable('SIGNING_KEY', '', str)
|
||||
@@ -41,3 +43,11 @@ TRAIN = get_env_variable('TRUENAS_TRAIN', '', str)
|
||||
TRUENAS_BRANCH_OVERRIDE = get_env_variable('TRUENAS_BRANCH_OVERRIDE', '', str)
|
||||
TRY_BRANCH_OVERRIDE = get_env_variable('TRY_BRANCH_OVERRIDE', '', str)
|
||||
VERSION = get_env_variable('TRUENAS_VERSION', f'{_VERS}-{BUILD_TIME_OBJ.strftime("%Y%m%d-%H%M%S")}', str)
|
||||
|
||||
|
||||
# We will get branch overrides and identity file path overrides from here
|
||||
for k, v in environ.items():
|
||||
if k.endswith('_OVERRIDE'):
|
||||
BRANCH_OVERRIDES[k[:-(len('_OVERRIDE'))]] = v
|
||||
elif k.endswith(IDENTITY_FILE_PATH_OVERRIDE_SUFFIX):
|
||||
PACKAGE_IDENTITY_FILE_PATH_OVERRIDES[k[:-(len(IDENTITY_FILE_PATH_OVERRIDE_SUFFIX))]] = v
|
||||
|
||||
@@ -3,7 +3,10 @@ import os
|
||||
import shutil
|
||||
import contextlib
|
||||
|
||||
from scale_build.config import BRANCH_OVERRIDES, TRUENAS_BRANCH_OVERRIDE, TRY_BRANCH_OVERRIDE
|
||||
from scale_build.config import (
|
||||
BRANCH_OVERRIDES, IDENTITY_FILE_PATH_OVERRIDE_SUFFIX, PACKAGE_IDENTITY_FILE_PATH_OVERRIDES,
|
||||
TRUENAS_BRANCH_OVERRIDE, TRY_BRANCH_OVERRIDE,
|
||||
)
|
||||
from scale_build.exceptions import CallError
|
||||
from scale_build.utils.git_utils import (
|
||||
branch_checked_out_locally, branch_exists_in_repository, create_branch,
|
||||
@@ -133,7 +136,8 @@ class GitPackageMixin:
|
||||
@property
|
||||
def get_identity_file_path(self):
|
||||
# We need to use absolute path as git changes it's working directory with -C
|
||||
return os.path.abspath(self.identity_file_path)
|
||||
path = PACKAGE_IDENTITY_FILE_PATH_OVERRIDES.get(self.name) or self.identity_file_path
|
||||
return os.path.abspath(path) if path else None
|
||||
|
||||
@property
|
||||
def ssh_based_source(self):
|
||||
@@ -143,17 +147,18 @@ class GitPackageMixin:
|
||||
if not self.ssh_based_source:
|
||||
return
|
||||
|
||||
if not self.identity_file_path:
|
||||
if not self.get_identity_file_path:
|
||||
raise CallError(
|
||||
'Identity file path ("identity_file_path" attribute) must be specified '
|
||||
f'in order to checkout {self.name!r}'
|
||||
f'Identity file path must be specified in order to checkout {self.name!r}. It can be done either as '
|
||||
'specifying "identity_file_path" attribute in manifest or providing '
|
||||
f'"{self.name}{IDENTITY_FILE_PATH_OVERRIDE_SUFFIX}" env variable specifying path of the file.'
|
||||
)
|
||||
|
||||
if not os.path.exists(self.get_identity_file_path):
|
||||
raise CallError(f'{self.identity_file_path!r} identity file path does not exist')
|
||||
raise CallError(f'{self.get_identity_file_path!r} identity file path does not exist')
|
||||
|
||||
if oct(os.stat(self.get_identity_file_path).st_mode & 0o777) != '0o600':
|
||||
raise CallError(f'{self.identity_file_path!r} identity file path should have 0o600 permissions')
|
||||
raise CallError(f'{self.get_identity_file_path!r} identity file path should have 0o600 permissions')
|
||||
|
||||
@property
|
||||
def existing_branch(self):
|
||||
|
||||
Reference in New Issue
Block a user