Skip to content
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

[WIP] Cloud update controller #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/system/modules/!composer/assets/css/backend.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/system/modules/!composer/assets/css/backend.css.map

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/system/modules/!composer/assets/css/backend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,32 @@ table#sql_table {
text-align: right;
}
}

/**
* Cloud update
*/
.cloud_update_container {
margin: 3px 18px 9px;

.cloud_info {
float: right;
margin-left: 10px;
margin-bottom: 10px;
border: 1px dashed #8ab858;
border-radius: 5px;
padding: 10px;

h2 {
color: #8ab858;
}

.sponsors li {
width: 110px;
height: 110px;
}
}

#cloud_errors {
margin-bottom: 10px;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions src/system/modules/!composer/assets/js/cloud_update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
$(window).addEvent('domready', function () {
var output = $('output');
var refreshIndicator = $('refresh-indicator');
var uptime = $('uptime');
var install = $('install');
var errors = $('cloud_errors');
var jobContainer = $('cloud_update_job_container');
var jobId = $('cloud_update_job_id');

var request = new Request.JSON({
url: 'contao/main.php?do=composer',
method: 'get',
onSuccess: function (responseJSON) {
output.innerHTML = responseJSON.output;
uptime.innerHTML = responseJSON.uptime;
errors.innerHTML = responseJSON.errors;

if (responseJSON.jobId) {
jobContainer.setStyle('display', 'block');
jobId.innerHTML = responseJSON.jobId;
}

errors.toggleClass('invisible', !responseJSON.errors);

if (responseJSON.isRunning) {
setTimeout(function () {
run();
}, 10);
} else {
install.setProperty('disabled', 'finished' !== responseJSON.jobStatus);
}
}
});

var timer = 0;

function run() {
timer++;

refreshIndicator.setStyle('width', timer + '%');

if (timer >= 100) {
timer = 0;
request.send();
} else {
setTimeout(function () {
run();
}, 30);
}
}

run();
});
1 change: 1 addition & 0 deletions src/system/modules/!composer/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
'be_composer_client_search' => 'system/modules/!composer/templates',
'be_composer_client_dependency_graph' => 'system/modules/!composer/templates',
'be_composer_client_detached' => 'system/modules/!composer/templates',
'be_composer_client_cloud_update' => 'system/modules/!composer/templates',
)
);
35 changes: 34 additions & 1 deletion src/system/modules/!composer/dca/tl_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@
* Palettes
*/
$GLOBALS['TL_DCA']['tl_settings']['palettes']['__selector__'][] = 'composerExecutionMode';
$GLOBALS['TL_DCA']['tl_settings']['palettes']['__selector__'][] = 'composerUseCloudForUpdate';

$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] .=
';{composer_legend:hide},composerAutoUpdateLibrary,' .
'composerExecutionMode,composerVerbosity,composerRemoveRepositoryTables';
'composerExecutionMode,composerVerbosity,composerRemoveRepositoryTables,composerUseCloudForUpdate';

$GLOBALS['TL_DCA']['tl_settings']['subpalettes']['composerExecutionMode_process'] =
'composerPhpPath,composerProfiling';
$GLOBALS['TL_DCA']['tl_settings']['subpalettes']['composerExecutionMode_detached'] =
'composerPhpPath,composerProfiling';
$GLOBALS['TL_DCA']['tl_settings']['subpalettes']['composerUseCloudForUpdate'] =
'composerCloudEndpoint,composerCloudAuthKey';


/**
Expand Down Expand Up @@ -100,3 +103,33 @@
'tl_class' => 'm12 w50',
),
);
$GLOBALS['TL_DCA']['tl_settings']['fields']['composerUseCloudForUpdate'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_settings']['composerUseCloudForUpdate'],
'inputType' => 'checkbox',
'eval' => array(
'tl_class' => 'm12 clr',
'submitOnChange' => true
),
'save_callback' => [function($v) {
$automator = new \Automator();
$automator->purgeTempFolder();
return $v;
}]
);
$GLOBALS['TL_DCA']['tl_settings']['fields']['composerCloudEndpoint'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_settings']['composerCloudEndpoint'],
'inputType' => 'text',
'eval' => array(
'tl_class' => 'w50',
'rgxp' => 'url',
'mandatory' => true,
),
);

$GLOBALS['TL_DCA']['tl_settings']['fields']['composerCloudAuthKey'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_settings']['composerCloudAuthKey'],
'inputType' => 'text',
'eval' => array(
'tl_class' => 'w50'
),
);
77 changes: 77 additions & 0 deletions src/system/modules/!composer/languages/en/composer_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$GLOBALS['TL_LANG']['composer_client']['editor_headline'] = 'Experts mode';
$GLOBALS['TL_LANG']['composer_client']['dependency_graph_headline'] = 'Dependency graph';
$GLOBALS['TL_LANG']['composer_client']['detached'] = 'Package update';
$GLOBALS['TL_LANG']['composer_client']['cloud_update'] = 'Cloud update (Beta version!)';

/**
* References
Expand Down Expand Up @@ -42,6 +43,80 @@
$GLOBALS['TL_LANG']['composer_client']['download_impossible'] =
'Downloading is impossible, please either enable the PHP zip extension or ensure proc_open() may run unzip.';

/**
* Cloud update
*/
$GLOBALS['TL_LANG']['composer_client']['cloud_update_explanation'] = <<<CLOUDUPDATEEXPLANATION
<h2>Welcome to the Beta program of the Cloud Update</h2>

<p>Composer is a really great package manager. A lot of developers that develop their
projects in different programming languages even call it one of the best.</p>

<p>Composer itself is great. However, the language it is written in - PHP - is
not really a great language for the tasks of a package manager. This is probably
one reasons why PHP requires so much memory when running Composer. Depending on
the amount and constellation of your dependencies, it might very well happen that
Composer requires 1.5 GB RAM to resolve them. Dependency resolving is a very
complex task.</p>

<p>Memory, however, is usually not a problem because package managers are not meant to
be run on web servers and on your local machine you should have more than 1.5 GB
RAM available.</p>

<p>This is obvously not true for our integration that runs directly on your webserver.</p>

<p>Composer works in such a way that it is analyzing the content of your "composer.json"
file. It contains the packages that you would like to install and their respective
versions. Basically, the GUI you see in the back end when you search for packages
and add or remove them, just writes to that "composer.json" in the background for
you. When you then update, Composer takes that "composer.json" and tries to resolve
it to a set of packages and versions that work together. This is the hard part
that uses a lot of memory. If Composer finds a possible combination, it will write
the exact versions of all packages into a "composer.lock" file and then install
the packages from there. You see, installing has never been a problem! Resolving
the dependencies is.</p>

<p>The Composer Resolver Cloud service tries to bring the dependency resolving process
into the cloud. In other words, you push the "composer.json" to the cloud and it
answers with either "does not work" or the "composer.lock" with a combination of
packages that works. You should then be able to install the packages without running
into any memory limits. Of course, installing the dependencies needs some RAM
too but a regular web hosting should provide enough for it.</p>

<h3>Important side notes:</h3>

<p>RAM is very expensive. You don't pay for it on
your webserver but we pay for it to run the cloud for you. As of today, we have
no idea how much resources are needed or how well this is going to work out.
Maybe there will be too many Contao users that use the cloud and we won't be able
to afford the required cloud resources. This is a beta service and it might
disappear again. <strong>Please, do not</strong> use the cloud
service if you don't need to. If your server provides enough resources to run
the update normally, use it! Thank you.</p>

<p>I put over 100 hours of work into this project because I want to help the people and so I did it for free.<br>Please bear that in mind
when you are about to report issues on <a href="https://github.com/contao-community-alliance/composer-client/issues" target="_blank">GitHub</a>.</p>

<p>Yanick, terminal42 gmbh</p>

CLOUDUPDATEEXPLANATION;

$GLOBALS['TL_LANG']['composer_client']['cloud_info_headline'] = 'Current Cloud information';
$GLOBALS['TL_LANG']['composer_client']['cloud_info']['approxWaitingTimeHuman'] = 'Current estimated waiting time';
$GLOBALS['TL_LANG']['composer_client']['cloud_info']['numberOfJobsInQueue'] = 'Current # of jobs queued';
$GLOBALS['TL_LANG']['composer_client']['cloud_info']['numberOfWorkers'] = 'Current # of workers running';
$GLOBALS['TL_LANG']['composer_client']['cloud_update_exception'] = 'Unfortunately, a (yet) unknown error occurred. Please check your "system/logs/composer_cloud_update_error.log" file and report it to us so we can try to improve and find a specific human-readable error message for this type of error.';
$GLOBALS['TL_LANG']['composer_client']['cloud_sponsors_headline'] = 'Sponsors';
$GLOBALS['TL_LANG']['composer_client']['cloud_sponsors_link_title'] = 'Visit the website of %s';

/**
* Cloud update errors
*/
$GLOBALS['TL_LANG']['composer_client']['cloud_update_errors']['url_malformed'] = 'The URL you entered in the back end seems to be malformed!';
$GLOBALS['TL_LANG']['composer_client']['cloud_update_errors']['could_not_resolve_host'] = 'The URL you entered in the back end could not be resolved to a valid host name!';
$GLOBALS['TL_LANG']['composer_client']['cloud_update_errors']['connection_refused'] = 'The URL you entered in the back end could not be connected to. Make sure the cloud endpoint is reachable from your webserver and up and running!';
$GLOBALS['TL_LANG']['composer_client']['cloud_update_errors']['operation_timed_out'] = 'The connection operation timed out. Are you sure the Cloud servers are reachable?';

/**
* Migration wizard
*/
Expand Down Expand Up @@ -339,3 +414,5 @@
$GLOBALS['TL_LANG']['composer_client']['save'] = 'Save';
$GLOBALS['TL_LANG']['composer_client']['close'] = 'Close';
$GLOBALS['TL_LANG']['composer_client']['terminate'] = 'Terminate';
$GLOBALS['TL_LANG']['composer_client']['cloud_confirm'] = 'Launch Cloud resolving now';
$GLOBALS['TL_LANG']['composer_client']['install'] = 'Install packages now';
13 changes: 12 additions & 1 deletion src/system/modules/!composer/languages/en/tl_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
'The old ER2 repository client tables will not be removed by the composer client database update tool, ' .
'until you enable this checkbox.'
);

$GLOBALS['TL_LANG']['tl_settings']['composerUseCloudForUpdate'] = array(
'Use the Cloud to resolve dependencies (Beta version!)',
'If your server does not provide enough resources to resolve package dependencies, you can let the cloud handle it for you.'
);
$GLOBALS['TL_LANG']['tl_settings']['composerCloudEndpoint'] = array(
'Cloud endpoint',
'Here you can configure the cloud endpoint.'
);
$GLOBALS['TL_LANG']['tl_settings']['composerCloudAuthKey'] = array(
'Cloud auth key',
'If the cloud endpoint is protected, enter your auth key here.'
);

/**
* Reference
Expand Down
19 changes: 19 additions & 0 deletions src/system/modules/!composer/src/ClientBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Composer\IO\BufferIO;
use Composer\Package\RootPackage;
use ContaoCommunityAlliance\Contao\Composer\Controller\ClearComposerCacheController;
use ContaoCommunityAlliance\Contao\Composer\Controller\CloudUpdateController;
use ContaoCommunityAlliance\Contao\Composer\Controller\DependencyGraphController;
use ContaoCommunityAlliance\Contao\Composer\Controller\DetachedController;
use ContaoCommunityAlliance\Contao\Composer\Controller\DetailsController;
Expand Down Expand Up @@ -109,6 +110,24 @@ public function generate()
return $template->parse();
}

$cloudTmpFile = TL_ROOT . '/' . CloudUpdateController::TMP_FILE_PATHNAME;

if ($GLOBALS['TL_CONFIG']['composerUseCloudForUpdate'] && file_exists($cloudTmpFile)) {
$config = json_decode(file_get_contents($cloudTmpFile), true);
if (!$config['writtenLock']) {
$this->loadComposer();
$controller = new CloudUpdateController();
$controller->setConfigPathname($this->configPathname);
$controller->setComposer($this->composer);
return $controller->handle($input);
} else {
// Make sure we're redirected to the update view
if (strpos(\Environment::get('request'), 'update=packages') === false) {
$this->redirect('contao/main.php?do=composer&update=packages');
}
}
}

if (file_exists(TL_ROOT . '/' . DetachedController::PID_FILE_PATHNAME)) {
$controller = new DetachedController();
$output = $controller->handle($input);
Expand Down
Loading