2016-11-19 15:13:32 +07:00
|
|
|
<?php
|
2020-10-08 01:19:39 +02:00
|
|
|
|
2016-11-19 15:13:32 +07:00
|
|
|
namespace Deployer;
|
|
|
|
|
2020-10-08 01:19:39 +02:00
|
|
|
set('composer_action', 'install');
|
|
|
|
|
2020-10-22 00:53:25 +03:00
|
|
|
set('composer_options', '--verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
|
2020-10-08 01:19:39 +02:00
|
|
|
|
2020-10-25 13:01:34 +01:00
|
|
|
/**
|
|
|
|
* Can be used to choose what composer version to install.
|
2020-10-25 14:20:03 +01:00
|
|
|
* Valid values are any that are [listed here](https://getcomposer.org/download/).
|
2020-10-25 13:01:34 +01:00
|
|
|
*
|
|
|
|
* For example:
|
2020-10-25 14:20:03 +01:00
|
|
|
* ```php
|
|
|
|
* set('composer_version', '10.10.15')
|
|
|
|
* ```
|
2020-10-25 13:01:34 +01:00
|
|
|
*/
|
|
|
|
set('composer_version', null);
|
|
|
|
|
2020-11-11 10:09:50 +01:00
|
|
|
/**
|
|
|
|
* Set this variable to stable, snapshot, preview, 1 or 2 to select which Composer channel to use
|
|
|
|
*/
|
|
|
|
set('composer_channel', null);
|
|
|
|
|
2020-10-08 01:19:39 +02:00
|
|
|
set('bin/composer', function () {
|
|
|
|
if (commandExist('composer')) {
|
|
|
|
return '{{bin/php}} ' . locateBinaryPath('composer');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test('[ -f {{deploy_path}}/.dep/composer.phar ]')) {
|
|
|
|
return '{{bin/php}} {{deploy_path}}/.dep/composer.phar';
|
|
|
|
}
|
|
|
|
|
2020-10-25 13:01:34 +01:00
|
|
|
$composerVersionToInstall = get('composer_version', null);
|
2020-11-11 10:09:50 +01:00
|
|
|
$composerChannel = get('composer_channel', null);
|
2020-10-25 13:01:34 +01:00
|
|
|
$installCommand = "cd {{release_path}} && curl -sS https://getcomposer.org/installer | {{bin/php}}";
|
|
|
|
|
|
|
|
if ($composerVersionToInstall) {
|
|
|
|
$installCommand .= " -- --version=" . $composerVersionToInstall;
|
2020-11-11 10:10:57 +01:00
|
|
|
} elseif ($composerChannel) {
|
|
|
|
$composerValidChannels = ['stable', 'snapshot', 'preview', '1', '2',];
|
|
|
|
if (!in_array($composerChannel, $composerValidChannels)) {
|
|
|
|
throw new \Exception('Selected Composer channel ' . $composerChannel . ' is not valid. Valid channels are: ' . implode(', ', $composerValidChannels));
|
2020-11-11 10:09:50 +01:00
|
|
|
}
|
2020-11-11 10:10:57 +01:00
|
|
|
$installCommand .= " -- --" . $composerChannel;
|
2020-11-11 10:09:50 +01:00
|
|
|
}
|
2020-10-25 13:01:34 +01:00
|
|
|
|
|
|
|
run($installCommand);
|
2020-10-08 01:19:39 +02:00
|
|
|
run('mv {{release_path}}/composer.phar {{deploy_path}}/.dep/composer.phar');
|
|
|
|
return '{{bin/php}} {{deploy_path}}/.dep/composer.phar';
|
|
|
|
});
|
|
|
|
|
2016-11-19 15:13:32 +07:00
|
|
|
desc('Installing vendors');
|
|
|
|
task('deploy:vendors', function () {
|
2017-06-05 12:53:01 +07:00
|
|
|
if (!commandExist('unzip')) {
|
2020-04-25 23:00:08 +03:00
|
|
|
warning('To speed up composer installation setup "unzip" command with PHP zip extension.');
|
2017-06-05 12:53:01 +07:00
|
|
|
}
|
2020-10-08 01:19:39 +02:00
|
|
|
run('cd {{release_path}} && {{bin/composer}} {{composer_action}} {{composer_options}} 2>&1');
|
2016-11-19 15:13:32 +07:00
|
|
|
});
|