Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion emhttp/plugins/dynamix.docker.manager/include/DockerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,22 @@ public function pullImage($image, $callback=null) {
]))."\r\n";
}

$ret = $this->getDockerJSON("/images/create?fromImage=".urlencode($image), 'POST', $code, $callback, false, $header);
// The daemon streams {"error":...} only once the pull has started. Failures before that (registry
// unreachable, DNS, TLS, auth) come back as an HTTP error with a {"message":...} body, which the
// callers of this function do not look at. Turn such a reply into an "error" line for them.
// An empty message ("", "0") does not count as reported: the callers treat an empty() error as success.
$reported = false;
$wrapped = $callback ? function ($line) use ($callback, &$code, &$reported) {
$cnt = json_decode($line, true);
if (is_array($cnt) && !empty($cnt['error'])) $reported = true;
elseif ($code !== true && is_array($cnt) && !empty($cnt['message'])) {
$line = json_encode(['error' => $cnt['message']])."\n";
$reported = true;
}
$callback($line);
} : null;
$ret = $this->getDockerJSON("/images/create?fromImage=".urlencode($image), 'POST', $code, $wrapped, false, $header);
if ($callback && $code !== true && !$reported) $callback(json_encode(['error' => is_string($code) ? $code : 'Pull failed'])."\n");
$this->flushCache($this::$imagesCache);
return $ret;
}
Expand Down
11 changes: 9 additions & 2 deletions emhttp/plugins/dynamix.docker.manager/scripts/update_container
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function pullImage_nchan($name, $image) {
write("addLog\0<br><b>"._('TOTAL DATA PULLED').":</b> ".$DockerClient->formatBytes(array_sum($alltotals)));
if (!empty($strError)) {
write("addLog\0<br><span class='error'><b>"._('Error').":</b> ".htmlspecialchars($strError)."</span>");
write("addLog\0"._('The container was not changed'));
my_logger("Pull of $image failed, container $name not updated");
return false;
}
return true;
Expand All @@ -152,6 +154,7 @@ $style[] = "fieldset.docker{border:solid thin;margin-top:8px}";
$style[] = "legend{font-size:1.1rem!important;font-weight:bold}";
$style[] = "</style>";

$failed = false;
write(implode($style)."<p class='logLine'></p>");
foreach (explode('*',rawurldecode($argv[1])) as $value) {
$tmpl = $DockerTemplates->getUserTemplate($value);
Expand All @@ -167,7 +170,10 @@ foreach (explode('*',rawurldecode($argv[1])) as $value) {
$TS_Enabled = getXmlVal($xml, "TailscaleEnabled");
$oldImageID = $DockerClient->getImageID($Repository);
// pull image
if (!pullImage_nchan($Name, $Repository)) continue;
if (!pullImage_nchan($Name, $Repository)) {
$failed = true;
continue;
}
$oldContainerInfo = $DockerClient->getContainerDetails($Name);
// determine if the container is still running
$startContainer = false;
Expand Down Expand Up @@ -206,5 +212,6 @@ foreach (explode('*',rawurldecode($argv[1])) as $value) {
// remove old orphan image since it's no longer used by this container
if ($oldImageID && $oldImageID != $newImageID) removeImage_nchan($oldImageID);
}
write('_DONE_','');
write($failed ? '_ERROR_' : '_DONE_','');
exit($failed ? 1 : 0);
?>