Skip to content

Commit

Permalink
compatibility with devenv 1.0.5 -> ProcessCompose Socket instead of Port
Browse files Browse the repository at this point in the history
  • Loading branch information
mwr committed May 2, 2024
1 parent 654efe4 commit e539ba4
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 206 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"symfony/finder": "^6.3",
"symfony/process": "^6.3",
"symfony/yaml": "^6.3",
"twig/twig": "^3.0"
"twig/twig": "^3.0",
"ext-curl": "*"
},
"bin": [
"rooter"
Expand Down
404 changes: 244 additions & 160 deletions composer.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions environments/laravel/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ in {
PROJECT_NAME = "${PROJECT_NAME}";
PROJECT_HOST = "${PROJECT_HOST}";

PC_SOCKET_PATH = "${config.env.DEVENV_STATE}/process-compose.sock";

NGINX_PKG_ROOT = pkgs.nginx;
DEVENV_STATE_NGINX = "${config.env.DEVENV_STATE}/nginx";

Expand All @@ -28,11 +30,6 @@ in {
];

process.implementation="process-compose";
process.process-compose={
"port" = config.env.DEVENV_PROCESS_COMPOSE_PORT;
"tui" = "false";
"version" = "0.5";
};

# PHP
languages.php = {
Expand Down
7 changes: 2 additions & 5 deletions environments/magento1/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ in {
PROJECT_NAME = "${PROJECT_NAME}";
PROJECT_HOST = "${PROJECT_HOST}";

PC_SOCKET_PATH = "${config.env.DEVENV_STATE}/process-compose.sock";

NGINX_PKG_ROOT = pkgs.nginx;
DEVENV_STATE_NGINX = "${config.env.DEVENV_STATE}/nginx";

Expand All @@ -28,11 +30,6 @@ in {
];

process.implementation="process-compose";
process.process-compose={
"port" = config.env.DEVENV_PROCESS_COMPOSE_PORT;
"tui" = "false";
"version" = "0.5";
};

# PHP
languages.php = {
Expand Down
7 changes: 2 additions & 5 deletions environments/magento2/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ in {
PROJECT_NAME = "${PROJECT_NAME}";
PROJECT_HOST = "${PROJECT_HOST}";

PC_SOCKET_PATH = "${config.env.DEVENV_STATE}/process-compose.sock";

NGINX_PKG_ROOT = pkgs.nginx;
DEVENV_STATE_NGINX = "${config.env.DEVENV_STATE}/nginx";

Expand Down Expand Up @@ -43,11 +45,6 @@ in {

# process-compose
process.implementation="process-compose";
process.process-compose={
"port" = config.env.DEVENV_PROCESS_COMPOSE_PORT;
"tui" = "false";
"version" = "0.5";
};

# PHP
languages.php = {
Expand Down
9 changes: 3 additions & 6 deletions environments/shopware6/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ in {
PROJECT_NAME = "${PROJECT_NAME}";
PROJECT_HOST = "${PROJECT_HOST}";

PC_SOCKET_PATH = "${config.env.DEVENV_STATE}/process-compose.sock";

NGINX_PKG_ROOT = pkgs.nginx;
DEVENV_STATE_NGINX = "${config.env.DEVENV_STATE}/nginx";

Expand All @@ -22,7 +24,7 @@ in {
STOREFRONT_PROXY_URL = "http://${config.env.PROJECT_HOST}";
MAILER_DSN = lib.mkDefault "smtp://127.0.0.1:${config.env.DEVENV_MAIL_SMTP_PORT}";
DATABASE_URL = lib.mkDefault "mysql://${config.env.DEVENV_DB_USER}:${config.env.DEVENV_DB_PASS}@127.0.0.1:${config.env.DEVENV_DB_PORT}/${config.env.DEVENV_DB_NAME}";
OPENSEARCH_URL="http://127.0.0.1:${config.env.DEVENV_ELASTICSEARCH_PORT}";
OPENSEARCH_URL="http://127.0.0.1:${config.env.DEVENV_OPENSEARCH_PORT}";
};

# PACKAGES
Expand All @@ -36,11 +38,6 @@ in {
];

process.implementation="process-compose";
process.process-compose={
"port" = config.env.DEVENV_PROCESS_COMPOSE_PORT;
"tui" = "false";
"version" = "0.5";
};

# PHP
languages.php = {
Expand Down
7 changes: 2 additions & 5 deletions environments/symfony/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ in {
PROJECT_NAME = "${PROJECT_NAME}";
PROJECT_HOST = "${PROJECT_HOST}";

PC_SOCKET_PATH = "${config.env.DEVENV_STATE}/process-compose.sock";

NGINX_PKG_ROOT = pkgs.nginx;
DEVENV_STATE_NGINX = "${config.env.DEVENV_STATE}/nginx";

Expand All @@ -32,11 +34,6 @@ in {
];

process.implementation="process-compose";
process.process-compose={
"port" = config.env.DEVENV_PROCESS_COMPOSE_PORT;
"tui" = "false";
"version" = "0.5";
};

# PHP
languages.php = {
Expand Down
20 changes: 14 additions & 6 deletions src/Api/ProcessCompose/ProcessComposeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ public function __construct(
/** @throws ApiException|\JsonException */
public function isAlive(array $envData): void
{
if (!array_key_exists('processComposePort', $envData)) {
throw new ApiException('processComposePort not found in envData');
if (!array_key_exists('processComposeSocket', $envData)) {
throw new ApiException(
'processComposeSocket not found in envData, please update the devenv.nix file. ' .
'devenv >= 1.0.5 does not support port based communication anymore.' .
'devenv >= 1.0.5 requires a socket based communication.'
);
}

try {
$processComposePort = $envData['processComposePort'];
$response = $this->client->get("127.0.0.1:$processComposePort/live");
$processComposeSocket = $envData['processComposeSocket'];
$response = $this->client->get(
"http://127.0.0.1/live", ['curl' => [CURLOPT_UNIX_SOCKET_PATH => $processComposeSocket,],]
);
} catch (GuzzleException $e) {
throw new ConnectionException("could not connect to process-compose: {$e->getMessage()}", 0, $e);
}
Expand All @@ -48,8 +54,10 @@ public function isAlive(array $envData): void
public function getProcessList(array $envData): array
{
try {
$processComposePort = $envData['processComposePort'];
$response = $this->client->get("127.0.0.1:$processComposePort/processes");
$processComposeSocket = $envData['processComposeSocket'];
$response = $this->client->get(
"http://127.0.0.1/processes", ['curl' => [CURLOPT_UNIX_SOCKET_PATH => $processComposeSocket,],]
);
} catch (GuzzleException $e) {
throw new ConnectionException("could not connect to process-compose: {$e->getMessage()}", 0, $e);
}
Expand Down
5 changes: 0 additions & 5 deletions src/Cli/Command/Env/CheckEnvPortsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$rows[] = ['Elastic TCP', $elasticsearchTcpPort, $this->portManager->isPortAvailable((int)$elasticsearchTcpPort),];
}

if (isset($envData['processComposePort']) && $envData['processComposePort'] > 0) {
$processComposePort = $envData['processComposePort'];
$rows[] = ['process-compose', $processComposePort, $this->portManager->isPortAvailable((int)$processComposePort),];
}

$table = new Table($output);
$table->setStyle('box');
$table->setHeaders(['name', 'port', 'status']);
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Command/Env/ShowEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'amqpManagementPort',
'elasticsearchPort',
'elasticsearchTcpPort',
'processComposePort',
'processComposeSocket',
];

$table = new Table($output);
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Command/Env/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$pid = $this->processManager->getPidFromFile($this->devenvConfig->getPidFile());

$output->writeln("devenv is running with PID: $pid");
$output->writeln("process-compose is running on port: {$envData['processComposePort']}" );
$output->writeln("process-compose is running with socket: {$envData['processComposeSocket']}" );
if (!$isSuccess) {
$output->writeln(
"<comment>not all processes started correctly, run `rooter env:process-compose` or `rooter env:status` to see details</comment>"
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Output/EnvironmentConfigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function render(array $envData, OutputInterface $output): void
['path', $envData['path']],
['host', $envData['host']],
new TableSeparator(),
['process-compose', $envData['processComposePort']],
['process-compose', $envData['processComposeSocket']],
['httpd', "http:{$envData['httpPort']} (https:{$envData['httpsPort']})"],
['db', $envData['dbPort']],
['redis', $envData['redisPort']],
Expand Down
3 changes: 1 addition & 2 deletions src/Cli/Output/EnvironmentListRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function render(
$project['Redis'] = sprintf("%s", $envData['redisPort'] ?? '');
$project['AMQP'] = $amqpStr;
$project['Elastic'] = sprintf("%s", $envData['elasticsearchPort'] ?? '');
$project['ProcessCompose'] = sprintf("%s", $envData['processComposePort'] ?? '');
}

if (count($projects) > 0) {
Expand All @@ -77,7 +76,7 @@ public function render(

$headers = ['Name', 'Type', 'Host', 'Status'];
if ($showPorts) {
$headers = array_merge($headers, ['HTTP', 'db', 'Mail', 'Redis', 'AMQP', 'Elastic', 'ProcessCompose',]);
$headers = array_merge($headers, ['HTTP', 'db', 'Mail', 'Redis', 'AMQP', 'Elastic',]);
}

$table = new Table($output);
Expand Down
4 changes: 2 additions & 2 deletions src/Manager/PortManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class PortManager
'REDIS' => [6379, 6779],
'AMQP' => [5672, 5999],
'AMQP_MANAGEMENT' => [15672, 19672],
'ELASTICSEARCH' => [9200, 9299],
'ELASTICSEARCH_TCP' => [9300, 9399],
'OPENSEARCH' => [9200, 9299],
'OPENSEARCH_TCP' => [9300, 9399],
'PROCESS_COMPOSE' => [9900, 9999],
];

Expand Down
2 changes: 1 addition & 1 deletion src/Repository/EnvironmentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function register(string $projectName): void
'amqpManagementPort' => getenv('DEVENV_AMQP_MANAGEMENT_PORT') ?? '',
'elasticsearchPort' => getenv('DEVENV_ELASTICSEARCH_PORT') ?? '',
'elasticsearchTcpPort' => getenv('DEVENV_ELASTICSEARCH_TCP_PORT') ?? '',
'processComposePort' => getenv('DEVENV_PROCESS_COMPOSE_PORT') ?? '',
'processComposeSocket' => getenv('PC_SOCKET_PATH') ?? '',
];

$this->save($data);
Expand Down

0 comments on commit e539ba4

Please sign in to comment.