Skip to content

Commit

Permalink
Merge 7bfe29f into f21cafd
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed Jan 15, 2021
2 parents f21cafd + 7bfe29f commit eb6aa5c
Show file tree
Hide file tree
Showing 69 changed files with 366 additions and 207 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
60 changes: 37 additions & 23 deletions src/Domain/Model/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
*/
class Application
{
/**
* default directory name for shared directory
*
* @const
*/
public const DEFAULT_SHARED_DIR = 'shared';

public const DEFAULT_WEB_DIRECTORY = 'public';

/**
Expand All @@ -40,12 +33,14 @@ class Application
/**
* The deployment path for this application on a node
* @var string
* @deprecated
*/
protected $deploymentPath = '';

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

Expand Down Expand Up @@ -128,6 +123,8 @@ public function hasNode(Node $node): bool
* |-- $this->getReleasesDirectory()
* |-- cache
* |-- shared
*
* @deprecated Get path from the node instead
*/
public function getDeploymentPath(): string
{
Expand All @@ -138,6 +135,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 @@ -149,10 +148,12 @@ 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
{
$result = self::DEFAULT_SHARED_DIR;
$result = Node::DEFAULT_SHARED_DIR;
if ($this->hasOption('sharedDirectory') && !empty($this->getOption('sharedDirectory'))) {
$sharedPath = $this->getOption('sharedDirectory');
if (preg_match('/(^|\/)\.\.(\/|$)/', $sharedPath)) {
Expand All @@ -169,17 +170,42 @@ public function getSharedDirectory(): string
return $result;
}

/**
* @param string $deploymentPath
* @return $this
*
* @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() === null) {
$node->setDeploymentPath($this->deploymentPath);
}
}, $this->nodes);

return $this;
}

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

/**
* @param string $releasesDirectory
* @return $this
* @throws InvalidConfigurationException
* @deprecated Set path in node instead
*/
public function setReleasesDirectory(string $releasesDirectory): self
{
if (preg_match('/(^|\/)\.\.(\/|$)/', $releasesDirectory)) {
Expand All @@ -194,6 +220,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 All @@ -208,11 +235,7 @@ public function getReleasesPath(): string
*/
public function getOptions(): array
{
return array_merge($this->options, [
'deploymentPath' => $this->getDeploymentPath(),
'releasesPath' => $this->getReleasesPath(),
'sharedPath' => $this->getSharedPath()
]);
return $this->options;
}

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

public function hasOption(string $key): bool
Expand Down
14 changes: 6 additions & 8 deletions src/Domain/Model/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,25 @@ public function simulate()
}

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

/**
* @param Application $application
*
* @param Node $node
* @return string
*/
public function getApplicationReleasePath(Application $application)
public function getApplicationReleasePath(Node $node)
{
return Files::concatenatePaths([
$this->getApplicationReleaseBasePath($application),
$this->getApplicationReleaseBasePath($node),
$this->relativeProjectRootPath
]);
}
Expand Down
120 changes: 113 additions & 7 deletions src/Domain/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,39 @@
* file that was distributed with this source code.
*/

/**
* A Node
*/
use TYPO3\Surf\Exception\InvalidConfigurationException;

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

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

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

/**
* The deployment path on the node
*
* @var string
*/
protected $deploymentPath;

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

/**
* Options for this node
*
Expand Down Expand Up @@ -49,6 +71,77 @@ public function getName()
return $this->name;
}

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
*
Expand All @@ -75,9 +168,13 @@ public function setHostname($hostname)
*
* @return array The Node's options
*/
public function getOptions()
public function getOptions(): array
{
return $this->options;
return array_merge($this->options, [
'deploymentPath' => $this->getDeploymentPath(),
'releasesPath' => $this->getReleasesPath(),
'sharedPath' => $this->getSharedPath()
]);
}

/**
Expand All @@ -96,9 +193,18 @@ public function setOptions(array $options)
* @param string $key
* @return mixed
*/
public function getOption($key)
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
2 changes: 1 addition & 1 deletion src/Task/CleanupReleasesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function execute(Node $node, Application $application, Deployment $deploy
return;
}

$releasesPath = $application->getReleasesPath();
$releasesPath = $node->getReleasesPath();
$currentReleaseIdentifier = $deployment->getReleaseIdentifier();

$previousReleaseIdentifier = \TYPO3\Surf\findPreviousReleaseIdentifier($deployment, $node, $application, $this->shell);
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Composer/AbstractComposerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function execute(Node $node, Application $application, Deployment $deploy
if ($options['useApplicationWorkspace']) {
$composerRootPath = $deployment->getWorkspaceWithProjectRootPath($application);
} else {
$composerRootPath = $deployment->getApplicationReleasePath($application);
$composerRootPath = $deployment->getApplicationReleasePath($node);
}

if ($options['nodeName'] !== null) {
Expand Down

0 comments on commit eb6aa5c

Please sign in to comment.