diff --git a/stx/lib/stx/k8s.py b/stx/lib/stx/k8s.py index 727d25702..263204a08 100644 --- a/stx/lib/stx/k8s.py +++ b/stx/lib/stx/k8s.py @@ -71,20 +71,27 @@ class KubeHelper: else: return False - def generatePrefixCommand(self, podname, command, enableuser): + def generatePrefixCommand(self, podname, command, enableuser, interactive=False): '''Generate the command executed in the host''' prefix_exec_cmd = self.config.kubectl() + ' exec -ti ' builder_exec_cmd = prefix_exec_cmd + podname prefix_bash_cmd = ' -- bash -l -c ' - prefix_bash_with_user_cmd = ' -- bash -l -c \'sudo -u ${MYUNAME} bash \ + prefix_bash_with_user_cmd = ' -- bash -l -c \'sudo -u ${MYUNAME} \ + BASH_ENV=/home/$MYUNAME/userenv bash --rcfile /home/$MYUNAME/userenv -c ' + prefix_bash_with_interactive_user_cmd = ' -- bash -l -i -c \'sudo -u ${MYUNAME} bash \ --rcfile /home/$MYUNAME/userenv -i -c ' builder_exec_bash_cmd = builder_exec_cmd + prefix_bash_cmd builder_exec_bash_with_user_cmd = builder_exec_cmd + \ prefix_bash_with_user_cmd + builder_exec_bash_with_interactive_user_cmd = builder_exec_cmd + \ + prefix_bash_with_interactive_user_cmd if enableuser: - cmd = builder_exec_bash_with_user_cmd + command + if interactive: + cmd = builder_exec_bash_with_interactive_user_cmd + command + else: + cmd = builder_exec_bash_with_user_cmd + command else: cmd = builder_exec_bash_cmd + command diff --git a/stx/lib/stx/stx_build.py b/stx/lib/stx/stx_build.py index b39ba7c6c..0622fda9d 100644 --- a/stx/lib/stx/stx_build.py +++ b/stx/lib/stx/stx_build.py @@ -150,7 +150,7 @@ class HandleBuildTask: '***********************************') sys.exit(1) - prefix_cmd = self.k8s.generatePrefixCommand(podname, '', 1) + prefix_cmd = self.k8s.generatePrefixCommand(podname, '', 1, 1) if args.build_task == 'image': cmd = self.buildImageCMD(args, prefix_cmd) diff --git a/stx/lib/stx/stx_main.py b/stx/lib/stx/stx_main.py index dadd31b36..ea365bdb0 100644 --- a/stx/lib/stx/stx_main.py +++ b/stx/lib/stx/stx_main.py @@ -127,12 +127,14 @@ image.\t\teg: [ prepare|layer|image|download|world|${pkgname}]') repo_subparser = subparsers.add_parser('repomgr', help='Manage source|binary \ -packages.\t\teg: [ list|download|sync|mirror|clean|remove_repo|upload_pkg|\ -delete_pkg ]') +packages.\t\teg: [ list|download|sync|merge|mirror|clean|\ +remove_repo|search_pkg|upload_pkg|delete_pkg ]') repo_subparser.add_argument('repomgr_task', - help='[ list|download|sync|mirror|clean|\ - remove_repo|upload_pkg|delete_pkg ]: \ + help='[ list|download|sync|merge|mirror|clean|\ + remove_repo|search_pkg|upload_pkg|delete_pkg ]: \ Execute the management task.\n\n') + # Pass remaining arguements into repo_manage.py for additional processing + repo_subparser.add_argument('args', nargs=argparse.REMAINDER) repo_subparser.set_defaults(handle=self.handlerepomgr.handleCommand) parser.add_argument('-d', '--debug', diff --git a/stx/lib/stx/stx_repomgr.py b/stx/lib/stx/stx_repomgr.py index d1e1cb6e6..ed09d281a 100644 --- a/stx/lib/stx/stx_repomgr.py +++ b/stx/lib/stx/stx_repomgr.py @@ -16,6 +16,7 @@ import logging from stx.k8s import KubeHelper from stx import utils # pylint: disable=E0611 import subprocess +import sys logger = logging.getLogger('STX-Repomgr') utils.set_logger(logger) @@ -38,12 +39,14 @@ class HandleRepomgrTask: logger.error('The builder container does not exist, so please \ consider to use the control module') - prefix_cmd = self.k8s.generatePrefixCommand(podname, '', 1) - cmd = prefix_cmd + '"repo_manage.py ' + args.repomgr_task + '"\'' + prefix_cmd = self.k8s.generatePrefixCommand(podname, '', 1, 0) + cmd = prefix_cmd + ' '.join(['"repo_manage.py', args.repomgr_task, ' '.join(args.args), '"\'']) logger.debug('Manage the repo with the command [%s]', cmd) try: subprocess.check_call(cmd, shell=True) except subprocess.CalledProcessError as exc: - raise Exception('Failed to manage the repo with the command [%s].\n \ + # raise Exception('Failed to manage the repo with the command [%s].\n \ + logger.error('Failed to manage the repo with the command [%s].\n \ Returncode: %s' % (cmd, exc.returncode)) + sys.exit(2) diff --git a/stx/toCOPY/builder/userenv b/stx/toCOPY/builder/userenv index ae378ea4a..f3b62a74c 100644 --- a/stx/toCOPY/builder/userenv +++ b/stx/toCOPY/builder/userenv @@ -19,6 +19,7 @@ if [ ! -d $MY_WORKSPACE ]; then mkdir -p $MY_WORKSPACE > /dev/null 2>&1 fi +if echo $- | grep -q i ; then cat <