1
0
mirror of https://github.com/e107inc/e107.git synced 2025-02-23 08:15:39 +01:00

cPanel Deployer can now bring up and tear down app

Also added more debug messages to cPanel Deployer
This commit is contained in:
Deltik 2018-02-08 03:56:05 -06:00
parent ba9a27787e
commit 4e779d81de
No known key found for this signature in database
GPG Key ID: 1167C5F9C9897637
3 changed files with 66 additions and 3 deletions

@ -1 +1 @@
Subproject commit 02dea0f01778a93f508e173d7a4ec06e4c01872f
Subproject commit b456119f3f276250f66a29ca3f346d3d150456d6

View File

@ -3,6 +3,7 @@
include_once(__DIR__ . "/../cpaneluapi/cpaneluapi.class.php");
define('ACCEPTANCE_TEST_PREFIX', 'acceptance-test-');
define('TARGET_RELPATH', 'public_html/');
class cPanelDeployer
{
@ -90,8 +91,25 @@ class cPanelDeployer
'privileges' => 'ALL PRIVILEGES'
]);
# TODO: Upload software to test
$app_archive = self::archive_app(APP_PATH, $this->run_id);
$app_archive_path = stream_get_meta_data($app_archive)['uri'];
$app_archive_name = basename($app_archive_path);
self::println("Sending archive to cPanel server…");
$cPanel->uapi->post->Fileman
->upload_files(['dir' => TARGET_RELPATH,
'file-1' => new CURLFile($app_archive_path)
]);
self::println("Extracting archive on cPanel server…");
$cPanel->api2->Fileman
->fileop(['op' => 'extract',
'sourcefiles' => TARGET_RELPATH.$app_archive_name,
'destfiles' => '.'
]);
self::println("Deleting archive from cPanel server…");
$cPanel->api2->Fileman
->fileop(['op' => 'unlink',
'sourcefiles' => TARGET_RELPATH.$app_archive_name
]);
return true;
}
@ -122,6 +140,19 @@ class cPanelDeployer
$listdbusers = $cPanel->api2->MysqlFE->listusers()->{'cpanelresult'}->{'data'};
self::prune_mysql_users($listdbusers, $valid_acceptance_test_ids, $cPanel);
$target_files_apiresponse = $cPanel->uapi->Fileman->list_files(['dir' => TARGET_RELPATH]);
$target_files = $target_files_apiresponse->{'data'};
foreach ($target_files as $target_file)
{
$questionable_filename = $target_file->{'file'};
if (substr($questionable_filename, 0, strlen(ACCEPTANCE_TEST_PREFIX)) === ACCEPTANCE_TEST_PREFIX &&
!in_array($questionable_filename, $valid_acceptance_test_ids))
{
self::println("Deleting expired test folder \"".TARGET_RELPATH.$questionable_filename."\"");
$cPanel->api2->Fileman->fileop(['op' => 'unlink', 'sourcefiles' => TARGET_RELPATH.$questionable_filename]);
}
}
}
private static function get_active_acceptance_tests($cPanel, $homedir)
@ -179,6 +210,7 @@ class cPanelDeployer
$questionable_db = substr($db['db'], $offset);
if (!in_array($questionable_db, $ids))
{
self::println("Deleting expired MySQL database \"".$db['db']."\"");
$cPanel->uapi->Mysql->delete_database(['name' => $db['db']]);
}
}
@ -193,8 +225,37 @@ class cPanelDeployer
$questionable_user = substr($user['user'], $offset);
if (!in_array($questionable_user, $ids))
{
self::println("Deleting expired MySQL user \"".$user['user']."\"");
$cPanel->uapi->Mysql->delete_user(['name' => $user['user']]);
}
}
}
private static function archive_app($path, $prefix = '')
{
$tmp_file = tmpfile();
$tmp_file_path = stream_get_meta_data($tmp_file)['uri'];
self::println("Touched temporary archive file; path: ".$tmp_file_path);
$archive = new ZipArchive();
$archive->open($tmp_file_path, ZipArchive::OVERWRITE);
$i = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
self::println("Adding app to temporary archive…");
$path = realpath($path);
foreach ($i as $relpath => $value)
{
$realpath = realpath($relpath);
if (substr($realpath, 0, strlen($path)) === $path)
$relpath = substr($realpath, strlen($path));
if (substr($relpath, -3) === "/.." ||
substr($relpath, -2) === "/." ||
!file_exists($realpath) ||
!is_file($realpath) ||
empty($relpath)) continue;
$relpath = $prefix . $relpath;
$archive->addFile($realpath, $relpath);
}
$archive->close();
return $tmp_file;
}
}

View File

@ -1 +1,3 @@
<?php
define('APP_PATH', realpath(__DIR__."/../e107"));