Skip to content

Commit 15638ce

Browse files
committed
Add log dir expose, unify SPC_FIX_DEPLOY_ROOT parsing
1 parent 9ed77c1 commit 15638ce

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

bin/spc-alpine-docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source"
150150
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
151151
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
152152
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
153+
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/log:/app/log"
153154
if [ -f "$(pwd)/craft.yml" ]; then
154155
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/craft.yml:/app/craft.yml"
155156
fi

bin/spc-gnu-docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source"
158158
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
159159
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
160160
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
161+
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/log:/app/log"
161162
if [ -f "$(pwd)/craft.yml" ]; then
162163
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/craft.yml:/app/craft.yml"
163164
fi

src/SPC/command/BuildPHPCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,9 @@ public function handle(): int
222222

223223
// ---------- When using bin/spc-alpine-docker, the build root path is different from the host system ----------
224224
$build_root_path = BUILD_ROOT_PATH;
225-
$cwd = getcwd();
226225
$fixed = '';
226+
$build_root_path = get_display_path($build_root_path);
227227
if (!empty(getenv('SPC_FIX_DEPLOY_ROOT'))) {
228-
str_replace($cwd, '', $build_root_path);
229-
$build_root_path = getenv('SPC_FIX_DEPLOY_ROOT') . '/' . basename($build_root_path);
230228
$fixed = ' (host system)';
231229
}
232230
if (($rule & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {

src/SPC/exception/ExceptionHandler.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,18 @@ public static function handleSPCException(SPCException $e): void
137137

138138
self::logError("\n----------------------------------------\n");
139139

140-
self::logError('⚠ The ' . ConsoleColor::cyan('console output log') . ConsoleColor::red(' is saved in ') . ConsoleColor::none(SPC_OUTPUT_LOG));
140+
// convert log file path if in docker
141+
$spc_log_convert = get_display_path(SPC_OUTPUT_LOG);
142+
$shell_log_convert = get_display_path(SPC_SHELL_LOG);
143+
$spc_logs_dir_convert = get_display_path(SPC_LOGS_DIR);
144+
145+
self::logError('⚠ The ' . ConsoleColor::cyan('console output log') . ConsoleColor::red(' is saved in ') . ConsoleColor::none($spc_log_convert));
141146
if (file_exists(SPC_SHELL_LOG)) {
142-
self::logError('⚠ The ' . ConsoleColor::cyan('shell output log') . ConsoleColor::red(' is saved in ') . ConsoleColor::none(SPC_SHELL_LOG));
147+
self::logError('⚠ The ' . ConsoleColor::cyan('shell output log') . ConsoleColor::red(' is saved in ') . ConsoleColor::none($shell_log_convert));
143148
}
144149
if ($e->getExtraLogFiles() !== []) {
145150
foreach ($e->getExtraLogFiles() as $key => $file) {
146-
self::logError("⚠ Log file [{$key}] is saved in: " . ConsoleColor::none(SPC_LOGS_DIR . "/{$file}"));
151+
self::logError("⚠ Log file [{$key}] is saved in: " . ConsoleColor::none("{$spc_logs_dir_convert}/{$file}"));
147152
}
148153
}
149154
if (!defined('DEBUG_MODE')) {

src/globals/functions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,20 @@ function strip_ansi_colors(string $text): string
300300
// Including color codes, cursor control, clear screen and other control sequences
301301
return preg_replace('/\e\[[0-9;]*[a-zA-Z]/', '', $text);
302302
}
303+
304+
/**
305+
* Convert to a real path for display purposes, used in docker volumes.
306+
*/
307+
function get_display_path(string $path): string
308+
{
309+
$deploy_root = getenv('SPC_FIX_DEPLOY_ROOT');
310+
if ($deploy_root === false) {
311+
return $path;
312+
}
313+
$cwd = WORKING_DIR;
314+
// replace build root with deploy root, only if path starts with build root
315+
if (str_starts_with($path, $cwd)) {
316+
return $deploy_root . substr($path, strlen($cwd));
317+
}
318+
throw new WrongUsageException("Cannot convert path: {$path}");
319+
}

0 commit comments

Comments
 (0)