Merge pull request #1969 from acelaya-forks/feature/mountable-data-dir

Feature/mountable data dir
This commit is contained in:
Alejandro Celaya 2024-01-04 08:42:41 +01:00 committed by GitHub
commit f9c9b3d981
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 41 additions and 17 deletions

View file

@ -4,6 +4,24 @@ 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).
## [Unreleased]
### Added
* *Nothing*
### Changed
* [#1968](https://github.com/shlinkio/shlink/issues/1968) Move migrations from `data` to `module/Core`.
* *Nothing*
### Deprecated
* *Nothing*
### Removed
* *Nothing*
### Fixed
* [#1967](https://github.com/shlinkio/shlink/issues/1967) Allow an empty dir to be mounted in `data` when using the docker image.
## [3.7.2] - 2023-12-26
### Added
* *Nothing*

View file

@ -46,17 +46,18 @@ This is a simplified version of the project structure:
```
shlink
├── bin
│ └── cli
│ ├── cli
│ └── [...]
├── config
│ ├── autoload
│ ├── params
│ ├── config.php
│ └── container.php
│ ├── container.php
│ └── [...]
├── data
│ ├── cache
│ ├── locks
│ ├── log
│ ├── migrations
│ └── proxies
├── docs
│ ├── adr
@ -67,6 +68,7 @@ shlink
│ ├── Core
│ └── Rest
├── public
│ └── [...]
├── composer.json
└── README.md
```
@ -75,7 +77,7 @@ The purposes of every folder are:
* `bin`: It contains the CLI tools. The `cli` one is the main entry point to run Shlink from the command line.
* `config`: Contains application-wide configurations, which are later merged with the ones provided by every module.
* `data`: Common runtime-generated git-ignored assets, like logs, caches, etc.
* `data`: Common git-ignored assets, like logs, caches, lock files, GeoLite DB files, etc. It's the only location where Shlink may need to write at runtime.
* `docs`: Any project documentation is stored here, like API spec definitions or architectural decision records.
* `module`: Contains a sub-folder for every module in the project. Modules contain the source code, tests and configurations for every context in the project.
* `public`: Few assets (like `favicon.ico` or `robots.txt`) and the web entry point are stored here. This web entry point is not used when serving the app with RoadRunner or openswoole.

View file

@ -75,7 +75,7 @@
"phpunit/phpunit": "^10.4",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.3.0",
"shlinkio/shlink-test-utils": "^3.8",
"shlinkio/shlink-test-utils": "^3.8.1",
"symfony/var-dumper": "^6.3",
"veewee/composer-run-parallel": "^1.3"
},
@ -116,7 +116,7 @@
],
"cs": "phpcs -s",
"cs:fix": "phpcbf",
"stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/test* module/*/config config docker/config data/migrations --level=8",
"stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/test* module/*/config module/*/migrations config docker/config --level=8",
"test": [
"@parallel test:unit test:db",
"@parallel test:api test:cli"

View file

@ -11,7 +11,9 @@ return [
'base_path' => EnvVars::BASE_PATH->loadFromEnv(''),
'fastroute' => [
FastRouteRouter::CONFIG_CACHE_ENABLED => true,
// Disabling config cache for cli, ensures it's never used for openswoole/RoadRunner, and also that console
// commands don't generate a cache file that's then used by php-fpm web executions
FastRouteRouter::CONFIG_CACHE_ENABLED => PHP_SAPI !== 'cli',
FastRouteRouter::CONFIG_CACHE_FILE => 'data/cache/fastroute_cached_routes.php',
],
],

View file

@ -11,7 +11,7 @@ use Doctrine\Migrations\DependencyFactory;
return (static function () {
$migrationsConfig = [
'migrations_paths' => [
'ShlinkMigrations' => 'data/migrations',
'ShlinkMigrations' => 'module/Core/migrations',
],
'table_storage' => [
'table_name' => 'migrations',

View file

@ -29,10 +29,10 @@ register_shutdown_function(function () use ($httpClient): void {
});
$testHelper->createTestDb(
['bin/cli', 'db:create'],
['bin/cli', 'db:migrate'],
['bin/doctrine', 'orm:schema-tool:drop'],
['bin/doctrine', 'dbal:run-sql'],
createDbCommand: ['bin/cli', 'db:create'],
migrateDbCommand: ['bin/cli', 'db:migrate'],
dropSchemaCommand: ['bin/doctrine', 'orm:schema-tool:drop'],
runSqlCommand: ['bin/doctrine', 'dbal:run-sql'],
);
ApiTest\ApiTestCase::setApiClient($httpClient);
ApiTest\ApiTestCase::setSeedFixturesCallback(fn () => $testHelper->seedFixtures($em, $config['data_fixtures'] ?? []));

View file

@ -9,9 +9,9 @@ use Psr\Container\ContainerInterface;
/** @var ContainerInterface $container */
$container = require __DIR__ . '/../container.php';
$container->get(Helper\TestHelper::class)->createTestDb(
['bin/cli', 'db:create'],
['bin/cli', 'db:migrate'],
['bin/doctrine', 'orm:schema-tool:drop'],
['bin/doctrine', 'dbal:run-sql'],
createDbCommand: ['bin/cli', 'db:create'],
migrateDbCommand: ['bin/cli', 'db:migrate'],
dropSchemaCommand: ['bin/doctrine', 'orm:schema-tool:drop'],
runSqlCommand: ['bin/doctrine', 'dbal:run-sql'],
);
DbTest\DatabaseTestCase::setEntityManager($container->get('em'));

View file

@ -3,6 +3,9 @@ set -e
cd /etc/shlink
# Create data directories if they do not exist. This allows data dir to be mounted as an empty dir if needed
mkdir -p data/cache data/locks data/log data/proxies
flags="--no-interaction --clear-db-cache"
# Skip downloading GeoLite2 db file if the license key env var was not defined or skipping was explicitly set

View file

@ -12,7 +12,6 @@
<!-- Paths to check -->
<file>bin</file>
<file>module</file>
<file>data/migrations</file>
<file>config</file>
<file>docker/config</file>
<file>public/index.php</file>