fix(corporate): detach no-input migration Docker stdin
Deploy Canina / deploy (push) Failing after 27s
Deploy Canina / deploy (push) Failing after 27s
This commit is contained in:
1 parent
90dcec413d
commit
bee9c4d6e1
6 files changed
+73
-4
No files matched your search
@@ -18,6 +18,21 @@ SQL = (m.ROOT / f'backend/prisma/migrations/{m.NAME}/migration.sql').read_bytes(
|
||||
|
||||
|
||||
class Transport(unittest.TestCase):
|
||||
def test_docker_stdin_contract(self):
|
||||
# Background PTY jobs must never inherit terminal stdin without a payload.
|
||||
# This checks the subprocess boundary, not real Docker/job-control behavior.
|
||||
for data in (None, b'SELECT 1;\n', b''):
|
||||
with self.subTest(data=data), patch.object(m.subprocess, 'run') as run:
|
||||
run.return_value = subprocess.CompletedProcess([], 0, stdout=b'ok')
|
||||
self.assertEqual(m.stage('command', data=data), b'ok')
|
||||
args, kwargs = run.call_args
|
||||
self.assertEqual(args[0], ['docker', 'exec', '-i', m.DB, 'sh', '-ec', 'command'])
|
||||
self.assertEqual(kwargs.get('stdin'), subprocess.DEVNULL if data is None else None)
|
||||
self.assertEqual(kwargs['input'], data)
|
||||
self.assertEqual(kwargs['stdout'], subprocess.PIPE)
|
||||
self.assertEqual(kwargs['stderr'], subprocess.PIPE)
|
||||
self.assertEqual(kwargs['timeout'], 600)
|
||||
|
||||
def test_gate_faults_and_order(self):
|
||||
for failure in ('backup', 'restore', 'clone-apply', 'digest', None):
|
||||
with self.subTest(failure=failure), tempfile.TemporaryDirectory() as td:
|
||||
@@ -63,10 +78,15 @@ class Transport(unittest.TestCase):
|
||||
class Result:
|
||||
returncode = 1 if failure == 'restore' else 0
|
||||
def restore(*args, **kwargs):
|
||||
self.assertIs(kwargs['stdin'], Source.stdout)
|
||||
events.append('restore'); return Result()
|
||||
def source(*args, **kwargs):
|
||||
self.assertEqual(kwargs.get('stdin'), subprocess.DEVNULL)
|
||||
self.assertEqual(kwargs['stdout'], subprocess.PIPE)
|
||||
return Source()
|
||||
with patch.object(m, 'ROOT', root), patch.object(m, 'docker', fake), patch.dict(
|
||||
os.environ, GITHUB_ACTIONS='true', DEPLOY_SHA='a' * 40), patch.object(
|
||||
m.subprocess, 'Popen', return_value=Source()), patch.object(m.subprocess, 'run', restore):
|
||||
m.subprocess, 'Popen', side_effect=source), patch.object(m.subprocess, 'run', restore):
|
||||
if failure:
|
||||
with self.assertRaises(RuntimeError): m.run()
|
||||
self.assertNotIn('live', events)
|
||||
|
||||
@@ -19,8 +19,11 @@ ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
def docker(*args, data=None, timeout=600):
|
||||
# Do not relay stderr: tools may expose connection details or row data.
|
||||
result = subprocess.run(['docker', *args], input=data, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, timeout=timeout)
|
||||
# No-payload calls must not read a background job's controlling terminal.
|
||||
# run(input=...) creates PIPE for payloads, including empty bytes.
|
||||
result = subprocess.run(['docker', *args], input=data,
|
||||
stdin=subprocess.DEVNULL if data is None else None,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
|
||||
if result.returncode:
|
||||
raise RuntimeError('Docker operation failed: ' + args[0])
|
||||
return result.stdout
|
||||
@@ -126,7 +129,8 @@ def run():
|
||||
else:
|
||||
raise RuntimeError('Restore server readiness timeout')
|
||||
# Stream full backup, never store its sensitive contents in runner logs/memory.
|
||||
source = subprocess.Popen(['docker', 'exec', DB, 'cat', backup], stdout=subprocess.PIPE,
|
||||
source = subprocess.Popen(['docker', 'exec', DB, 'cat', backup],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL)
|
||||
try:
|
||||
assert source.stdout is not None
|
||||
|
||||
Reference in new issue
Block a user