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 2b58524
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 98 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ jobs:
matrix:
os: [macos-12]
# php: ['8.3', '8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1']
php: ['8.1']
php: ['8.2']
runs-on: ${{matrix.os}}
name: ${{matrix.os}} with ${{matrix.php}}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: '[INSTALL] Install PHP 8.0'
- name: '[INSTALL] Install PHP 8.1'
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: dom, curl, libxml, mbstring, zip, fileinfo
ini-values: error_reporting=E_ALL, max_execution_time=-1, memory_limit=512M
tools: composer:v2
coverage: none
- 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
4 changes: 2 additions & 2 deletions .github/workflows/test-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: '[INSTALL] Install PHP 8.0'
- name: '[INSTALL] Install PHP 8.1'
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: dom, curl, libxml, mbstring, zip, fileinfo
ini-values: error_reporting=E_ALL, max_execution_time=-1, memory_limit=512M
tools: composer:v2
Expand Down
9 changes: 5 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ To get started, you first need to ensure that Homebrew is up to date using the u
brew update
```

Next, you should use Homebrew to install PHP 8.0:
Next, you should use Homebrew to install PHP 8.1 (using `shivammathur/php`):
```shell
brew install [email protected]
brew link [email protected] --force
brew services restart [email protected]
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
brew link [email protected] --force
brew services restart [email protected]
```

Install Valet+ 3.x-dev with composer:
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 2b58524

Please sign in to comment.