Skip to content

Commit 883aa88

Browse files
committed
Log path fix
1 parent 3d165db commit 883aa88

3 files changed

Lines changed: 70 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DEPLOY_COMPOSER_BIN=composer
3838
DEPLOY_COMPOSER_HOME= # blank = storage/app/.composer
3939
DEPLOY_COMPOSER_MEMORY_LIMIT=-1
4040
DEPLOY_TIMEOUT=600
41-
DEPLOY_LOGS_DIRECTORY_PATH="../deploylogs/"
41+
DEPLOY_LOGS_DIRECTORY_PATH="storage/logs/deploy"
4242
```
4343

4444
Each secret gates its own endpoint, and every one of them is required for that
@@ -174,6 +174,32 @@ production.ERROR: deployme: deploy failed {"via":"trigger","branch":"dev",
174174
`via` distinguishes the webhook from the manual trigger. The full, untruncated output
175175
of every step is in that run's file under `DEPLOY_LOGS_DIRECTORY_PATH`.
176176

177+
### No run files appearing?
178+
179+
`DEPLOY_LOGS_DIRECTORY_PATH` resolves **relative to the repository root**, not the CWD,
180+
and it must be writable by the *web user* — not by you. A path like `../deploylogs/`
181+
lands outside the application, in `/var/www/` on a typical layout, which the web user
182+
almost never owns; `open_basedir`, where it is set, blocks the `..` traversal for the
183+
same result. Prefer somewhere inside the app that the web user already has to own:
184+
185+
```
186+
DEPLOY_LOGS_DIRECTORY_PATH="storage/logs/deploy"
187+
```
188+
189+
A deploy is never blocked by a log it cannot write, but it no longer stays quiet about
190+
it either — the Laravel log gets a warning naming the configured path, the path it
191+
resolved to, and whether the parent is writable:
192+
193+
```
194+
production.WARNING: deployme: could not create the deploy log directory —
195+
the deploy will still run, but unlogged
196+
{"configured":"../deploylogs/","resolved":"/var/www/site/../deploylogs/",
197+
"parent":"/var/www/site/..","parent_writable":false,"error":"mkdir(): Permission denied"}
198+
```
199+
200+
Blank the setting to turn file logging off deliberately; that is the one case that
201+
passes without a warning.
202+
177203
Reading the exit code:
178204

179205
| Exit | Usually means |

‎config/deployme.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,5 @@
111111
|
112112
*/
113113

114-
'logs_path' => env('DEPLOY_LOGS_DIRECTORY_PATH', '../deploylogs/'),
114+
'logs_path' => env('DEPLOY_LOGS_DIRECTORY_PATH', 'storage/logs/deploy'),
115115
];

‎src/Support/DeployLogger.php‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
namespace Wizcoders\Deployme\Support;
44

5+
use Illuminate\Support\Facades\Log;
6+
57
/**
68
* Centralized deployment logging.
79
*
810
* Handles log file creation, path resolution, and writing with consistent formatting.
911
* Returns null rather than throwing on file errors — a missing or unwritable
1012
* log directory must not block a deploy.
13+
*
14+
* It must, however, *say* so. Failing silently means a deploy that logged nothing
15+
* looks exactly like a deploy that was never fired, which is the worst state to
16+
* debug from. Every failure here is therefore a Log::warning; only a blank
17+
* logs_path — a deliberate "off" — passes quietly.
1118
*/
1219
class DeployLogger
1320
{
@@ -24,19 +31,24 @@ class DeployLogger
2431
*/
2532
public static function open(string $repositoryPath): ?self
2633
{
27-
$path = trim((string) config('deployme.logs_path', ''));
34+
$configured = trim((string) config('deployme.logs_path', ''));
2835

29-
if ($path === '') {
36+
// Blank is a deliberate "no file logging", not a failure. Say nothing.
37+
if ($configured === '') {
3038
return null;
3139
}
3240

3341
// Relative paths in .env are relative to the repository root, not the CWD.
34-
if (!Git::isAbsolute($path)) {
35-
$path = $repositoryPath . DIRECTORY_SEPARATOR . $path;
36-
}
42+
$path = Git::isAbsolute($configured)
43+
? $configured
44+
: $repositoryPath . DIRECTORY_SEPARATOR . $configured;
3745

38-
// Create directory if it doesn't exist
39-
@mkdir($path, 0755, true);
46+
// The trailing is_dir() covers the race where a concurrent run wins the mkdir.
47+
if (! is_dir($path) && ! @mkdir($path, 0755, true) && ! is_dir($path)) {
48+
self::warn('could not create the deploy log directory', $path, $configured);
49+
50+
return null;
51+
}
4052

4153
// Colons are legal in a POSIX filename but not on Windows, and they make
4254
// the log awkward to scp — so H-i-s, not H:i:s.
@@ -45,6 +57,8 @@ public static function open(string $repositoryPath): ?self
4557
$handle = @fopen($file, 'w');
4658

4759
if ($handle === false) {
60+
self::warn('could not open the deploy log file', $file, $configured);
61+
4862
return null;
4963
}
5064

@@ -54,6 +68,27 @@ public static function open(string $repositoryPath): ?self
5468
return $logger;
5569
}
5670

71+
/**
72+
* Report a logging failure to the Laravel log, then let the deploy continue.
73+
*
74+
* Reports the resolved path as well as the configured one: '../deploylogs/'
75+
* looks harmless in .env but lands outside the application root, which is
76+
* usually where the permission denial comes from.
77+
*/
78+
private static function warn(string $message, string $path, string $configured): void
79+
{
80+
$parent = dirname($path);
81+
82+
Log::warning("deployme: {$message} — the deploy will still run, but unlogged", [
83+
'configured' => $configured,
84+
'resolved' => $path,
85+
'parent' => $parent,
86+
'parent_exists' => is_dir($parent),
87+
'parent_writable' => is_writable($parent),
88+
'error' => error_get_last()['message'] ?? null,
89+
]);
90+
}
91+
5792
/**
5893
* Write a line to the log file.
5994
*

0 commit comments

Comments
 (0)