| 124 | |
| 125 | |
| 126 | def 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 |