Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15380186
D11495.id27648.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11495.id27648.diff
View Options
diff --git a/scripts/repository/commit_hook.php b/scripts/repository/commit_hook.php
--- a/scripts/repository/commit_hook.php
+++ b/scripts/repository/commit_hook.php
@@ -1,6 +1,25 @@
#!/usr/bin/env php
<?php
+// Commit hooks execute in an unusual context where the environment may be
+// unavailable, particularly in SVN. The first parameter to this script is
+// either a bare repository identifier ("X"), or a repository identifier
+// followed by an instance identifier ("X:instance"). If we have an instance
+// identifier, unpack it into the environment before we start up. This allows
+// subclasses of PhabricatorConfigSiteSource to read it and build an instance
+// environment.
+
+if ($argc > 1) {
+ $context = $argv[1];
+ $context = explode(':', $context, 2);
+ $argv[1] = $context[0];
+
+ if (count($context) > 1) {
+ $_ENV['PHABRICATOR_INSTANCE'] = $context[1];
+ putenv('PHABRICATOR_INSTANCE='.$context[1]);
+ }
+}
+
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
diff --git a/src/applications/config/option/PhabricatorClusterConfigOptions.php b/src/applications/config/option/PhabricatorClusterConfigOptions.php
--- a/src/applications/config/option/PhabricatorClusterConfigOptions.php
+++ b/src/applications/config/option/PhabricatorClusterConfigOptions.php
@@ -52,6 +52,18 @@
'0.0.0.0/0',
),
pht('Allow Any Host (Insecure!)')),
+ $this->newOption('cluster.instance', 'string', null)
+ ->setLocked(true)
+ ->setSummary(pht('Instance identifier for multi-tenant clusters.'))
+ ->setDescription(
+ pht(
+ 'WARNING: This is a very advanced option, and only useful for '.
+ 'hosting providers running multi-tenant clusters.'.
+ "\n\n".
+ 'If you provide an instance identifier here (normally by '.
+ 'injecting it with a `PhabricatorConfigSiteSource`), Phabricator '.
+ 'will pass it to subprocesses and commit hooks in the '.
+ '`PHABRICATOR_INSTANCE` environmental variable.')),
);
}
diff --git a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
--- a/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
+++ b/src/applications/repository/engine/PhabricatorRepositoryPullEngine.php
@@ -161,7 +161,7 @@
$this->log('%s', pht('Installing commit hook to "%s"...', $path));
$repository = $this->getRepository();
- $callsign = $repository->getCallsign();
+ $identifier = $this->getHookContextIdentifier($repository);
$root = dirname(phutil_get_library_root('phabricator'));
$bin = $root.'/bin/commit-hook';
@@ -171,7 +171,7 @@
'exec %s -f %s -- %s "$@"',
$full_php_path,
$bin,
- $callsign);
+ $identifier);
$hook = "#!/bin/sh\nexport TERM=dumb\n{$cmd}\n";
@@ -190,6 +190,17 @@
Filesystem::writeFile($path.'/README', $readme);
}
+ private function getHookContextIdentifier(PhabricatorRepository $repository) {
+ $identifier = $repository->getCallsign();
+
+ $instance = PhabricatorEnv::getEnvConfig('cluster.instance');
+ if (strlen($instance)) {
+ $identifier = "{$identifier}:{$instance}";
+ }
+
+ return $identifier;
+ }
+
/* -( Pulling Git Working Copies )----------------------------------------- */
@@ -412,6 +423,8 @@
$repository = $this->getRepository();
$path = $repository->getLocalPath().'/.hg/hgrc';
+ $identifier = $this->getHookContextIdentifier($repository);
+
$root = dirname(phutil_get_library_root('phabricator'));
$bin = $root.'/bin/commit-hook';
@@ -422,14 +435,14 @@
$data[] = csprintf(
'pretxnchangegroup.phabricator = %s %s %s',
$bin,
- $repository->getCallsign(),
+ $identifier,
'pretxnchangegroup');
// This one handles creating bookmarks.
$data[] = csprintf(
'prepushkey.phabricator = %s %s %s',
$bin,
- $repository->getCallsign(),
+ $identifier,
'prepushkey');
$data[] = null;
diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php
--- a/src/infrastructure/env/PhabricatorEnv.php
+++ b/src/infrastructure/env/PhabricatorEnv.php
@@ -112,6 +112,15 @@
// subprocess environments.
$_ENV['PATH'] = $env_path;
+
+ // If an instance identifier is defined, write it into the environment so
+ // it's available to subprocesses.
+ $instance = PhabricatorEnv::getEnvConfig('cluster.instance');
+ if (strlen($instance)) {
+ putenv('PHABRICATOR_INSTANCE='.$instance);
+ $_ENV['PHABRICATOR_INSTANCE'] = $instance;
+ }
+
PhabricatorEventEngine::initialize();
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 15, 1:53 AM (1 w, 22 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7309122
Default Alt Text
D11495.id27648.diff (4 KB)
Attached To
Mode
D11495: Promote instance identity to the upstream and pass it to commit hooks
Attached
Detach File
Event Timeline
Log In to Comment