Skip to content

Commit

Permalink
Merge 7976a17 into f67f5ca
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed Mar 16, 2022
2 parents f67f5ca + 7976a17 commit 35d2274
Show file tree
Hide file tree
Showing 90 changed files with 415 additions and 174 deletions.
2 changes: 1 addition & 1 deletion Documentation/Examples/Neos/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ If you would like to deploy a Neos website a good starting point is to use the N
$node = new \TYPO3\Surf\Domain\Model\Node('production');
$node
->setHostname('my.node.com')
->setDeploymentPath('/var/www/vhosts/my.node.com')
->setOption('username', 'myuser');

$application = new \TYPO3\Surf\Application\Neos\Neos('My Node');
Expand All @@ -28,7 +29,6 @@ If you would like to deploy a Neos website a good starting point is to use the N
'Neos_Fusion_Content',
'Neos_Neos_Fusion'
])
->setDeploymentPath('/var/www/vhosts/my.node.com')
->addNode($node);

$deployment
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Examples/TYPO3/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ If you would like to deploy a TYPO3 website a good starting point is to use TYPO
$node = new \TYPO3\Surf\Domain\Model\Node('my.node.com');
$node
->setHostname($node->getName())
->setDeploymentPath('/httpdocs')
->setOption('username', 'myuser')
->setOption('phpBinaryPathAndFilename', '/usr/local/bin/php_cli');

$application = new \TYPO3\Surf\Application\TYPO3\CMS();
$application
->setDeploymentPath('/httpdocs')
->setOption('baseUrl', 'https://my.node.com/')
->setOption('webDirectory', 'public')
->setOption('symlinkDataFolders', ['fileadmin'])
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Usage/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ with name **MyDeployment**::
<?php
$node = new \TYPO3\Surf\Domain\Model\Node('example');
$node->setHostname('example.com');
$node->setDeploymentPath('/home/my-flow-app/app');
$node->setOption('username', 'myuser');

$application = new \TYPO3\Surf\Application\Neos\Flow();
$application->setVersion('4.0');
$application->setDeploymentPath('/home/my-flow-app/app');
$application->setOption('repositoryUrl', 'git@github.com:myuser/my-flow-app.git');
$application->addNode($node);

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"phpstan": "phpstan analyse",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff",
"check-style": "vendor/bin/phpcs -p --standard=ruleset.xml --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "vendor/bin/phpcbf -p --standard=ruleset.xml --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
"fix-style": "vendor/bin/phpcbf -p --standard=ruleset.xml --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"test": "vendor/bin/phpunit"
}
}
41 changes: 41 additions & 0 deletions src/Domain/Model/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class Application

/**
* The deployment path for this application on a node
* @deprecated
*/
protected string $deploymentPath = '';

/**
* The relative releases directory for this application on a node
* @deprecated
*/
protected string $releasesDirectory = 'releases';

Expand Down Expand Up @@ -102,13 +104,27 @@ public function setNodes(array $nodes): self

$this->nodes = $nodes;

// Backwards compatibility if deployment path is set in application, set it for all nodes where path is null
// FIXME: can be removed in Surf 4.0
array_map(function (Node $node) {
if ($node->getDeploymentPath() === '') {
$node->setDeploymentPath($this->deploymentPath);
}
}, $this->nodes);

return $this;
}

public function addNode(Node $node): self
{
$this->nodes[$node->getName()] = $node;

// Backwards compatibility if deployment path is set in application, set it for all nodes where path is null
// FIXME: can be removed in Surf 4.0
if ($node->getDeploymentPath() === '') {
$node->setDeploymentPath($this->deploymentPath);
}

return $this;
}

Expand All @@ -126,6 +142,8 @@ public function hasNode(Node $node): bool
* |-- $this->getReleasesDirectory()
* |-- cache
* |-- shared
*
* @deprecated Get path from the node instead
*/
public function getDeploymentPath(): string
{
Expand All @@ -136,6 +154,8 @@ public function getDeploymentPath(): string
* Get the path for shared resources for this application
*
* This path defaults to a directory "shared" below the deployment path.
*
* @deprecated Get path from the node instead
*/
public function getSharedPath(): string
{
Expand All @@ -147,6 +167,8 @@ public function getSharedPath(): string
*
* takes directory name from option "sharedDirectory"
* if option is not set or empty constant DEFAULT_SHARED_DIR "shared" is used
*
* @deprecated Get path from node instead
*/
public function getSharedDirectory(): string
{
Expand All @@ -165,18 +187,36 @@ public function getSharedDirectory(): string
return rtrim($sharedDirectory, '/');
}

/**
* @deprecated Set path in node instead
*/
public function setDeploymentPath(string $deploymentPath): self
{
$this->deploymentPath = rtrim($deploymentPath, '/');

// Backwards compatibility if deployment path is set in application, set it for all nodes where path is null
// FIXME: can be removed in Surf 4.0
array_map(function (Node $node) {
if ($node->getDeploymentPath() === '') {
$node->setDeploymentPath($this->deploymentPath);
}
}, $this->nodes);

return $this;
}

/**
* @deprecated Get path from node instead
*/
public function getReleasesDirectory(): string
{
return $this->releasesDirectory;
}

/**
* @throws InvalidConfigurationException
* @deprecated Set path in node instead
*/
public function setReleasesDirectory(string $releasesDirectory): self
{
$message = sprintf('"../" is not allowed in the releases directory "%s"', $releasesDirectory);
Expand All @@ -189,6 +229,7 @@ public function setReleasesDirectory(string $releasesDirectory): self

/**
* Returns path to the directory with releases
* @deprecated Get path from the node instead
*/
public function getReleasesPath(): string
{
Expand Down
8 changes: 4 additions & 4 deletions src/Domain/Model/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ public function simulate(): void
$this->getWorkflow()->run($this);
}

public function getApplicationReleaseBasePath(Application $application): string
public function getApplicationReleaseBasePath(Node $node): string
{
return Files::concatenatePaths([
$application->getReleasesPath(),
$node->getReleasesPath(),
$this->getReleaseIdentifier()
]);
}

public function getApplicationReleasePath(Application $application): string
public function getApplicationReleasePath(Node $node): string
{
return Files::concatenatePaths([
$this->getApplicationReleaseBasePath($application),
$this->getApplicationReleaseBasePath($node),
$this->relativeProjectRootPath
]);
}
Expand Down
122 changes: 116 additions & 6 deletions src/Domain/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,39 @@

namespace TYPO3\Surf\Domain\Model;

use TYPO3\Surf\Exception\InvalidConfigurationException;

/**
* A Node
*/
class Node
{
/**
* default directory name for shared directory
*
* @const
*/
public const DEFAULT_SHARED_DIR = 'shared';

private const FORBIDDEN_SHARED_REGULAR_EXPRESSION = '/(^|\/)\.\.(\/|$)/';

/**
* The name
*/
protected string $name;

/**
* The deployment path on the node
*/
protected string $deploymentPath = '';

/**
* The relative releases directory on a node
*
* @var string
*/
protected string $releasesDirectory = 'releases';

/**
* Options for this node
*
Expand All @@ -36,7 +62,81 @@ public function getName(): string
return $this->name;
}

public function getHostname(): string
public function getDeploymentPath(): string
{
return $this->deploymentPath;
}

public function setDeploymentPath(string $deploymentPath): self
{
$this->deploymentPath = $deploymentPath;
return $this;
}

public function getReleasesDirectory(): string
{
return $this->releasesDirectory;
}

public function setReleasesDirectory(string $releasesDirectory): self
{
if (preg_match(self::FORBIDDEN_SHARED_REGULAR_EXPRESSION, $releasesDirectory)) {
throw new InvalidConfigurationException(
sprintf('"../" is not allowed in the releases directory "%s"', $releasesDirectory),
1380870750
);
}
$this->releasesDirectory = trim($releasesDirectory, '/');
return $this;
}

/**
* Get the path for shared resources for this application
*
* This path defaults to a directory "shared" below the deployment path.
*/
public function getSharedPath(): string
{
return $this->getDeploymentPath() . '/' . $this->getSharedDirectory();
}

/**
* Returns the shared directory
*
* takes directory name from option "sharedDirectory"
* if option is not set or empty constant DEFAULT_SHARED_DIR "shared" is used
*/
public function getSharedDirectory(): string
{
$result = self::DEFAULT_SHARED_DIR;
if ($this->hasOption('sharedDirectory') && !empty($this->getOption('sharedDirectory'))) {
$sharedPath = $this->getOption('sharedDirectory');
if (preg_match(self::FORBIDDEN_SHARED_REGULAR_EXPRESSION, $sharedPath)) {
throw new InvalidConfigurationException(
sprintf(
'Relative constructs as "../" are not allowed in option "sharedDirectory". Given option: "%s"',
$sharedPath
),
1490107183141
);
}
$result = rtrim($sharedPath, '/');
}
return $result;
}

/**
* Returns path to the directory with releases
*/
public function getReleasesPath(): string
{
return rtrim($this->getDeploymentPath() . '/' . $this->getReleasesDirectory(), '/');
}

/**
* Get the Node's hostname
*/
public function getHostname(): ?string
{
return $this->getOption('hostname');
}
Expand All @@ -48,7 +148,11 @@ public function setHostname(string $hostname): Node

public function getOptions(): array
{
return $this->options;
return array_merge($this->options, [
'deploymentPath' => $this->getDeploymentPath(),
'releasesPath' => $this->getReleasesPath(),
'sharedPath' => $this->getSharedPath()
]);
}

public function setOptions(array $options): self
Expand All @@ -62,7 +166,16 @@ public function setOptions(array $options): self
*/
public function getOption(string $key)
{
return $this->options[$key];
switch ($key) {
case 'deploymentPath':
return $this->getDeploymentPath();
case 'releasesPath':
return $this->getReleasesPath();
case 'sharedPath':
return $this->getSharedPath();
default:
return $this->options[$key];
}
}

/**
Expand Down Expand Up @@ -113,9 +226,6 @@ public function getUsername(): ?string
return null;
}

/**
* @return int|null
*/
public function getPort(): ?int
{
if ($this->hasOption('port')) {
Expand Down
16 changes: 16 additions & 0 deletions src/Domain/Service/RunOncePerDeploymentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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\Domain\Service;

interface RunOncePerDeploymentInterface
{
}

0 comments on commit 35d2274

Please sign in to comment.