Skip to content

Commit

Permalink
Proxy mailhog, elasticsearch domains
Browse files Browse the repository at this point in the history
  • Loading branch information
mischabraam committed Jan 31, 2024
1 parent 6d9fc93 commit 25d19dc
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: '[INSTALL] Brew'
run: brew cleanup
- name: '[INSTALL] Composer install'
run: composer install --no-interaction --prefer-dist
run: composer install --no-dev --no-interaction --prefer-dist
- name: '[INSTALL] Valet install'
run: ./valet-plus install

Expand Down
2 changes: 1 addition & 1 deletion cli/ValetPlus/AbstractDockerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function upContainer($name): self
return $this;
}

info("Docker up version {$name}...");
info("Docker up version {$name} (this might take a while)...");
$installPath = $this->getComposeInstallPath($name);
$installDir = $this->getComposeInstallDir($name);

Expand Down
35 changes: 10 additions & 25 deletions cli/ValetPlus/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
use Valet\Brew;
use Valet\CommandLine;
use Valet\Filesystem;
use WeProvide\ValetPlus\Extended\Site;

use function Valet\info;

class Elasticsearch extends AbstractDockerService
{
/** @var string */
protected const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/elasticsearch/elasticsearch.conf';
/** @var string */
protected const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/elasticsearch.conf';

Expand All @@ -29,20 +28,25 @@ class Elasticsearch extends AbstractDockerService

/** @var Brew */
protected $brew;
/** @var Site */
protected $site;

/**
* @param CommandLine $cli
* @param Filesystem $files
* @param Brew $brew
* @param Site $site
*/
public function __construct(
CommandLine $cli,
Filesystem $files,
Brew $brew
Brew $brew,
Site $site
) {
parent::__construct($cli, $files);

$this->brew = $brew;
$this->site = $site;
}

/**
Expand Down Expand Up @@ -242,14 +246,16 @@ public function install($version = self::ES_DEFAULT_VERSION, $tld = 'test')
}

$this->restart($version);
$this->updateDomain($tld);
$this->site->proxyCreate('elasticsearch', 'http://127.0.0.1:9200');
}

/**
* Uninstall all supported versions.
*/
public function uninstall()
{
$this->site->proxyDelete('elasticsearch');

// Remove nginx domain listen file.
$this->files->unlink(static::NGINX_CONFIGURATION_PATH);

Expand Down Expand Up @@ -293,25 +299,4 @@ public function uninstall()
$this->files->rmDirAndContents(BREW_PREFIX . '/etc/opensearch');
}
}

/**
* Set the domain (TLD) to use.
*
* @param $domain
*/
public function updateDomain($domain)
{
$currentVersion = $this->getCurrentVersion();
if ($currentVersion) {
info('Updating elasticsearch domain...');
$this->files->putAsUser(
static::NGINX_CONFIGURATION_PATH,
str_replace(
['VALET_DOMAIN'],
[$domain],
$this->files->get(static::NGINX_CONFIGURATION_STUB)
)
);
}
}
}
37 changes: 13 additions & 24 deletions cli/ValetPlus/Mailhog.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace WeProvide\ValetPlus;

use Illuminate\Container\Container;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Valet\Brew;
use Valet\CommandLine;
use Valet\Configuration;
use Valet\Filesystem;
use WeProvide\ValetPlus\Event\DataEvent;
use WeProvide\ValetPlus\Extended\Site;

use function Valet\info;

Expand All @@ -22,29 +25,34 @@ class Mailhog extends AbstractService
/** @var string */
protected const PHP_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.ini';
/** @var string */
protected const NGINX_CONFIGURATION_STUB = __DIR__ . '/../stubs/mailhog.conf';
/** @var string */
protected const NGINX_CONFIGURATION_PATH = VALET_HOME_PATH . '/Nginx/mailhog.conf';

/** @var EventDispatcher */
protected $eventDispatcher;
/** @var Site */
protected $site;

/**
* @param Configuration $configuration
* @param Brew $brew
* @param Filesystem $files
* @param CommandLine $cli
* @param Site $site
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct(
Configuration $configuration,
Brew $brew,
Filesystem $files,
CommandLine $cli
CommandLine $cli,
Site $site
) {
parent::__construct($configuration, $brew, $files, $cli);

$container = Container::getInstance();
$this->eventDispatcher = $container->get('event_dispatcher');
$this->site = $site;
}

/**
Expand All @@ -64,7 +72,7 @@ public function register()
public function install(string $tld = 'test'): void
{
$this->brew->ensureInstalled(static::SERVICE_NAME);
$this->updateDomain($tld);
$this->site->proxyCreate('mailhog', 'http://127.0.0.1:8025');
$this->setEnabled(static::STATE_ENABLED);
$this->restart();
}
Expand Down Expand Up @@ -111,32 +119,13 @@ public function uninstall(): void
{
$this->stop();
$this->removeEnabled();
$this->site->proxyDelete('mailhog');
$this->brew->uninstallFormula(static::SERVICE_NAME);
$this->files->unlink(BREW_PREFIX . '/var/log/mailhog.log');
// Remove nginx domain listen file.
$this->files->unlink(static::NGINX_CONFIGURATION_PATH);
}

/**
* Set the domain (TLD) to use.
*
* @param $domain
*/
public function updateDomain($domain)
{
if ($this->installed()) {
info('Updating mailhog domain...');
$this->files->putAsUser(
static::NGINX_CONFIGURATION_PATH,
str_replace(
['VALET_DOMAIN'],
[$domain],
$this->files->get(static::NGINX_CONFIGURATION_STUB)
)
);
}
}

/**
* Create php ini files.
*
Expand Down
17 changes: 0 additions & 17 deletions cli/stubs/elasticsearch/elasticsearch.conf

This file was deleted.

17 changes: 0 additions & 17 deletions cli/stubs/mailhog.conf

This file was deleted.

12 changes: 10 additions & 2 deletions cli/valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

use function Valet\info;
use function Valet\table;
use function Valet\warning;
Expand Down Expand Up @@ -265,7 +266,7 @@
*/
$app
->command('mailhog', function (OutputInterface $output, string $mode = null) {
$modes = ['install', 'on', 'enable', 'off', 'disable'];
$modes = ['install', 'on', 'enable', 'off', 'disable', 'uninstall'];

if (!in_array($mode, $modes)) {
throw new Exception('Mode not found. Available modes: ' . implode(', ', $modes));
Expand All @@ -285,11 +286,18 @@
case 'off':
Mailhog::disable();

return;
case 'uninstall':
Mailhog::uninstall();

return;
}

PhpFpm::restart();
Nginx::restart();
})
->descriptions('Enable/disable Mailhog')
->addArgument('mode', InputArgument::REQUIRED, 'Available modes: ' . implode(', ', ['install', 'on', 'enable', 'off', 'disable']));
->addArgument('mode', InputArgument::REQUIRED, 'Available modes: ' . implode(', ', ['install', 'on', 'enable', 'off', 'disable', 'uninstall']));

/**
* Varnish services.
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
}
},
"config": {
"platform-check": false
"platform-check": false,
"allow-plugins": {
"phpro/grumphp-shim": true
}
},
"bin": [
"valet-plus"
Expand All @@ -27,6 +30,7 @@
"laravel/valet": "^4.5"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.8"
"squizlabs/php_codesniffer": "^3.8",
"phpro/grumphp-shim": "^2.4"
}
}
12 changes: 12 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
grumphp:
ascii:
failed: ~
succeeded: ~
tasks:
phpcs:
standard: phpcs.xml
triggered_by:
- php
whitelist_patterns:
- /^cli\/ValetPlus\/(.*)/
- /^cli\/stubs\/drivers\/(.*)/

0 comments on commit 25d19dc

Please sign in to comment.