Exemplo n.º 1
0
def run_docker(enter_to_shell):
    interactive_message = 'true' if enter_to_shell else 'false'

    have_winpty = shutil.which('winpty') != None

    pwd = os.getcwd()

    path_escape = ''

    if have_winpty:
        pwd = '/' + pwd
        path_escape = '/'

    if on_windows():
        args = []

        if have_winpty:
            args += ['winpty']

        args += [
            'docker', 'run', '--privileged',
            get_windows_interactive_switch(have_winpty), '-e',
            'ON_WINDOWS=true', '-e',
            'INTERACTIVE_MESSAGE=' + interactive_message, '-v',
            '{volume}:{path_escape}/home/build'.format(
                volume=WIN_VOLUME, path_escape=path_escape), '-v',
            '{pwd}\\src:{path_escape}/home/build/src'.format(
                pwd=pwd, path_escape=path_escape), '-v',
            '{pwd}\\artifacts:{path_escape}/home/build/artifacts'.format(
                pwd=pwd, path_escape=path_escape), '-v',
            '{pwd}\\config:{path_escape}/home/build/config'.format(
                pwd=pwd, path_escape=path_escape), IMAGE, ENTRY_SCRIPT
        ]
    else:
        pake.FileHelper().makedirs('install.cache')

        username = getpass.getuser()
        args = [
            'docker', 'run', '--privileged', '-ti', '-e', 'ON_WINDOWS=false',
            '-e', 'INTERACTIVE_MESSAGE=' + interactive_message, '-e',
            'LOCAL_USER_ID=' + str(os.getuid()), '-e',
            'LOCAL_USER='******'-v',
            '{pwd}/install.cache:/var/tmp/{username}/install.cache'.format(
                pwd=pwd, username=username), '-v',
            '{pwd}:/home/build'.format(pwd=pwd), IMAGE, ENTRY_SCRIPT
        ]

    if not enter_to_shell:
        args += [
            '{path_escape}/home/build/src/build_in_docker.sh'.format(
                path_escape=path_escape)
        ]

    process.call(args)
Exemplo n.º 2
0
    def test_call(self):
        cmd = [sys.executable, os.path.join(script_dir, 'timeout.py')]

        with self.assertRaises(process.TimeoutExpired) as exc:
            process.call(*cmd, timeout=0.1, stderr=process.DEVNULL, stdout=process.DEVNULL)

        self.assertSequenceEqual((cmd, 0.1), exc.exception.cmd)

        self.assertNotEqual(process.call(sys.executable, os.path.join(script_dir, 'throw.py'),
                                         stderr=process.DEVNULL, stdout=process.DEVNULL), 0)

        self.assertNotEqual(process.call(sys.executable, os.path.join(script_dir, 'killself.py'),
                                         stderr=process.DEVNULL, stdout=process.DEVNULL), 0)
Exemplo n.º 3
0
def docker_volume_exists(name):
    return process.call('docker',
                        'volume',
                        'inspect',
                        name,
                        stdout=process.DEVNULL,
                        stderr=process.DEVNULL) == 0
Exemplo n.º 4
0
    def test_stdin_defines(self):
        # Test that the --stdin-defines feature is working, and can handle being fed bad values

        good_value = {
            'DEFINE_VALUE_TRUE': True,
            'DEFINE_VALUE_FALSE': False,
            'DEFINE_VALUE_STRING': 'string',
            'DEFINE_VALUE_LIST': ['list', 42],
            'DEFINE_VALUE_DICT': {
                'dict': 42
            },
            'DEFINE_VALUE_TUP': ('tuple', 42),
            'DEFINE_VALUE_SET': {'set', 42}
        }

        assert_script = os.path.join(script_dir,
                                     'assert_stdin_define_values.py')

        # Temp file is the quickest way to do this

        with tempfile.TemporaryFile(mode='w+', newline='\n') as temp:
            temp.write(str(good_value))
            temp.flush()
            temp.seek(0)

            # If this raises a pake.process.CalledProcessException, test failed
            process.check_call(sys.executable,
                               assert_script,
                               '--stdin-define',
                               stdin=temp)

            # ==========================

            # Feed it python dictionary syntax errors

            temp.seek(0)
            temp.write("{'This dictionary is bad':}")
            temp.flush()
            temp.seek(0)

            return_code = process.call(sys.executable,
                                       assert_script,
                                       '--stdin-define',
                                       stdin=temp,
                                       stderr=process.DEVNULL,
                                       stdout=process.DEVNULL)

            # Check pake handled the syntax error in the defines dictionary correctly
            self.assertEqual(return_code,
                             pake.returncodes.STDIN_DEFINES_SYNTAX_ERROR)

            # ==========================

            # Feed it something that is not a dictionary,
            # but will still deserialize

            temp.seek(0)
            temp.write("['list']")
            temp.flush()
            temp.seek(0)

            return_code = process.call(sys.executable,
                                       assert_script,
                                       '--stdin-define',
                                       stdin=temp,
                                       stderr=process.DEVNULL,
                                       stdout=process.DEVNULL)

            # Check pake handled the incorrect literal type correctly
            self.assertEqual(return_code,
                             pake.returncodes.STDIN_DEFINES_SYNTAX_ERROR)

            # ==========================

            # Feed it garbage

            temp.seek(0)
            temp.write("IM THE TRASHMAN. I EAT GARBAGE.")
            temp.flush()
            temp.seek(0)

            return_code = process.call(sys.executable,
                                       assert_script,
                                       '--stdin-define',
                                       stdin=temp,
                                       stderr=process.DEVNULL,
                                       stdout=process.DEVNULL)

            # Check pake handled the syntax error in the defines dictionary correctly
            self.assertEqual(return_code,
                             pake.returncodes.STDIN_DEFINES_SYNTAX_ERROR)

            # ==========================

            # Test that override on the command line is working by trying to override
            # a value that the assert_stdin_define_values.py script expects

            temp.seek(0)
            temp.write(str(good_value))
            temp.flush()
            temp.seek(0)

            with self.assertRaises(pake.process.CalledProcessException):
                # This should raise pake.process.CalledProcessException,
                # because the helper script is not expecting DEFINE_VALUE_TRUE=False

                process.check_call(sys.executable,
                                   assert_script,
                                   '--stdin-define',
                                   '-D',
                                   'DEFINE_VALUE_TRUE=False',
                                   stdin=temp,
                                   stderr=process.DEVNULL,
                                   stdout=process.DEVNULL)