-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,597 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Application; | ||
|
||
use TYPO3\Surf\Domain\Enum\SimpleWorkflowStage; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Workflow; | ||
use TYPO3\Surf\Task\Laravel\ClearAuthResetsTask; | ||
use TYPO3\Surf\Task\Laravel\ConfigCacheTask; | ||
use TYPO3\Surf\Task\Laravel\CreateDirectoriesTask; | ||
use TYPO3\Surf\Task\Laravel\EnvAwareTask; | ||
use TYPO3\Surf\Task\Laravel\MigrateTask; | ||
use TYPO3\Surf\Task\Laravel\RouteCacheTask; | ||
use TYPO3\Surf\Task\Laravel\StorageLinkTask; | ||
use TYPO3\Surf\Task\Laravel\SymlinkStorageTask; | ||
use TYPO3\Surf\Task\Laravel\ViewCacheTask; | ||
|
||
class Laravel extends BaseApplication | ||
{ | ||
public function __construct(string $name = 'Laravel') | ||
{ | ||
parent::__construct($name); | ||
$this->options = array_merge($this->options, [ | ||
'webDirectory' => 'public', | ||
'rsyncExcludes' => [ | ||
'.git', | ||
'*.example', | ||
'*.lock', | ||
'.editorconfig', | ||
'.gitattributes', | ||
'.gitignore', | ||
'.styleci.yml', | ||
'/package.json', | ||
'/package-lock.json', | ||
'/phpunit.xml', | ||
'/README.md', | ||
'/storage', | ||
'/tests', | ||
'/server.php', | ||
'/webpack.mix.js', | ||
'{webDirectory}/storage', | ||
] | ||
]); | ||
} | ||
|
||
/** | ||
* Register tasks for this application | ||
*/ | ||
public function registerTasks(Workflow $workflow, Deployment $deployment): void | ||
{ | ||
parent::registerTasks($workflow, $deployment); | ||
|
||
$workflow | ||
->addTask(CreateDirectoriesTask::class, SimpleWorkflowStage::STEP_01_INITIALIZE, $this) | ||
->addTask([ | ||
SymlinkStorageTask::class, | ||
EnvAwareTask::class, | ||
], SimpleWorkflowStage::STEP_05_UPDATE, $this) | ||
->addTask(MigrateTask::class, SimpleWorkflowStage::STEP_06_MIGRATE, $this) | ||
->addTask([ | ||
StorageLinkTask::class, | ||
ConfigCacheTask::class, | ||
RouteCacheTask::class, | ||
ViewCacheTask::class, | ||
], SimpleWorkflowStage::STEP_07_FINALIZE, $this) | ||
->afterStage(SimpleWorkflowStage::STEP_10_CLEANUP, ClearAuthResetsTask::class, $this) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use TYPO3\Surf\Domain\Model\Task; | ||
use TYPO3\Surf\Domain\Service\ShellCommandServiceAwareInterface; | ||
use TYPO3\Surf\Domain\Service\ShellCommandServiceAwareTrait; | ||
|
||
abstract class AbstractCliTask extends Task implements ShellCommandServiceAwareInterface | ||
{ | ||
use ShellCommandServiceAwareTrait; | ||
|
||
/** | ||
* The working directory. Either local or remote, and probably in a special application root directory | ||
* | ||
* @var string | ||
*/ | ||
protected ?string $workingDirectory = null; | ||
|
||
/** | ||
* Localhost or deployment target node | ||
*/ | ||
protected ?Node $targetNode = null; | ||
|
||
/** | ||
* Execute this task | ||
* | ||
* @param array $cliArguments | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
* @return bool|mixed | ||
* @throws \TYPO3\Surf\Exception\TaskExecutionException | ||
*/ | ||
protected function executeCliCommand( | ||
array $cliArguments, | ||
Node $node, | ||
Application $application, | ||
Deployment $deployment, | ||
array $options = [] | ||
) { | ||
$this->determineWorkingDirectoryAndTargetNode($node, $application, $deployment, $options); | ||
$phpBinaryPathAndFilename = $options['phpBinaryPathAndFilename'] ?? 'php'; | ||
$commandPrefix = $phpBinaryPathAndFilename . ' '; | ||
|
||
if (!$this->targetNode instanceof Node) { | ||
return false; | ||
} | ||
|
||
return $this->shell->executeOrSimulate([ | ||
'cd ' . escapeshellarg((string)$this->workingDirectory), | ||
$commandPrefix . implode(' ', array_map('escapeshellarg', $cliArguments)) | ||
], $this->targetNode, $deployment); | ||
} | ||
|
||
/** | ||
* Simulate this task | ||
* | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
*/ | ||
public function simulate(Node $node, Application $application, Deployment $deployment, array $options = []): void | ||
{ | ||
$this->execute($node, $application, $deployment, $options); | ||
} | ||
|
||
/** | ||
* Determines the path to the working directory and the target node by given options | ||
* | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
*/ | ||
protected function determineWorkingDirectoryAndTargetNode( | ||
Node $node, | ||
Application $application, | ||
Deployment $deployment, | ||
array $options = [] | ||
): void { | ||
if (!isset($this->workingDirectory, $this->targetNode)) { | ||
if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === true) { | ||
$this->workingDirectory = $deployment->getWorkspacePath($application); | ||
$node = $deployment->createLocalhostNode(); | ||
} else { | ||
$this->workingDirectory = $deployment->getApplicationReleasePath($application); | ||
} | ||
$this->targetNode = $node; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
use TYPO3\Surf\Application\Laravel; | ||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use Webmozart\Assert\Assert; | ||
|
||
class ClearAuthResetsTask extends AbstractCliTask | ||
{ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
Assert::isInstanceOf( | ||
$application, | ||
Laravel::class, | ||
sprintf('Laravel application needed for %s, got "%s"', get_class($this), get_class($application)) | ||
); | ||
|
||
$this->executeCliCommand( | ||
['artisan', 'auth:clear-resets'], | ||
$node, | ||
$application, | ||
$deployment, | ||
$options | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
use TYPO3\Surf\Application\Laravel; | ||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use Webmozart\Assert\Assert; | ||
|
||
class ConfigCacheTask extends AbstractCliTask | ||
{ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
Assert::isInstanceOf( | ||
$application, | ||
Laravel::class, | ||
sprintf('Laravel application needed for %s, got "%s"', get_class($this), get_class($application)) | ||
); | ||
|
||
$this->executeCliCommand( | ||
['artisan', 'config:cache'], | ||
$node, | ||
$application, | ||
$deployment, | ||
$options | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
|
||
class CreateDirectoriesTask extends \TYPO3\Surf\Task\Generic\CreateDirectoriesTask | ||
{ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []): void | ||
{ | ||
$options = [ | ||
'directories' => [ | ||
'shared/storage/app/public', | ||
'shared/storage/framework/cache/data', | ||
'shared/storage/framework/sessions', | ||
'shared/storage/framework/testing', | ||
'shared/storage/framework/views', | ||
], | ||
'baseDirectory' => $application->getDeploymentPath() | ||
]; | ||
parent::execute($node, $application, $deployment, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
use TYPO3\Surf\Application\Laravel; | ||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use Webmozart\Assert\Assert; | ||
|
||
class DisableMaintenanceModeTask extends AbstractCliTask | ||
{ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
Assert::isInstanceOf( | ||
$application, | ||
Laravel::class, | ||
sprintf('Laravel application needed for %s, got "%s"', get_class($this), get_class($application)) | ||
); | ||
|
||
$this->executeCliCommand( | ||
['artisan', 'up'], | ||
$node, | ||
$application, | ||
$deployment, | ||
$options | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of TYPO3 Surf. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
use TYPO3\Surf\Application\Laravel; | ||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use Webmozart\Assert\Assert; | ||
|
||
class EnableMaintenanceModeTask extends AbstractCliTask | ||
{ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
Assert::isInstanceOf( | ||
$application, | ||
Laravel::class, | ||
sprintf('Laravel application needed for %s, got "%s"', get_class($this), get_class($application)) | ||
); | ||
|
||
$this->executeCliCommand( | ||
['artisan', 'down'], | ||
$node, | ||
$application, | ||
$deployment, | ||
$options | ||
); | ||
} | ||
} |
Oops, something went wrong.