deployphp /
deployer
| 1 | <?php |
||
| 2 | /* |
||
| 3 | ### Installing |
||
| 4 | |||
| 5 | ```php |
||
| 6 | // deploy.php |
||
| 7 | |||
| 8 | require 'recipe/rabbit.php'; |
||
| 9 | ``` |
||
| 10 | |||
| 11 | ### Configuration options |
||
| 12 | |||
| 13 | - **rabbit** *(required)*: accepts an *array* with the connection information to [rabbitmq](http://www.rabbitmq.com) server token and team name. |
||
| 14 | |||
| 15 | |||
| 16 | You can provide also other configuration options: |
||
| 17 | |||
| 18 | - *host* - default is localhost |
||
| 19 | - *port* - default is 5672 |
||
| 20 | - *username* - default is *guest* |
||
| 21 | - *password* - default is *guest* |
||
| 22 | - *channel* - no default value, need to be specified via config |
||
| 23 | - *message* - default is **Deployment to '$host' on *$prod* was successful\n$releasePath** |
||
| 24 | - *vhost* - default is |
||
| 25 | |||
| 26 | |||
| 27 | ```php |
||
| 28 | // deploy.php |
||
| 29 | |||
| 30 | set('rabbit', [ |
||
| 31 | 'host' => 'localhost', |
||
| 32 | 'port' => '5672', |
||
| 33 | 'username' => 'guest', |
||
| 34 | 'password' => 'guest', |
||
| 35 | 'channel' => 'notify-channel', |
||
| 36 | 'vhost' => '/my-app' |
||
| 37 | ]); |
||
| 38 | ``` |
||
| 39 | |||
| 40 | ### Suggested Usage |
||
| 41 | |||
| 42 | Since you should only notify RabbitMQ channel of a successful deployment, the `deploy:rabbit` task should be executed right at the end. |
||
| 43 | |||
| 44 | ```php |
||
| 45 | // deploy.php |
||
| 46 | |||
| 47 | before('deploy:end', 'deploy:rabbit'); |
||
| 48 | ``` |
||
| 49 | */ |
||
| 50 | |||
| 51 | namespace Deployer; |
||
| 52 | |||
| 53 | use Deployer\Task\Context; |
||
| 54 | use PhpAmqpLib\Connection\AMQPConnection; |
||
|
0 ignored issues
–
show
|
|||
| 55 | use PhpAmqpLib\Message\AMQPMessage; |
||
|
0 ignored issues
–
show
The type
PhpAmqpLib\Message\AMQPMessage was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 56 | |||
| 57 | desc('Notifies RabbitMQ channel about deployment'); |
||
| 58 | task('deploy:rabbit', function () { |
||
| 59 | |||
| 60 | if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) { |
||
| 61 | throw new \RuntimeException("<comment>Please install php package</comment> <info>videlalvaro/php-amqplib</info> <comment>to use rabbitmq</comment>"); |
||
| 62 | } |
||
| 63 | |||
| 64 | $config = get('rabbit', []); |
||
| 65 | |||
| 66 | if (!isset($config['message'])) { |
||
| 67 | $releasePath = get('release_path'); |
||
| 68 | $host = Context::get()->getHost(); |
||
| 69 | |||
| 70 | $stage = get('stage', false); |
||
| 71 | $stageInfo = ($stage) ? sprintf(' on *%s*', $stage) : ''; |
||
| 72 | |||
| 73 | $message = "Deployment to '%s'%s was successful\n(%s)"; |
||
| 74 | $config['message'] = sprintf( |
||
| 75 | $message, |
||
| 76 | $host->getHostname(), |
||
| 77 | $stageInfo, |
||
| 78 | $releasePath, |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | $defaultConfig = [ |
||
| 83 | 'host' => 'localhost', |
||
| 84 | 'port' => 5672, |
||
| 85 | 'username' => 'guest', |
||
| 86 | 'password' => 'guest', |
||
| 87 | 'vhost' => '/', |
||
| 88 | ]; |
||
| 89 | |||
| 90 | $config = array_merge($defaultConfig, $config); |
||
| 91 | |||
| 92 | if (!is_array($config) || |
||
|
0 ignored issues
–
show
|
|||
| 93 | !isset($config['channel']) || |
||
| 94 | !isset($config['host']) || |
||
| 95 | !isset($config['port']) || |
||
| 96 | !isset($config['username']) || |
||
| 97 | !isset($config['password']) || |
||
| 98 | !isset($config['vhost'])) { |
||
| 99 | throw new \RuntimeException("<comment>Please configure rabbit config:</comment> <info>set('rabbit', array('channel' => 'channel', 'host' => 'host', 'port' => 'port', 'username' => 'username', 'password' => 'password'));</info>"); |
||
| 100 | } |
||
| 101 | |||
| 102 | $connection = new AMQPConnection($config['host'], $config['port'], $config['username'], $config['password'], $config['vhost']); |
||
| 103 | $channel = $connection->channel(); |
||
| 104 | |||
| 105 | $msg = new AMQPMessage($config['message']); |
||
| 106 | $channel->basic_publish($msg, $config['channel'], $config['channel']); |
||
| 107 | |||
| 108 | $channel->close(); |
||
| 109 | $connection->close(); |
||
| 110 | |||
| 111 | }); |
||
| 112 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths