mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-09 14:21:02 +01:00
Allow Drydock to allocate (very basic) working copy resources
Summary: This is missing a lot of features, but technically allows working copy allocation. Test Plan: Ran `drydock lease --type working-copy --attributes repositoryID=12`, got a working copy of Phabricator allocated on disk. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D3999
This commit is contained in:
parent
5cbc31644b
commit
b04114f95c
5 changed files with 91 additions and 4 deletions
|
@ -444,6 +444,7 @@ phutil_register_library_map(array(
|
||||||
'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php',
|
'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php',
|
||||||
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
|
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
|
||||||
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
|
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
|
||||||
|
'DrydockWorkingCopyBlueprint' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprint.php',
|
||||||
'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php',
|
'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php',
|
||||||
'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php',
|
'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php',
|
||||||
'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php',
|
'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php',
|
||||||
|
@ -1701,6 +1702,7 @@ phutil_register_library_map(array(
|
||||||
'DrydockResourceViewController' => 'DrydockController',
|
'DrydockResourceViewController' => 'DrydockController',
|
||||||
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
|
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
|
||||||
'DrydockWebrootInterface' => 'DrydockInterface',
|
'DrydockWebrootInterface' => 'DrydockInterface',
|
||||||
|
'DrydockWorkingCopyBlueprint' => 'DrydockBlueprint',
|
||||||
'FeedPublisherWorker' => 'PhabricatorWorker',
|
'FeedPublisherWorker' => 'PhabricatorWorker',
|
||||||
'HarbormasterDAO' => 'PhabricatorLiskDAO',
|
'HarbormasterDAO' => 'PhabricatorLiskDAO',
|
||||||
'HarbormasterObject' => 'HarbormasterDAO',
|
'HarbormasterObject' => 'HarbormasterDAO',
|
||||||
|
|
|
@ -36,6 +36,10 @@ abstract class DrydockBlueprint {
|
||||||
|
|
||||||
$this->log('Acquiring Lease');
|
$this->log('Acquiring Lease');
|
||||||
try {
|
try {
|
||||||
|
$lease->setStatus(DrydockLeaseStatus::STATUS_ACTIVE);
|
||||||
|
$lease->setResourceID($resource->getID());
|
||||||
|
$lease->attachResource($resource);
|
||||||
|
|
||||||
$this->executeAcquireLease($resource, $lease);
|
$this->executeAcquireLease($resource, $lease);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$this->logException($ex);
|
$this->logException($ex);
|
||||||
|
@ -45,8 +49,6 @@ abstract class DrydockBlueprint {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lease->setResourceID($resource->getID());
|
|
||||||
$lease->setStatus(DrydockLeaseStatus::STATUS_ACTIVE);
|
|
||||||
$lease->save();
|
$lease->save();
|
||||||
|
|
||||||
$this->activeResource = null;
|
$this->activeResource = null;
|
||||||
|
|
|
@ -30,6 +30,7 @@ final class DrydockLocalHostBlueprint extends DrydockBlueprint {
|
||||||
|
|
||||||
$resource = $this->newResourceTemplate('localhost');
|
$resource = $this->newResourceTemplate('localhost');
|
||||||
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
|
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
|
||||||
|
$resource->setAttribute('path', $path);
|
||||||
$resource->save();
|
$resource->save();
|
||||||
|
|
||||||
return $resource;
|
return $resource;
|
||||||
|
@ -38,6 +39,15 @@ final class DrydockLocalHostBlueprint extends DrydockBlueprint {
|
||||||
protected function executeAcquireLease(
|
protected function executeAcquireLease(
|
||||||
DrydockResource $resource,
|
DrydockResource $resource,
|
||||||
DrydockLease $lease) {
|
DrydockLease $lease) {
|
||||||
|
|
||||||
|
$lease_id = $lease->getID();
|
||||||
|
|
||||||
|
$cmd = $lease->getInterface('command');
|
||||||
|
$cmd->execx('mkdir %s', $lease_id);
|
||||||
|
|
||||||
|
$lease->setAttribute('path', $resource->getAttribute('path').'/'.$lease_id);
|
||||||
|
$lease->save();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DrydockWorkingCopyBlueprint extends DrydockBlueprint {
|
||||||
|
|
||||||
|
public function isEnabled() {
|
||||||
|
return PhabricatorEnv::getEnvConfig('drydock.localhost.enabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function executeAllocateResource(DrydockLease $lease) {
|
||||||
|
$repository_id = $lease->getAttribute('repositoryID');
|
||||||
|
if (!$repository_id) {
|
||||||
|
throw new Exception(
|
||||||
|
"Lease is missing required 'repositoryID' attribute.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$repository = id(new PhabricatorRepository())->load($repository_id);
|
||||||
|
|
||||||
|
if (!$repository) {
|
||||||
|
throw new Exception(
|
||||||
|
"Repository '{$repository_id}' does not exist!");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($repository->getVersionControlSystem()) {
|
||||||
|
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("Unsupported VCS!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$host_lease = id(new DrydockLease())
|
||||||
|
->setResourceType('host')
|
||||||
|
->waitUntilActive();
|
||||||
|
|
||||||
|
$path = $host_lease->getAttribute('path').'/'.$repository->getCallsign();
|
||||||
|
|
||||||
|
$cmd = $host_lease->getInterface('command');
|
||||||
|
$cmd->execx(
|
||||||
|
'git clone --origin origin %s %s',
|
||||||
|
$repository->getRemoteURI(),
|
||||||
|
$path);
|
||||||
|
|
||||||
|
$resource = $this->newResourceTemplate($repository->getCallsign());
|
||||||
|
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
|
||||||
|
$resource->setAttribute('lease.host', $host_lease->getID());
|
||||||
|
$resource->setAttribute('path', $path);
|
||||||
|
$resource->save();
|
||||||
|
|
||||||
|
return $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function executeAcquireLease(
|
||||||
|
DrydockResource $resource,
|
||||||
|
DrydockLease $lease) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType() {
|
||||||
|
return 'working-copy';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInterface(
|
||||||
|
DrydockResource $resource,
|
||||||
|
DrydockLease $lease,
|
||||||
|
$type) {
|
||||||
|
|
||||||
|
throw new Exception("No interface of type '{$type}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,12 +26,12 @@ final class DrydockLease extends DrydockDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAttribute($key, $value) {
|
public function setAttribute($key, $value) {
|
||||||
$this->attributes[$key] = $value;
|
$this->attributes[strtolower($key)] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAttribute($key, $default = null) {
|
public function getAttribute($key, $default = null) {
|
||||||
return idx($this->attributes, $key, $default);
|
return idx($this->attributes, strtolower($key), $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generatePHID() {
|
public function generatePHID() {
|
||||||
|
@ -150,6 +150,10 @@ final class DrydockLease extends DrydockDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function waitUntilActive() {
|
public function waitUntilActive() {
|
||||||
|
if (!$this->getID()) {
|
||||||
|
$this->queueForActivation();
|
||||||
|
}
|
||||||
|
|
||||||
self::waitForLeases(array($this));
|
self::waitForLeases(array($this));
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue