diff --git a/source/compose.manager/event/started b/source/compose.manager/event/started index 7954c0b..a4954aa 100755 --- a/source/compose.manager/event/started +++ b/source/compose.manager/event/started @@ -26,16 +26,33 @@ fi for dir in $COMPOSE_ROOT/*; do if [ -d "$dir" ]; then - if [ -f "$dir/docker-compose.yml" ] || [ -f "$dir/indirect" ]; then + # Check if any valid compose file exists + if [ -f "$dir/compose.yaml" ] || [ -f "$dir/compose.yml" ] || [ -f "$dir/docker-compose.yaml" ] || [ -f "$dir/docker-compose.yml" ] || [ -f "$dir/indirect" ]; then if [ -f "$dir/autostart" ]; then autostart=${dir}/autostart if [ 'true' == "$(< "${autostart}" )" ]; then name=${dir}/name name=$(< "${name}") name=$(sanitize ${name}) + # Find the compose file + compose_file="" + if [ -f "$dir/compose.yaml" ]; then + compose_file="$dir/compose.yaml" + override_file="$dir/compose.override.yml" + elif [ -f "$dir/compose.yml" ]; then + compose_file="$dir/compose.yml" + override_file="$dir/compose.override.yml" + elif [ -f "$dir/docker-compose.yaml" ]; then + compose_file="$dir/docker-compose.yaml" + override_file="$dir/docker-compose.override.yml" + elif [ -f "$dir/docker-compose.yml" ]; then + compose_file="$dir/docker-compose.yml" + override_file="$dir/docker-compose.override.yml" + fi + override="" - if [ -f "$dir/docker-compose.override.yml" ]; then - override="$dir/docker-compose.override.yml" + if [ -n "$compose_file" ] && [ -f "$override_file" ]; then + override="$override_file" override="-f ${override@Q}" fi envpath="" @@ -50,8 +67,7 @@ for dir in $COMPOSE_ROOT/*; do indirect=$(< "${indirect}") eval $COMPOSE_WRAPPER -c up -d ${indirect@Q} -p ${name} $recreate $debug $override $envpath > /dev/null & else - dir="$dir/docker-compose.yml" - eval $COMPOSE_WRAPPER -c up -f ${dir@Q} -p ${name} $recreate $debug $override $envpath > /dev/null & + eval $COMPOSE_WRAPPER -c up -f ${compose_file@Q} -p ${name} $recreate $debug $override $envpath > /dev/null & fi fi fi diff --git a/source/compose.manager/event/stopping_docker b/source/compose.manager/event/stopping_docker index bd2f12f..63919fd 100755 --- a/source/compose.manager/event/stopping_docker +++ b/source/compose.manager/event/stopping_docker @@ -8,12 +8,29 @@ COMPOSE_WRAPPER=/usr/local/emhttp/plugins/compose.manager/scripts/compose.sh for dir in $COMPOSE_ROOT/*; do if [ -d "$dir" ]; then - if [ -f "$dir/docker-compose.yml" ] || [ -f "$dir/indirect" ]; then + # Check if any valid compose file exists + if [ -f "$dir/compose.yaml" ] || [ -f "$dir/compose.yml" ] || [ -f "$dir/docker-compose.yaml" ] || [ -f "$dir/docker-compose.yml" ] || [ -f "$dir/indirect" ]; then name=${dir}/name name=$(< "${name}") + # Find the compose file + compose_file="" + if [ -f "$dir/compose.yaml" ]; then + compose_file="$dir/compose.yaml" + override_file="$dir/compose.override.yml" + elif [ -f "$dir/compose.yml" ]; then + compose_file="$dir/compose.yml" + override_file="$dir/compose.override.yml" + elif [ -f "$dir/docker-compose.yaml" ]; then + compose_file="$dir/docker-compose.yaml" + override_file="$dir/docker-compose.override.yml" + elif [ -f "$dir/docker-compose.yml" ]; then + compose_file="$dir/docker-compose.yml" + override_file="$dir/docker-compose.override.yml" + fi + override="" - if [ -f "$dir/docker-compose.override.yml" ]; then - override="$dir/docker-compose.override.yml" + if [ -n "$compose_file" ] && [ -f "$override_file" ]; then + override="$override_file" override="-f ${override@Q}" fi envpath="" @@ -28,8 +45,7 @@ for dir in $COMPOSE_ROOT/*; do indirect=$(< "${indirect}") eval $COMPOSE_WRAPPER -c stop -d ${indirect@Q} -p "${name// /_}" $override $envpath > /dev/null & else - dir="$dir/docker-compose.yml" - eval $COMPOSE_WRAPPER -c stop -f ${dir@Q} -p "${name// /_}" $override $envpath > /dev/null & + eval $COMPOSE_WRAPPER -c stop -f ${compose_file@Q} -p "${name// /_}" $override $envpath > /dev/null & fi fi fi diff --git a/source/compose.manager/php/compose_manager_main.php b/source/compose.manager/php/compose_manager_main.php index 8d07a17..5e5b3d5 100644 --- a/source/compose.manager/php/compose_manager_main.php +++ b/source/compose.manager/php/compose_manager_main.php @@ -33,7 +33,7 @@ function createComboButton($text, $id, $onClick, $onClickParams, $items) { } $o = ""; foreach ($composeProjects as $project) { - if ( ( ! is_file("$compose_root/$project/docker-compose.yml") ) && + if ( ( findComposeFile("$compose_root/$project") === null ) && ( ! is_file("$compose_root/$project/indirect") ) ) { continue; } @@ -596,7 +596,9 @@ function editComposeFile(myID) { editor.getSession().setOptions({ tabSize: 2, useSoftTabs: true }); $('#editorFileName').data("stackname", project); - $('#editorFileName').data("stackfilename", "docker-compose.yml") + // Extract the actual filename from the response + var filename = response.fileName.split('/').pop(); + $('#editorFileName').data("stackfilename", filename) $('#editorFileName').html(response.fileName) $(".editing").show(); window.scrollTo(0, 0); @@ -635,18 +637,14 @@ function saveEdit() { var scriptContents = editor.getValue(); var actionStr = null - switch(fileName) { - case 'docker-compose.yml': - actionStr = 'saveYml' - break; - - case '.env': - actionStr = 'saveEnv' - break; - - default: - $(".editing").hide(); - return; + // Check if this is a compose file (any valid extension) + if (fileName.match(/^(docker-)?compose\.(yml|yaml)$/)) { + actionStr = 'saveYml' + } else if (fileName === '.env') { + actionStr = 'saveEnv' + } else { + $(".editing").hide(); + return; } $.post(caURL,{action:actionStr,script:project,scriptContents:scriptContents},function(data) { diff --git a/source/compose.manager/php/compose_util.php b/source/compose.manager/php/compose_util.php index 84a87c5..5bbae1c 100644 --- a/source/compose.manager/php/compose_util.php +++ b/source/compose.manager/php/compose_util.php @@ -11,7 +11,7 @@ function logger($string) { function execComposeCommandInTTY($cmd, $debug) { - global $socket_name;; + global $socket_name; $pid = exec("pgrep -a ttyd|awk '/\\/$socket_name\\.sock/{print \$1}'"); if ( $debug ) { logger($pid); @@ -61,14 +61,71 @@ function echoComposeCommand($action) $composeFile = "-d$composeFile"; } else { - $composeFile .= "$path/docker-compose.yml"; + $foundComposeFile = findComposeFile($path); + if ($foundComposeFile === null) { + $composeFile .= "$path/docker-compose.yml"; + } else { + $composeFile .= $foundComposeFile; + } $composeFile = "-f$composeFile"; } $composeCommand[] = $composeFile; - if ( is_file("$path/docker-compose.override.yml") ) { - $composeOverride = "-f$path/docker-compose.override.yml"; + // First, always include the plugin's override file if it exists + global $compose_root; + $projectName = basename($path); + $pluginOverrideYml = "$compose_root/$projectName/docker-compose.override.yml"; + $pluginOverrideYaml = "$compose_root/$projectName/docker-compose.override.yaml"; + + if (is_file($pluginOverrideYml)) { + $composeOverride = "-f$pluginOverrideYml"; $composeCommand[] = $composeOverride; + if ( $debug ) { + logger("Using plugin override file: $pluginOverrideYml"); + } + } else if (is_file($pluginOverrideYaml)) { + $composeOverride = "-f$pluginOverrideYaml"; + $composeCommand[] = $composeOverride; + if ( $debug ) { + logger("Using plugin override file: $pluginOverrideYaml"); + } + } + + // Then, also include any project-specific override files + if (isIndirect($path)) { + $basePath = getPath($path); + } else { + $basePath = $path; + } + + $foundComposeFile = findComposeFile($basePath); + if ($foundComposeFile !== null) { + $baseFileName = getComposeFileBaseName($foundComposeFile); + // Get the extension of the original compose file + $extension = pathinfo($foundComposeFile, PATHINFO_EXTENSION); + $overrideFile = "$basePath/$baseFileName.override.$extension"; + if (is_file($overrideFile)) { + $composeOverride = "-f$overrideFile"; + $composeCommand[] = $composeOverride; + if ( $debug ) { + logger("Using project override file: $overrideFile"); + } + } + } else { + // Check for both yml and yaml override files + if (is_file("$basePath/docker-compose.override.yml")) { + $composeOverride = "-f$basePath/docker-compose.override.yml"; + $composeCommand[] = $composeOverride; + if ( $debug ) { + logger("Using project override file: $basePath/docker-compose.override.yml"); + } + } else if (is_file("$basePath/docker-compose.override.yaml")) { + $composeOverride = "-f$basePath/docker-compose.override.yaml"; + $composeCommand[] = $composeOverride; + if ( $debug ) { + logger("Using project override file: $basePath/docker-compose.override.yaml"); + } + } } if ( is_file("$path/envpath") ) { diff --git a/source/compose.manager/php/exec.php b/source/compose.manager/php/exec.php index dee0af0..b9f024d 100644 --- a/source/compose.manager/php/exec.php +++ b/source/compose.manager/php/exec.php @@ -51,10 +51,13 @@ function getElement($element) { #Create stack files if ( !empty($indirect) ) { file_put_contents("$folder/indirect",$indirect); - if ( !is_file("$indirect/docker-compose.yml") ) { + $composeFile = findComposeFile($indirect); + if ($composeFile === null) { + // Create default docker-compose.yml if no compose file exists file_put_contents("$indirect/docker-compose.yml","services:\n"); } } else { + // Create default docker-compose.yml for new projects file_put_contents("$folder/docker-compose.yml","services:\n"); } @@ -92,9 +95,22 @@ function getElement($element) { case 'getYml': $script = isset($_POST['script']) ? urldecode(($_POST['script'])) : ""; $basePath = getPath("$compose_root/$script"); - $fileName = "docker-compose.yml"; + $composeFile = findComposeFile($basePath); + + // If no compose file exists, use the default path + if ($composeFile === null) { + // Try both yaml and yml extensions + if (is_file("$basePath/docker-compose.yaml")) { + $fileName = "docker-compose.yaml"; + } else { + $fileName = "docker-compose.yml"; + } + $composeFile = "$basePath/$fileName"; + } else { + $fileName = basename($composeFile); + } - $scriptContents = file_get_contents("$basePath/$fileName"); + $scriptContents = file_get_contents($composeFile); $scriptContents = str_replace("\r","",$scriptContents); if ( ! $scriptContents ) { $scriptContents = "services:\n"; @@ -120,7 +136,22 @@ function getElement($element) { case 'getOverride': $script = isset($_POST['script']) ? urldecode(($_POST['script'])) : ""; $basePath = "$compose_root/$script"; - $fileName = "docker-compose.override.yml"; + $composeFile = findComposeFile($basePath); + + // Determine the override file name based on the base compose file + if ($composeFile !== null) { + $baseFileName = getComposeFileBaseName($composeFile); + // Get the extension of the original compose file + $extension = pathinfo($composeFile, PATHINFO_EXTENSION); + $fileName = "$baseFileName.override.$extension"; + } else { + // Check for both yml and yaml override files + if (is_file("$basePath/docker-compose.override.yaml")) { + $fileName = "docker-compose.override.yaml"; + } else { + $fileName = "docker-compose.override.yml"; + } + } $scriptContents = is_file("$basePath/$fileName") ? file_get_contents("$basePath/$fileName") : ""; $scriptContents = str_replace("\r","",$scriptContents); @@ -133,9 +164,22 @@ function getElement($element) { $script = isset($_POST['script']) ? urldecode(($_POST['script'])) : ""; $scriptContents = isset($_POST['scriptContents']) ? $_POST['scriptContents'] : ""; $basePath = getPath("$compose_root/$script"); - $fileName = "docker-compose.yml"; + $composeFile = findComposeFile($basePath); + + // If no compose file exists, use the default path + if ($composeFile === null) { + // Try both yaml and yml extensions + if (is_file("$basePath/docker-compose.yaml")) { + $fileName = "docker-compose.yaml"; + } else { + $fileName = "docker-compose.yml"; + } + $composeFile = "$basePath/$fileName"; + } else { + $fileName = basename($composeFile); + } - file_put_contents("$basePath/$fileName",$scriptContents); + file_put_contents($composeFile, $scriptContents); echo "$basePath/$fileName saved"; break; case 'saveEnv': @@ -155,9 +199,24 @@ function getElement($element) { $script = isset($_POST['script']) ? urldecode(($_POST['script'])) : ""; $scriptContents = isset($_POST['scriptContents']) ? $_POST['scriptContents'] : ""; $basePath = "$compose_root/$script"; - $fileName = "docker-compose.override.yml"; + $composeFile = findComposeFile($basePath); + + // Determine the override file name based on the base compose file + if ($composeFile !== null) { + $baseFileName = getComposeFileBaseName($composeFile); + // Get the extension of the original compose file + $extension = pathinfo($composeFile, PATHINFO_EXTENSION); + $fileName = "$baseFileName.override.$extension"; + } else { + // Check for both yml and yaml override files + if (is_file("$basePath/docker-compose.override.yaml")) { + $fileName = "docker-compose.override.yaml"; + } else { + $fileName = "docker-compose.override.yml"; + } + } - file_put_contents("$basePath/$fileName",$scriptContents); + file_put_contents("$basePath/$fileName", $scriptContents); echo "$basePath/$fileName saved"; break; case 'updateAutostart': diff --git a/source/compose.manager/php/util.php b/source/compose.manager/php/util.php index 6073884..06e47f9 100644 --- a/source/compose.manager/php/util.php +++ b/source/compose.manager/php/util.php @@ -1,5 +1,40 @@