-
-
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
13 changed files
with
923 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,82 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TYPO3\Surf\Application; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Workflow; | ||
use TYPO3\Surf\Task\Laravel\ClearAuthResetsTask; | ||
use TYPO3\Surf\Task\Laravel\CreateDirectoriesTask; | ||
use TYPO3\Surf\Task\Laravel\EnvAwareTask; | ||
use TYPO3\Surf\Task\Laravel\FlushCachesTask; | ||
use TYPO3\Surf\Task\Laravel\MigrateTask; | ||
use TYPO3\Surf\Task\Laravel\StorageLinkTask; | ||
use TYPO3\Surf\Task\Laravel\SymlinkStorageTask; | ||
use TYPO3\Surf\Task\Laravel\WarmUpCachesTask; | ||
|
||
class Laravel extends BaseApplication | ||
{ | ||
/** | ||
* Constructor | ||
* @param string $name | ||
*/ | ||
public function __construct($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 | ||
* | ||
* @param Workflow $workflow | ||
* @param Deployment $deployment | ||
* @return void | ||
*/ | ||
public function registerTasks(Workflow $workflow, Deployment $deployment): void | ||
{ | ||
parent::registerTasks($workflow, $deployment); | ||
|
||
$workflow | ||
->addTask(CreateDirectoriesTask::class, 'initialize', $this) | ||
->afterStage('update', [ | ||
EnvAwareTask::class, | ||
SymlinkStorageTask::class | ||
], $this) | ||
->afterStage('migrate', MigrateTask::class, $this) | ||
->afterStage('finalize', [ | ||
FlushCachesTask::class, | ||
WarmUpCachesTask::class | ||
], $this) | ||
->afterStage('switch', StorageLinkTask::class, $this) | ||
->afterStage('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,165 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
use TYPO3\Flow\Utility\Files; | ||
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 $workingDirectory; | ||
|
||
/** | ||
* Localhost or deployment target node | ||
* | ||
* @var Node | ||
*/ | ||
protected $targetNode; | ||
|
||
/** | ||
* 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 . ' '; | ||
|
||
return $this->shell->executeOrSimulate( | ||
[ | ||
'cd ' . escapeshellarg($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 | ||
* @return void | ||
*/ | ||
public function simulate(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
$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 = [] | ||
) { | ||
if (!isset($this->workingDirectory, $this->targetNode)) { | ||
if (isset($options['useApplicationWorkspace']) && $options['useApplicationWorkspace'] === true) { | ||
$this->workingDirectory = $deployment->getWorkspacePath($application); | ||
$node = $deployment->getNode('localhost'); | ||
} else { | ||
$this->workingDirectory = $deployment->getApplicationReleasePath($application); | ||
} | ||
$this->targetNode = $node; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if a given directory exists. | ||
* | ||
* @param string $directory | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
* @return bool | ||
* @throws \TYPO3\Surf\Exception\TaskExecutionException | ||
*/ | ||
protected function directoryExists( | ||
$directory, | ||
Node $node, | ||
Application $application, | ||
Deployment $deployment, | ||
array $options = [] | ||
) { | ||
$this->determineWorkingDirectoryAndTargetNode($node, $application, $deployment, $options); | ||
$directory = Files::concatenatePaths([$this->workingDirectory, $directory]); | ||
return $this->shell->executeOrSimulate( | ||
'test -d ' . escapeshellarg($directory), | ||
$this->targetNode, | ||
$deployment, | ||
true | ||
) !== false; | ||
} | ||
|
||
/** | ||
* Checks if a given file exists. | ||
* | ||
* @param string $pathAndFileName | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
* @return bool | ||
* @throws \TYPO3\Surf\Exception\TaskExecutionException | ||
*/ | ||
protected function fileExists( | ||
$pathAndFileName, | ||
Node $node, | ||
Application $application, | ||
Deployment $deployment, | ||
array $options = [] | ||
) { | ||
$this->determineWorkingDirectoryAndTargetNode($node, $application, $deployment, $options); | ||
$pathAndFileName = $this->workingDirectory . '/' . $pathAndFileName; | ||
return $this->shell->executeOrSimulate( | ||
'test -f ' . escapeshellarg($pathAndFileName), | ||
$this->targetNode, | ||
$deployment, | ||
true | ||
) !== false; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
use TYPO3\Surf\Application\Laravel; | ||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use TYPO3\Surf\Exception\TaskExecutionException; | ||
use Webmozart\Assert\Assert; | ||
|
||
class ClearAuthResetsTask extends AbstractCliTask | ||
{ | ||
/** | ||
* Execute this task | ||
* | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
* @return void | ||
* @throws TaskExecutionException | ||
*/ | ||
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,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
use TYPO3\Surf\Domain\Model\Application; | ||
use TYPO3\Surf\Domain\Model\Deployment; | ||
use TYPO3\Surf\Domain\Model\Node; | ||
use TYPO3\Surf\Exception\InvalidConfigurationException; | ||
|
||
class CreateDirectoriesTask extends \TYPO3\Surf\Task\Generic\CreateDirectoriesTask | ||
{ | ||
/** | ||
* Execute this task | ||
* | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
* @throws InvalidConfigurationException | ||
*/ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
$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,53 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace TYPO3\Surf\Task\Laravel; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
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; | ||
use TYPO3\Surf\Exception\TaskExecutionException; | ||
|
||
class EnvAwareTask extends Task implements ShellCommandServiceAwareInterface | ||
{ | ||
use ShellCommandServiceAwareTrait; | ||
|
||
/** | ||
* Execute this task | ||
* | ||
* @param Node $node | ||
* @param Application $application | ||
* @param Deployment $deployment | ||
* @param array $options | ||
* | ||
* @throws TaskExecutionException | ||
*/ | ||
public function execute(Node $node, Application $application, Deployment $deployment, array $options = []) | ||
{ | ||
$sharedPath = $application->getSharedPath(); | ||
$releasePath = $deployment->getApplicationReleasePath($application); | ||
|
||
$result = $this->shell->execute(sprintf('test -f %s/.env', $sharedPath), $node, $deployment, true); | ||
if ($result === false) { | ||
throw new TaskExecutionException('.env file in "' . $sharedPath . '" does not exist on node ' . $node->getName(), 1582080037); | ||
} | ||
|
||
$command = sprintf( | ||
'cp %s %s', | ||
escapeshellarg($sharedPath . '/.env'), | ||
escapeshellarg($releasePath . '/.env') | ||
); | ||
|
||
$this->shell->executeOrSimulate($command, $node, $deployment); | ||
} | ||
} |
Oops, something went wrong.