MCPcopy
hub / github.com/astral-sh/python-build-standalone / container_exec

Function container_exec

pythonbuild/docker.py:126–150  ·  view source on GitHub ↗
(container, command, user="build", environment=None)

Source from the content-addressed store, hash-verified

124
125
126def container_exec(container, command, user="build", environment=None):
127 # docker-py's exec_run() won't return the exit code. So we reinvent the
128 # wheel.
129 create_res = container.client.api.exec_create(
130 container.id, command, user=user, environment=environment
131 )
132
133 exec_output = container.client.api.exec_start(create_res["Id"], stream=True)
134
135 for chunk in exec_output:
136 for l in chunk.strip().splitlines():
137 log(l)
138
139 log_raw(chunk)
140
141 inspect_res = container.client.api.exec_inspect(create_res["Id"])
142
143 if inspect_res["ExitCode"] != 0:
144 if "PYBUILD_BREAK_ON_FAILURE" in os.environ:
145 print("to enter container: docker exec -it %s /bin/bash" % container.id)
146 import pdb
147
148 pdb.set_trace()
149
150 raise Exception("exit code %d from %s" % (inspect_res["ExitCode"], command))
151
152
153# 2019-01-01T00:00:00

Callers 1

runMethod · 0.85

Calls 2

logFunction · 0.90
log_rawFunction · 0.90

Tested by

no test coverage detected