Skip to content
Permalink
Browse files

Merged branch `release-1.0` to `master`.

  • Loading branch information...
corpsee committed Mar 10, 2019
2 parents 665c382 + a92586e commit 38878621e0aca85fd34250ebb524a7c63b84cdae
@@ -94,7 +94,10 @@ cd /var/www
* Create project by Composer:

```bash
composer create-project php-censor/php-censor php-censor.local --keep-vcs
composer create-project \
php-censor/php-censor \
php-censor.local \
--keep-vcs
```

Or download [latest archive](https://github.com/php-censor/php-censor/releases/latest) from GitHub, unzip it and run
@@ -105,7 +108,8 @@ Or download [latest archive](https://github.com/php-censor/php-censor/releases/l
* Install Beanstalkd Queue (Optional, if you are going to use queue with Worker):

```bash
aptitude install beanstalkd # For deb-based
# For Debian-based
aptitude install beanstalkd
```

* Install PHP Censor itself:
@@ -117,10 +121,29 @@ cd ./php-censor.local
./bin/console php-censor:install
# Non-interactive installation
./bin/console php-censor:install --url='http://php-censor.local' --db-type=pgsql --db-host=localhost --db-pgsql-sslmode=prefer --db-name=php-censor --db-user=php-censor --db-password=php-censor --db-port=null --admin-name=admin --admin-password=admin --admin-email='admin@php-censor.local' --queue-use=1 --queue-host=localhost --queue-name=php-censor
./bin/console php-censor:install \
--url='http://php-censor.local' \
--db-type=pgsql \
--db-host=localhost \
--db-pgsql-sslmode=prefer \
--db-name=php-censor \
--db-user=php-censor \
--db-password=php-censor \
--db-port=null \
--admin-name=admin \
--admin-password=admin \
--admin-email='admin@php-censor.local' \
--queue-use=1 \
--queue-host=localhost \
--queue-port=11300 \
--queue-name=php-censor
# Non-interactive installation with prepared config.yml file
./bin/console php-censor:install --config-from-file=yes --admin-name=admin --admin-password=admin --admin-email='admin@php-censor.local'
./bin/console php-censor:install \
--config-from-file=yes \
--admin-name=admin \
--admin-password=admin \
--admin-email='admin@php-censor.local'
```

* [Add a virtual host to your web server](docs/en/virtual_host.md), pointing to the `public` directory within your new
@@ -36,6 +36,7 @@ php-censor:
queue:
use_queue: true
host: localhost
port: 11300
name: php-censor-queue
lifetime: 600
log:
@@ -40,9 +40,8 @@ For use with an existing project:
```yaml
test:
php_code_sniffer:
standard: "/phpcs.xml" # The leading slash is needed to trigger an external ruleset.
# Without it, PHP Censor looks for a rule named "phpcs.xml"
allowed_errors: -1 # Even a single error will cause the build to fail. -1 = unlimited
standard: "./phpcs.xml"
allowed_errors: -1 # Even a single error will cause the build to fail. -1 = unlimited
allowed_warnings: -1
```

@@ -13,7 +13,8 @@ Pre-Requisites

* You need to install [Beanstalkd](http://kr.github.io/beanstalkd/) - On Ubuntu, this is as simple as running
`apt-get install beanstalkd`.
* [Supervisord](http://supervisord.org/) needs to be installed and running on your server.

* Systemd or [Supervisord](http://supervisord.org/) needs to be installed and running on your server.

Setting up the PHP Censor worker
--------------------------------
@@ -22,20 +23,60 @@ Setting up the PHP Censor worker

Setting up the worker on a new installation of PHP Censor is as simple as entering the appropriate values for your
Beanstalkd server hostname and queue name when running the PHP Censor installer. By default, the installer assumes that
you'll be using beanstalkd on `localhost` and will use the queue name `php-censor-queue`.
you'll be using beanstalkd on `localhost:11300` and will use the queue name `php-censor-queue`.

### On an existing installation

On an existing installation, to set up the worker, you simply need to add the beanstalkd host and queue names directly
into your `config.yml` file. You should add a `worker` key beneath the `php-censor` section, with the properties `host`
and `queue` as outlined in the screenshot below:
into your `config.yml` file like:

```yml
php-censor:
queue:
use_queue: true
host: localhost
port: 11300
name: php-censor-queue
lifetime: 600
```

Running the PHP Censor worker
-----------------------------

Once you've set up PHP Censor to add your jobs to a beanstalkd queue, you need to start the worker so that it can pick
up and run your builds. On most servers, it is best to manage this using supervisord. The following instructions work
on Ubuntu, but will need slight amendments for other distributions.
### By Systemd

You can use systemd to run the worker. Configuration for the unit is almost the same as supervisord's configuration.
Just copy this config to `/etc/systemd/system/php-censor.service` with right permissions, enable
`systemctl enable php-censor.service` and run it by `systemctl start php-censor.service`. If you want to start more
than one worker, just create more unit files with different name and repeat previous steps.

```
[Unit]
Description=PHPCensor Worker
After=network.target
[Service]
Type=simple
ExecStart=/your/path/bin/console php-censor:worker
Restart=always
#Could be changed
User=php-censor
#Could be changed
Group=php-censor
[Install]
WantedBy=multi-user.target
```

And check that it works properly by `systemctl status php-censor.service`

### By Supervisord

Also you can use Supervisord to run the worker. Once you've set up PHP Censor to add your jobs to a beanstalkd queue,
you need to start the worker so that it can pick up and run your builds. On most servers, it is best to manage this
using supervisord. The following instructions work on Ubuntu, but will need slight amendments for other distributions.

Using your preferred text editor, create a file named `php-censor.conf` under `/etc/supervisor/conf.d`. In it, enter
the following config:
@@ -66,6 +107,8 @@ php-censor 19057 0.0 0.9 200244 18720 ? S 03:00 0:01 php /php-c
php-censor 19058 0.0 0.9 200244 18860 ? S 03:00 0:01 php /php-censor/console php-censor:worker
```

### Simple start with nohup (not recommended)

Also you can simple daemonise worker by `nohup`:

```
@@ -75,32 +118,5 @@ nohup /path/to/php-censor/bin/console php-censor:worker &> /var/log/php-censor-w
But keep in mind: it won't restart your worker if it fails and can be inconvenient to manage worker process in contrast
with other solutions. So, it's good for debug purposes or as temporary solution.

Also you can use systemd to run the worker.
Configuration for the unit is almost the same as supervisord's configuration.
Just copy this config to `/etc/systemd/system/php-censor.service` with right permissions, enable
`systemctl enable php-censor.service` and run it by `systemctl start php-censor.service`. If you want to start more
than one worker, just create more unit files with different name and repeat previous steps.

```
[Unit]
Description=PHPCensor Worker
After=network.target
[Service]
Type=simple
ExecStart=/your/path/bin/console php-censor:worker
Restart=always
#Could be changed
User=php-censor
#Could be changed
Group=php-censor
[Install]
WantedBy=multi-user.target
```

And check that it works properly by `systemctl status php-censor.service`

That's it! Now, whenever you create a new build in PHP Censor, it should start building immediately.
@@ -5,6 +5,7 @@
use Exception;
use PDO;
use Pheanstalk\Pheanstalk;
use PHPCensor\Config;
use PHPCensor\Exception\InvalidArgumentException;
use PHPCensor\Store\Factory;
@@ -51,6 +52,7 @@ protected function configure()
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'Admin email')
->addOption('queue-use', null, InputOption::VALUE_OPTIONAL, 'Don\'t ask for queue details', true)
->addOption('queue-host', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue server hostname')
->addOption('queue-port', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue server port')
->addOption('queue-name', null, InputOption::VALUE_OPTIONAL, 'Beanstalkd queue name')
->addOption('config-from-file', null, InputOption::VALUE_OPTIONAL, 'Take config from file and ignore options', false)
@@ -245,7 +247,7 @@ protected function getConfigInformation(InputInterface $input, OutputInterface $
if ($url = $input->getOption('url')) {
$url = $urlValidator($url);
} else {
$question = new Question('Your PHP Censor URL ("http://php-censor.local" for example): ');
$question = new Question('Enter your application URL (default: "http://php-censor.local"): ', 'http://php-censor.local');
$question->setValidator($urlValidator);
$url = $helper->ask($input, $output, $question);
}
@@ -333,6 +335,7 @@ protected function getQueueInformation(InputInterface $input, OutputInterface $o
$skipQueueConfig = [
'use_queue' => false,
'host' => null,
'port' => Pheanstalk::DEFAULT_PORT,
'name' => null,
'lifetime' => 600,
];
@@ -344,13 +347,17 @@ protected function getQueueInformation(InputInterface $input, OutputInterface $o
$queueConfig = [
'use_queue' => true,
'host' => null,
'port' => Pheanstalk::DEFAULT_PORT,
'name' => null,
'lifetime' => 600,
];
$queueConfig['host'] = $input->getOption('queue-host');
$queueConfig['name'] = $input->getOption('queue-name');
$port = $input->getOption('queue-port');
$queueConfig['port'] = $port ? $port : $queueConfig['port'];
if (!$queueConfig['host'] && !$queueConfig['name']) {
/** @var $helper QuestionHelper */
$helper = $this->getHelper('question');
@@ -362,10 +369,13 @@ protected function getQueueInformation(InputInterface $input, OutputInterface $o
return $skipQueueConfig;
}
$questionQueue = new Question('Enter your beanstalkd hostname [localhost]: ', 'localhost');
$questionQueue = new Question('Enter your queue hostname (default: "localhost"): ', 'localhost');
$queueConfig['host'] = $helper->ask($input, $output, $questionQueue);
$questionName = new Question('Enter the queue (tube) name to use [php-censor-queue]: ', 'php-censor-queue');
$questionQueue = new Question('Enter your queue port (default: ' . $queueConfig['port'] . '): ', $queueConfig['port']);
$queueConfig['port'] = $helper->ask($input, $output, $questionQueue);
$questionName = new Question('Enter your queue name (default: "php-censor-queue"): ', 'php-censor-queue');
$queueConfig['name'] = $helper->ask($input, $output, $questionName);
}
@@ -388,37 +398,46 @@ protected function getDatabaseInformation(InputInterface $input, OutputInterface
$helper = $this->getHelperSet()->get('question');
if (!$dbType = $input->getOption('db-type')) {
$questionType = new Question('Please enter your database type (mysql or pgsql): ');
$dbType = $helper->ask($input, $output, $questionType);
$questionType = new Question('Enter your database type ("mysql" or "pgsql"): ');
$dbType = trim(strtolower($helper->ask($input, $output, $questionType)));
}
if (!$dbHost = $input->getOption('db-host')) {
$questionHost = new Question('Please enter your database host (default: localhost): ', 'localhost');
$dbHost = $helper->ask($input, $output, $questionHost);
$questionHost = new Question('Enter your database host (default: "localhost"): ', 'localhost');
$dbHost = trim($helper->ask($input, $output, $questionHost));
}
$defaultPort = 3306;
if ('pgsql' === $dbType) {
$defaultPort = 5432;
}
if (!$dbPort = $input->getOption('db-port')) {
$questionPort = new Question('Please enter your database port (default: empty): ');
$dbPort = $helper->ask($input, $output, $questionPort);
if (!$dbPort = (int)$input->getOption('db-port')) {
$questionPort = new Question(
'Enter your database port (default: ' . $defaultPort . '): ',
$defaultPort
);
$dbPort = (int)$helper->ask($input, $output, $questionPort);
}
if (strtolower($dbType) === "pgsql") {
if ('pgsql' === $dbType) {
$dbPgsqlSslmode = $input->getOption('db-pgsql-sslmode')
?: 'prefer';
}
if (!$dbName = $input->getOption('db-name')) {
$questionDb = new Question('Please enter your database name (default: php-censor-db): ', 'php-censor-db');
$dbName = $helper->ask($input, $output, $questionDb);
$questionDb = new Question('Enter your database name (default: "php-censor-db"): ', 'php-censor-db');
$dbName = trim($helper->ask($input, $output, $questionDb));
}
if (!$dbUser = $input->getOption('db-user')) {
$questionUser = new Question('Please enter your DB user (default: php-censor-user): ', 'php-censor-user');
$dbUser = $helper->ask($input, $output, $questionUser);
$questionUser = new Question('Enter your database user (default: "php-censor-user"): ', 'php-censor-user');
$dbUser = trim($helper->ask($input, $output, $questionUser));
}
if (!$dbPass = $input->getOption('db-password')) {
$questionPass = new Question('Please enter your database password: ');
$questionPass = new Question('Enter your database password: ');
$questionPass->setHidden(true);
$questionPass->setHiddenFallback(false);
$dbPass = $helper->ask($input, $output, $questionPass);
@@ -430,15 +449,11 @@ protected function getDatabaseInformation(InputInterface $input, OutputInterface
]
];
if ($dbType === "pgsql") {
if ($dbType === "pgsql" && !empty($dbPgsqlSslmode)) {
$dbServers[0]['pgsql-sslmode'] = $dbPgsqlSslmode;
}
$dbPort = (integer)$dbPort;
if ($dbPort) {
$dbServers[0]['port'] = $dbPort;
}
$dbServers[0]['port'] = $dbPort;
$db['servers']['read'] = $dbServers;
$db['servers']['write'] = $dbServers;
@@ -3,6 +3,7 @@
namespace PHPCensor\Command;
use Monolog\Logger;
use Pheanstalk\Pheanstalk;
use PHPCensor\Config;
use PHPCensor\Service\BuildService;
use PHPCensor\Worker\BuildWorker;
@@ -72,6 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->logger,
$this->buildService,
$config['host'],
Config::getInstance()->get('php-censor.queue.port', Pheanstalk::DEFAULT_PORT),
$config['name'],
($input->hasOption('periodical-work') && $input->getOption('periodical-work'))
))
@@ -5,7 +5,6 @@
use GuzzleHttp\Client;
use PHPCensor\Builder;
use PHPCensor\Helper\Bitbucket;
use PHPCensor\Helper\Diff;
use PHPCensor\Config;
use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError;
@@ -108,6 +108,29 @@ public function __construct(Builder $builder, Build $build, array $options = [])
$this->builder->logDebug('Plugin options: ' . json_encode($options));
}
/**
* @param string $rawPath
*
* @return string
*/
protected function normalizePath($rawPath)
{
$normalizedPath = $this->builder->interpolate($rawPath);
if ('/' !== substr($rawPath, 0, 1)) {
$normalizedPath = $this->build->getBuildPath() . $normalizedPath;
}
$realPath = realpath($normalizedPath);
return (false !== $realPath)
? rtrim($realPath, '/\\') . '/'
: rtrim(
str_replace('//', '/',
str_replace('/./', '/',$normalizedPath)
), '/\\') . '/';
}
/**
* @return string
*/
Oops, something went wrong.

0 comments on commit 3887862

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.