Skip to content

Commit b4c7671

Browse files
committed
✅ Add fpm reloading when using forge
1 parent cb66cf8 commit b4c7671

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/LaravelDeployer/DeployFileGenerator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DeployFileGenerator
2424
'npm_build' => 'production',
2525
'hook_horizon_command' => 'before',
2626
'hook_horizon_other_hook' => 'deploy:symlink',
27+
'hook_fpm_version' => 'php7.1-fpm',
2728
];
2829

2930
protected $blocks = [
@@ -35,6 +36,7 @@ class DeployFileGenerator
3536
'hook_npm' => false,
3637
'hook_migrations' => false,
3738
'hook_horizon' => false,
39+
'hook_fpm' => false,
3840
'hook_empty' => true,
3941
];
4042

@@ -231,12 +233,26 @@ public function useForge()
231233
{
232234
$this->useForge = true;
233235
$this->localhost();
236+
$this->reloadFpm();
234237
$this->user('forge');
235238
$this->updateUnchangedDeploymentPathForForge();
236239

237240
return $this;
238241
}
239242

243+
/**
244+
* Set up to reload php-fpm when deploying.
245+
*
246+
* @return DeployFileGenerator
247+
*/
248+
public function reloadFpm()
249+
{
250+
$this->blocks['hook_fpm'] = true;
251+
$this->blocks['hook_empty'] = false;
252+
253+
return $this;
254+
}
255+
240256
/**
241257
* Return the current value of a replacement variable.
242258
*

src/LaravelDeployer/stubs/deploy.stub

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,8 @@ before('deploy:symlink', 'artisan:migrate');}}
8585
{{hook_horizon:// Horizon
8686
{{hook_horizon_command}}('{{hook_horizon_other_hook}}', 'artisan:horizon:terminate');}}
8787

88+
{{hook_fpm:// Reload php-fpm
89+
set('php_fpm_service', '{{hook_fpm_version}}');
90+
after('cleanup', 'fpm:reload');}}
91+
8892
{{hook_empty:// before('deploy:symlink', 'artisan:migrate');}}

tests/DeployFileGeneratorTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ function when_no_hooks_are_used_it_display_the_migration_hook_commented()
177177
$stubNpm = (new DeployFileGenerator)->useNpm()->getParsedStub();
178178
$stubMigrate = (new DeployFileGenerator)->migrate()->getParsedStub();
179179
$stubHorizon = (new DeployFileGenerator)->terminateHorizon()->getParsedStub();
180-
$stubFull = (new DeployFileGenerator)->useNpm()->migrate()->terminateHorizon()->getParsedStub();
180+
$stubFpm = (new DeployFileGenerator)->reloadFpm()->getParsedStub();
181181

182182
$this->assertContains("// before('deploy:symlink', 'artisan:migrate');", $stubEmpty);
183183
$this->assertNotContains("// before('deploy:symlink', 'artisan:migrate');", $stubNpm);
184184
$this->assertNotContains("// before('deploy:symlink', 'artisan:migrate');", $stubMigrate);
185185
$this->assertNotContains("// before('deploy:symlink', 'artisan:migrate');", $stubHorizon);
186-
$this->assertNotContains("// before('deploy:symlink', 'artisan:migrate');", $stubFull);
186+
$this->assertNotContains("// before('deploy:symlink', 'artisan:migrate');", $stubFpm);
187187
}
188188

189189
/** @test */
@@ -253,4 +253,26 @@ function it_returns_current_values_of_replacement_variables()
253253

254254
$this->assertEquals('Elegon', $appName);
255255
}
256+
257+
/** @test */
258+
function it_can_be_set_to_use_fpm_reloading()
259+
{
260+
$stub = (new DeployFileGenerator)
261+
->reloadFpm()
262+
->getParsedStub();
263+
264+
$this->assertContains("set('php_fpm_service', 'php7.1-fpm');", $stub);
265+
$this->assertContains("after('cleanup', 'fpm:reload');", $stub);
266+
}
267+
268+
/** @test */
269+
function it_automatically_use_fpm_reloading_when_using_forge()
270+
{
271+
$stub = (new DeployFileGenerator)
272+
->useForge()
273+
->getParsedStub();
274+
275+
$this->assertContains("set('php_fpm_service', 'php7.1-fpm');", $stub);
276+
$this->assertContains("after('cleanup', 'fpm:reload');", $stub);
277+
}
256278
}

0 commit comments

Comments
 (0)