Skip to content
Open
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
62 changes: 62 additions & 0 deletions source/compose.manager/php/DockerUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?PHP
/* This file and functionality is based on and uses the Dynamix Docker Manager from unRaid
* Script by mtongnz, Jan 2024
*
* Copyright 2005-2022, Lime Technology
* Copyright 2014-2022, Guilherme Jardim, Eric Schultz, Jon Panozzo.
* Copyright 2012-2022, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php";

define("SHELL_FORMAT", [
'green' => "\033[32m",
'yellow' => "\033[33m",
'red' => "\033[31m",
'bold' => "\033[1m",
'default' => "\033[0m",
]);

$images = array();

// Take stdin from compose.sh and put into images array
$f = fopen( 'php://stdin', 'r' );
while( $image = fgets( $f ) )
$images[] = trim($image);
fclose( $f );
$images = array_unique($images);


echo "\nChecking for updates & updating unRaid's image version details for " . SHELL_FORMAT['bold'] . count($images) . " image(s):\n" . SHELL_FORMAT['default'];
$DockerUpdate = new DockerUpdate();

try {
foreach( $images as $image ) {
echo " - {$image}...";

// Update the local image version info
$localVer = $DockerUpdate->inspectLocalVersion($image);
$DockerUpdate->setUpdateStatus($image, $localVer);

// Update the remote version info
$DockerUpdate->reloadUpdateStatus($image);

// Get current update status - true=up-to-date false=update available null=data unavailable
$updateStatus = $DockerUpdate->getUpdateStatus($image);
echo ( $updateStatus==true ? SHELL_FORMAT['green']." up to date" : ( $updateStatus===null ? SHELL_FORMAT['red']." failed to get update status" : SHELL_FORMAT['yellow']." update available" ) ) . "\n" . SHELL_FORMAT['default'];
}
echo "\nunRaid image versions updated\n";

} catch (Exception $err) {
echo SHELL_FORMAT['red']."\nUpdating unRaid's image versions failed".SHELL_FORMAT['default']."\nError: ". $err->getMessage() ."\n";
}
?>
14 changes: 14 additions & 0 deletions source/compose.manager/php/compose_manager_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ functionBefore: function(instance,helper) {
<input type='button' onclick='editStack(&quot;"+myID+"&quot;);' value='Edit Stack'> \
<input type='button' onclick='deleteStack(&quot;"+myID+"&quot;);' value='Delete Stack' "+disabled+"> \
<input type='button' onclick='ComposeLogs(&quot;"+myID+"&quot;);' value='Logs' "+notdisabled+"> \
<input type='button' onclick='ComposeCheckUpdates(&quot;"+myID+"&quot;);' value='Check for Updates'> \
</center>");
}
});
Expand Down Expand Up @@ -754,6 +755,19 @@ function ComposeLogs(myID) {
}
})
}

function ComposeCheckUpdates(myID) {
var height = 800;
var width = 1200;
$("#"+myID).tooltipster("close");
var script = $("#"+myID).attr("data-scriptname");
var path = compose_root + "/" + script;
$.post(compURL,{action:'composeCheckUpdates',path:path},function(data) {
if (data) {
openBox(data,"Check for Available Updates to Stack "+basename(path),height,width,true);
}
})
}
</script>

<HTML>
Expand Down
3 changes: 3 additions & 0 deletions source/compose.manager/php/compose_util.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,8 @@ function echoComposeCommand($action)
case 'composeLogs':
echoComposeCommand('logs');
break;
case 'composeCheckUpdates':
echoComposeCommand('checkUpdates');
break;
}
?>
10 changes: 10 additions & 0 deletions source/compose.manager/scripts/compose.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
export HOME=/root

phpScriptDir=/usr/local/emhttp/plugins/compose.manager/php

SHORT=e:,c:,f:,p:,d:,o:,g:
LONG=env,command:,file:,project_name:,project_dir:,override:,profile:,debug,recreate
OPTS=$(getopt -a -n compose --options $SHORT --longoptions $LONG -- "$@")
Expand Down Expand Up @@ -132,6 +134,9 @@ case $command in
fi
eval docker rmi ${images[*]}
fi

# Update unRaid's local/remote image versions database so GUI shows correct info about updates
docker compose -p "$name" ps --format "{{.Image}}" | php $phpScriptDir/DockerUpdate.php 2>&1
;;

stop)
Expand All @@ -155,6 +160,11 @@ case $command in
eval docker compose $envFile $files $options logs -f 2>&1
;;

checkUpdates)
# Update unRaid's local/remote image versions database so GUI shows correct info about updates
docker compose -p "$name" ps --format "{{.Image}}" | php $phpScriptDir/DockerUpdate.php 2>&1
;;

*)
echo "unknown command"
echo $command
Expand Down