mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-22 17:33:12 +00:00
plugin installation in docker
This commit is contained in:
@@ -26,4 +26,6 @@ if [ ${XDEBUG_ENABLED} == "1" ]; then
|
||||
docker-php-ext-enable xdebug
|
||||
fi
|
||||
|
||||
./docker/phraseanet/plugins/console init
|
||||
|
||||
bash -e docker-php-entrypoint $@
|
||||
|
@@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
function setupStreaming() {
|
||||
// Turn off output buffering
|
||||
ini_set('output_buffering', 'off');
|
||||
// Turn off PHP output compression
|
||||
ini_set('zlib.output_compression', false);
|
||||
// Disable Apache output buffering/compression
|
||||
if (function_exists('apache_setenv')) {
|
||||
apache_setenv('no-gzip', '1');
|
||||
apache_setenv('dont-vary', '1');
|
||||
}
|
||||
}
|
||||
function runCommand($cmd){
|
||||
echo "+ $cmd\n";
|
||||
system($cmd, $return);
|
||||
if (0 !== $return) {
|
||||
throw new \Exception(sprintf('Error %d: %s', $return, $cmd));
|
||||
}
|
||||
}
|
||||
setupStreaming();
|
||||
|
||||
$plugins = trim(getenv('PHRASEANET_PLUGINS'));
|
||||
if (empty($plugins)) {
|
||||
echo "No plugin to install... SKIP\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
foreach (explode(' ', $plugins) as $key => $plugin) {
|
||||
$plugin = trim($plugin);
|
||||
$repo = $plugin;
|
||||
$branch = 'master';
|
||||
if (1 === preg_match('#^(.+)\(([^)]+)\)$#', $plugin, $matches)) {
|
||||
$repo = $matches[1];
|
||||
$branch = $matches[2];
|
||||
}
|
||||
|
||||
$pluginTmpName = 'plugin' . $key;
|
||||
$pluginPath = './plugin' . $key;
|
||||
if (is_dir($pluginPath)) {
|
||||
echo shell_exec(sprintf('rm -rf %s', $pluginPath));
|
||||
}
|
||||
|
||||
echo sprintf("Installing %s (branch: %s)\n", $repo, $branch);
|
||||
runCommand(sprintf('git clone --single-branch --branch %s %s %s', $branch, $repo, $pluginPath));
|
||||
|
||||
runCommand(sprintf('bin/setup plugins:add %s', $pluginPath));
|
||||
|
||||
echo shell_exec(sprintf('rm -rf %s', $pluginPath));
|
||||
}
|
29
docker/phraseanet/plugins/InitCommand.php
Normal file
29
docker/phraseanet/plugins/InitCommand.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Docker\Plugins\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class InitCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('init')
|
||||
->setDescription('Initialize plugins');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
foreach (glob('./plugins/*') as $dir) {
|
||||
if (is_dir($dir)) {
|
||||
$output->writeln(sprintf('Init <info>%s</info> plugin', basename($dir)));
|
||||
SubCommand::run(sprintf('bin/setup plugin:add %s', $dir));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
64
docker/phraseanet/plugins/InstallCommand.php
Normal file
64
docker/phraseanet/plugins/InstallCommand.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Docker\Plugins\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class InstallCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('install')
|
||||
->setDescription('Install plugins');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$plugins = trim(getenv('PHRASEANET_PLUGINS'));
|
||||
if (empty($plugins)) {
|
||||
$output->writeln('<comment>No plugin to install... SKIP</comment>');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$pluginsDir = 'plugins';
|
||||
if (!is_dir($pluginsDir)) {
|
||||
mkdir($pluginsDir);
|
||||
}
|
||||
|
||||
foreach (explode(' ', $plugins) as $key => $plugin) {
|
||||
$plugin = trim($plugin);
|
||||
$repo = $plugin;
|
||||
$branch = 'master';
|
||||
if (1 === preg_match('#^(.+)\(([^)]+)\)$#', $plugin, $matches)) {
|
||||
$repo = $matches[1];
|
||||
$branch = $matches[2];
|
||||
}
|
||||
|
||||
$pluginPath = './plugin' . $key;
|
||||
if (is_dir($pluginPath)) {
|
||||
SubCommand::run(sprintf('rm -rf %s', $pluginPath));
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('Installing <info>%s</info> (branch: <info>%s</info>)', $repo, $branch));
|
||||
SubCommand::run(sprintf('git clone --single-branch --branch %s %s %s', $branch, $repo, $pluginPath));
|
||||
|
||||
$manifestSrc = $pluginPath.'/manifest.json';
|
||||
if (!file_exists($manifestSrc)) {
|
||||
throw new \Exception(sprintf('Cannot install plugin %s: no manifest.json file found', $plugin));
|
||||
}
|
||||
$pluginDestName = json_decode(file_get_contents($manifestSrc), true)['name'];
|
||||
rename($pluginPath, $pluginsDir.'/'.$pluginDestName);
|
||||
$pluginPath = $pluginsDir.'/'.$pluginDestName;
|
||||
|
||||
if (file_exists($pluginPath.'/composer.json')) {
|
||||
SubCommand::run(sprintf('cd %s && composer install --no-dev', $pluginPath));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
26
docker/phraseanet/plugins/SubCommand.php
Normal file
26
docker/phraseanet/plugins/SubCommand.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Docker\Plugins\Command;
|
||||
|
||||
function setupStreaming()
|
||||
{
|
||||
ini_set('output_buffering', 'off');
|
||||
ini_set('zlib.output_compression', false);
|
||||
if (function_exists('apache_setenv')) {
|
||||
apache_setenv('no-gzip', '1');
|
||||
apache_setenv('dont-vary', '1');
|
||||
}
|
||||
}
|
||||
|
||||
setupStreaming();
|
||||
|
||||
abstract class SubCommand
|
||||
{
|
||||
static public function run($cmd)
|
||||
{
|
||||
system($cmd, $return);
|
||||
if (0 !== $return) {
|
||||
throw new \Exception(sprintf('Error %d: %s', $return, $cmd));
|
||||
}
|
||||
}
|
||||
}
|
17
docker/phraseanet/plugins/console
Executable file
17
docker/phraseanet/plugins/console
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
namespace Alchemy\Docker\Plugins\Command;
|
||||
|
||||
require __DIR__.'/../../../vendor/autoload.php';
|
||||
require __DIR__.'/SubCommand.php';
|
||||
require __DIR__.'/InstallCommand.php';
|
||||
require __DIR__.'/InitCommand.php';
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$application = new Application();
|
||||
|
||||
$application->add(new InstallCommand());
|
||||
$application->add(new InitCommand());
|
||||
|
||||
$application->run();
|
Reference in New Issue
Block a user