Skip to content

Commit

Permalink
Merge pull request #150 from shlinkio/develop
Browse files Browse the repository at this point in the history
Release 7.0.0
  • Loading branch information
acelaya authored Jan 27, 2022
2 parents be6087f + 24adf66 commit ff600d3
Show file tree
Hide file tree
Showing 132 changed files with 975 additions and 913 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [7.0.0] - 2022-01-27
### Added
* [#143](https://github.com/shlinkio/shlink-installer/issues/143) Reworked how config options are "persisted", switching from regular config to an env var map.

### Changed
* *Nothing*

### Changed
* Dropped support for Symfony 5.
* Updated to infection 0.26, enabling HTML reports.
* Added explicitly enabled composer plugins to composer.json.

### Deprecated
* *Nothing*

### Removed
* Removed everything that was deprecated

### Fixed
* *Nothing*


## [6.3.0] - 2021-12-12
### Added
* [#140](https://github.com/shlinkio/shlink-installer/issues/140) Added support for RabbitMQ options.
Expand Down
72 changes: 28 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,39 @@ Install this tool using [composer](https://getcomposer.org/).

This is the command line tool used by [shlink](https://github.com/shlinkio/shlink) to guide you through the installation process.

The tool expects the active directory to be a valid shlink instance.
The tool expects the working directory to be a valid shlink instance.

There are two main ways to run this tool:
In order to run it, use the built-in CLI entry point.

* Using the built-in CLI entry point.
Run `vendor/bin/shlink-installer` to print all available commands.

Run `vendor/bin/shlink-installer` to print all available commands.

```
Shlink installer
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
install Guides you through the installation process, to get Shlink up and running.
list Lists commands
set-option Allows you to set new values for any config option.
update Helps you import Shlink's config from an older version to a new one.
```
> You can also run `vendor/bin/shlink-install` or `vendor/bin/shlink-update`, which alias the `install` and `update` commands respectively, but this is deprecated and will be removed in next major release.
* Using the `bin/run.php` helper script.
This script returns three functions that can be used to run the install or update, or the whole shlink installer tool.
Just require it and invoke the appropriate function:
```php
<?php
```
Shlink installer
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Display help for a command
install Guides you through the installation process, to get Shlink up and running.
list List commands
set-option Allows you to set new values for any config option.
update Helps you import Shlink's config from an older version to a new one.
```

declare(strict_types=1);
The most important ones are these:

[$install, $update, $installer] = require 'vendor/shlinkio/shlink-installer/bin/run.php';
$install(); // To install
$update(); // To update
$installer(); // To run any supported commands
```
* `install`: Used to set up Shlink from scratch.
* `update`: Used to update an existing Shlink instance. Will allow importing the config, skipping the options that already have a value.
* `set-option`: Allows to set the value for an individual option, in case you want to update it.

## Customize options

Expand Down
18 changes: 0 additions & 18 deletions bin/run.php

This file was deleted.

10 changes: 0 additions & 10 deletions bin/shlink-install

This file was deleted.

9 changes: 7 additions & 2 deletions bin/shlink-installer
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Installer;

[,, $app] = require __DIR__ . '/run.php';
$app();
use Laminas\ServiceManager\ServiceLocatorInterface;
use Symfony\Component\Console\Application;

/** @var ServiceLocatorInterface $container */
$container = include __DIR__ . '/../config/container.php';
$container->get(Application::class)->run();
10 changes: 0 additions & 10 deletions bin/shlink-update

This file was deleted.

18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
"laminas/laminas-servicemanager": "^3.7",
"laminas/laminas-stdlib": "^3.4",
"lstrojny/functional-php": "^1.17",
"shlinkio/shlink-config": "^1.4",
"symfony/console": "^6.0 || ^5.4",
"symfony/filesystem": "^6.0 || ^5.4",
"symfony/process": "^6.0 || ^5.4"
"shlinkio/shlink-config": "^1.5",
"symfony/console": "^6.0",
"symfony/filesystem": "^6.0",
"symfony/process": "^6.0"
},
"require-dev": {
"devster/ubench": "^2.0",
"infection/infection": "^0.25.3",
"infection/infection": "^0.26",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.2",
"phpunit/phpunit": "^9.5",
Expand Down Expand Up @@ -78,11 +78,13 @@
"infect:show": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing and shows applied mutators</>"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true
}
},
"bin": [
"bin/shlink-install",
"bin/shlink-update",
"bin/shlink-installer"
]
}
16 changes: 5 additions & 11 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@
'Database > Password' => Config\Option\Database\DatabasePasswordConfigOption::class,
'Database > Unix socket (Mysql/MariaDB)'
=> Config\Option\Database\DatabaseUnixSocketConfigOption::class,
'Database > Path (SQLite)' => Config\Option\Database\DatabaseSqlitePathConfigOption::class,
Config\Option\Database\DatabaseMySqlOptionsConfigOption::class,
],
'URL SHORTENER' => [
'URL shortener > Short domain' => Config\Option\UrlShortener\ShortDomainHostConfigOption::class,
'URL shortener > Schema' => Config\Option\UrlShortener\ShortDomainSchemaConfigOption::class,
'URL shortener > Validate URLs' => Config\Option\UrlShortener\ValidateUrlConfigOption::class,
'URL shortener > Short codes length' => Config\Option\UrlShortener\ShortCodeLengthOption::class,
'URL shortener > Auto resolve titles'
=> Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class,
Expand Down Expand Up @@ -87,14 +84,14 @@
'QR codes > Default round block size' => Config\Option\QrCode\DefaultRoundBlockSizeConfigOption::class,
],
'APPLICATION' => [
'Delete short URLs > Check threshold' => Config\Option\Visit\CheckVisitsThresholdConfigOption::class,
'Delete short URLs > Visits threshold amount' => Config\Option\Visit\VisitsThresholdConfigOption::class,
'Delete short URLs > Visits threshold' => Config\Option\Visit\VisitsThresholdConfigOption::class,
'Base path' => Config\Option\BasePathConfigOption::class,
'Swoole > Amount of task workers' => Config\Option\Worker\TaskWorkerNumConfigOption::class,
'Swoole > Amount of web workers' => Config\Option\Worker\WebWorkerNumConfigOption::class,
],
'INTEGRATIONS' => [
'Redis servers' => Config\Option\RedisServersConfigOption::class,
'Redis > servers' => Config\Option\Redis\RedisServersConfigOption::class,
'Redis > sentinels service' => Config\Option\Redis\RedisSentinelServiceConfigOption::class,
Config\Option\Mercure\EnableMercureConfigOption::class,
'Mercure > Public URL' => Config\Option\Mercure\MercurePublicUrlConfigOption::class,
'Mercure > Internal URL' => Config\Option\Mercure\MercureInternalUrlConfigOption::class,
Expand All @@ -110,7 +107,6 @@

'factories' => [
Config\Option\BasePathConfigOption::class => InvokableFactory::class,
Config\Option\Visit\CheckVisitsThresholdConfigOption::class => InvokableFactory::class,
Config\Option\Visit\VisitsThresholdConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseDriverConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseNameConfigOption::class => InvokableFactory::class,
Expand All @@ -119,17 +115,15 @@
Config\Option\Database\DatabaseUserConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabasePasswordConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseUnixSocketConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseSqlitePathConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseMySqlOptionsConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\BaseUrlRedirectConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\InvalidShortUrlRedirectConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\Regular404RedirectConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ShortDomainHostConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ShortDomainSchemaConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\ValidateUrlConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AutoResolveTitlesConfigOption::class => InvokableFactory::class,
Config\Option\UrlShortener\AppendExtraPathConfigOption::class => InvokableFactory::class,
Config\Option\RedisServersConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisServersConfigOption::class => InvokableFactory::class,
Config\Option\Redis\RedisSentinelServiceConfigOption::class => InvokableFactory::class,
Config\Option\Visit\VisitsWebhooksConfigOption::class => ConfigAbstractFactory::class,
Config\Option\Visit\OrphanVisitsWebhooksConfigOption::class => ConfigAbstractFactory::class,
Config\Option\Worker\TaskWorkerNumConfigOption::class => ConfigAbstractFactory::class,
Expand Down
5 changes: 3 additions & 2 deletions infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"timeout": 5,
"logs": {
"text": "build/infection/infection-log.txt",
"html": "build/infection/infection-log.html",
"summary": "build/infection/summary-log.txt",
"debug": "build/infection/debug-log.txt",
"badge": {
"branch": "develop"
"stryker": {
"report": "develop"
}
},
"tmpDir": "build/infection/temp",
Expand Down
4 changes: 3 additions & 1 deletion src/Command/AbstractInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Shlinkio\Shlink\Installer\Service\ShlinkAssetsHandler;
use Shlinkio\Shlink\Installer\Service\ShlinkAssetsHandlerInterface;
use Shlinkio\Shlink\Installer\Util\InstallationCommand;
use Shlinkio\Shlink\Installer\Util\Utils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -46,9 +47,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->assetsHandler->importShlinkAssetsFromPath($io, $importedConfig->importPath());
}
$config = $this->configGenerator->generateConfigInteractively($io, $importedConfig->importedConfig());
$configArray = Utils::normalizeAndKeepEnvVarKeys($config->toArray());

// Generate config params files
$this->configWriter->toFile(ShlinkAssetsHandler::GENERATED_CONFIG_PATH, $config->toArray(), false);
$this->configWriter->toFile(ShlinkAssetsHandler::GENERATED_CONFIG_PATH, $configArray, false);
$io->text('<info>Custom configuration properly generated!</info>');
$io->newLine();

Expand Down
2 changes: 1 addition & 1 deletion src/Command/SetOptionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
/** @var ConfigOptionInterface $plugin */
$plugin = $this->optionsManager->get($this->groups[$optionTitle]);
$answers = new PathCollection(include $this->generatedConfigPath);
$answers->setValueInPath($plugin->ask($io, $answers), $plugin->getConfigPath());
$answers->setValueInPath($plugin->ask($io, $answers), [$plugin->getEnvVar()]);
$this->configWriter->toFile($this->generatedConfigPath, $answers->toArray(), false);
$this->assetsHandler->dropCachedConfigIfAny($io);

Expand Down
12 changes: 3 additions & 9 deletions src/Config/ConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function generateConfigInteractively(StyleInterface $io, array $previousC

// FIXME Improve code quality on these nested loops
foreach ($pluginsGroups as $title => $configOptions) {
/** @var ConfigOptionInterface $plugin */
foreach ($configOptions as $configOption => $plugin) {
$optionIsEnabled = $this->enabledOptions === null || contains($this->enabledOptions, $configOption);
$shouldAsk = $optionIsEnabled && $plugin->shouldBeAsked($answers);
Expand All @@ -48,7 +47,7 @@ public function generateConfigInteractively(StyleInterface $io, array $previousC
$io->title($title);
}

$answers->setValueInPath($plugin->ask($io, $answers), $plugin->getConfigPath());
$answers->setValueInPath($plugin->ask($io, $answers), [$plugin->getEnvVar()]);
}
}

Expand All @@ -60,13 +59,8 @@ public function generateConfigInteractively(StyleInterface $io, array $previousC
*/
private function resolveAndSortOptions(): array
{
$dependentPluginSorter = static function (ConfigOptionInterface $left, ConfigOptionInterface $right): int {
if ($left instanceof DependentConfigOptionInterface) {
return $left->getDependentOption() === get_class($right) ? 1 : 0;
}

return 0;
};
$dependentPluginSorter = static fn (ConfigOptionInterface $a, ConfigOptionInterface $b): int =>
$a instanceof DependentConfigOptionInterface && $a->getDependentOption() === get_class($b) ? 1 : 0;
$sortAndResolvePlugins = fn (array $configOptions) => array_combine(
$configOptions,
// Resolve all plugins for every config option, and then sort them
Expand Down
4 changes: 2 additions & 2 deletions src/Config/Option/AbstractSwooleDependentConfigOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Closure;
use Shlinkio\Shlink\Config\Collection\PathCollection;

abstract class AbstractSwooleDependentConfigOption implements ConfigOptionInterface
abstract class AbstractSwooleDependentConfigOption extends BaseConfigOption
{
private Closure $swooleInstalled;

Expand All @@ -18,6 +18,6 @@ public function __construct(callable $swooleInstalled)

public function shouldBeAsked(PathCollection $currentOptions): bool
{
return ($this->swooleInstalled)() && ! $currentOptions->pathExists($this->getConfigPath());
return ($this->swooleInstalled)() && parent::shouldBeAsked($currentOptions);
}
}
24 changes: 0 additions & 24 deletions src/Config/Option/AbstractWithDeprecatedPathConfigOption.php

This file was deleted.

Loading

0 comments on commit ff600d3

Please sign in to comment.