-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Per user persistent storage #1269
Changes from 3 commits
d013f95
ad11d01
b0e373d
f4235f6
ced4a16
4b0bdf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,73 @@ | |
|
||
class Storage | ||
{ | ||
/** | ||
* In a multi user environment where multiple projects are located on the same instance(s) | ||
* if two or more users are deploying at the same time on the same environment, | ||
* the generated hosts files are overwritten or worse, the deploy will fail | ||
* due to file permissions | ||
* | ||
* Make the persistent storage folder configurable or use the system tmp | ||
* as default if not possible | ||
* | ||
* @return string | ||
* @throws Exception | ||
*/ | ||
private static function _getPersistentStorageLocation() { | ||
$config = \Deployer\Deployer::get()->config; | ||
|
||
// use the system temporary folder and the current pid as default | ||
// persistent storage in case we can't use the configured value | ||
// or we can't create the default location | ||
$tmp = sys_get_temp_dir() . '/' . posix_getpid(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extension is not available on Windows platforms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For non posix compatible i'm going to use getmypid. |
||
|
||
// get the location for the deployer configuration | ||
$deployerConfig = $config->has('deployer_config') ? $config->get('deployer_config') : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's over this PR, I think such functionality should done in separate PR. Anyway I don't see way it's needed. Please remove everything related to deployer_config. |
||
|
||
if ( !is_null($deployerConfig) ) { | ||
// check if the folder exists and it's writable | ||
if ( !(is_dir($deployerConfig) && is_writable($deployerConfig)) ) { | ||
throw new Exception("Deployer folder `$deployerConfig` doesn't exists or doesn't writable."); | ||
} | ||
} else { | ||
// not configured, generate deployer folder name | ||
|
||
// use the home dir of the current user | ||
// and the repository name | ||
$userInfo = posix_getpwuid(posix_getuid()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, what about windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For non posix compatible i'm going to use getenv. It's Windows 8+ enough? |
||
|
||
// if for some reason we couldn't find a valid home folder | ||
// or if it's not writable, use the default location | ||
if ( !isset($userInfo['dir']) || !(is_dir($userInfo['dir']) && is_writable($userInfo['dir'])) ) { | ||
return $tmp; | ||
} | ||
|
||
// we have a folder name | ||
$deployerConfig = $userInfo['dir'] . '/.deployer'; | ||
|
||
//if it doesn't exists, create it | ||
if ( !file_exists($deployerConfig) ) { | ||
mkdir($deployerConfig, 0777, true); | ||
} | ||
|
||
//it exists, check if it's a folder and if it's writable | ||
if ( !(is_dir($deployerConfig) && is_writable($deployerConfig)) ) { | ||
return $tmp; | ||
} | ||
} | ||
|
||
// we will store the persistent data per repository | ||
$configRepository = $config->has('repository') ? $config->get('repository') : null; | ||
if (empty($configRepository)) { | ||
return $tmp; | ||
} | ||
|
||
// we now have the repository name | ||
$repository = str_replace('/', '_', substr($configRepository, (strrpos($configRepository, ':') + 1))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is it for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long story short: i have five webapps on the same instances (my staging). If i deploy two apps at the same time (using two terminals for example) the second one i launch will overwrite the content of the .dep files so, the first deployer will start running tasks in the locations set by the second one and everything ends up in a mess. The .dep files should be stored per webapp so, the easiest way was to use the repository to generate a separate folder name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's easier to create rundom files instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Easier yes... but then you will need an internal task to clean up temporary files older than N days or something simmilar. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But tmp cleaned by system itself |
||
|
||
return $deployerConfig . '/' . $repository; | ||
} | ||
|
||
/** | ||
* @param Host[] $hosts | ||
*/ | ||
|
@@ -27,7 +94,7 @@ public static function persist(array $hosts) | |
$values[$key] = $host->get($key); | ||
} | ||
|
||
$file = sys_get_temp_dir() . '/' . $host->getHostname() . '.dep'; | ||
$file = self::_getPersistentStorageLocation() . '/' . $host->getHostname() . '.dep'; | ||
$values['host_config_storage'] = $file; | ||
|
||
$persistentCollection = new PersistentCollection($file, $values); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename
_getPersistentStorageLocation
togetPersistentStorageLocation
and move this method to end of class.