From 377861c5f1e746e3f4353fad1f527dc2417cbc3b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 2 Jan 2024 17:55:23 +0100 Subject: [PATCH 1/4] Move migrations to module/Core --- .dockerignore | 10 +--------- CONTRIBUTING.md | 5 ----- composer.json | 2 +- config/cli-config.php | 2 +- config/test/bootstrap_api_tests.php | 8 ++++---- config/test/bootstrap_db_tests.php | 8 ++++---- .../Core}/migrations/Version20160819142757.php | 0 .../Core}/migrations/Version20160820191203.php | 0 .../Core}/migrations/Version20171021093246.php | 0 .../Core}/migrations/Version20171022064541.php | 0 .../Core}/migrations/Version20180801183328.php | 0 .../Core}/migrations/Version20180913205455.php | 0 .../Core}/migrations/Version20180915110857.php | 0 .../Core}/migrations/Version20181020060559.php | 0 .../Core}/migrations/Version20181020065148.php | 0 .../Core}/migrations/Version20181110175521.php | 0 .../Core}/migrations/Version20190824075137.php | 0 .../Core}/migrations/Version20190930165521.php | 0 .../Core}/migrations/Version20191001201532.php | 0 .../Core}/migrations/Version20191020074522.php | 0 .../Core}/migrations/Version20200105165647.php | 0 .../Core}/migrations/Version20200106215144.php | 0 .../Core}/migrations/Version20200110182849.php | 0 .../Core}/migrations/Version20200323190014.php | 0 .../Core}/migrations/Version20200503170404.php | 0 .../Core}/migrations/Version20201023090929.php | 0 .../Core}/migrations/Version20201102113208.php | 0 .../Core}/migrations/Version20210102174433.php | 0 .../Core}/migrations/Version20210118153932.php | 0 .../Core}/migrations/Version20210202181026.php | 0 .../Core}/migrations/Version20210207100807.php | 0 .../Core}/migrations/Version20210306165711.php | 0 .../Core}/migrations/Version20210522051601.php | 0 .../Core}/migrations/Version20210522124633.php | 0 .../Core}/migrations/Version20210720143824.php | 0 .../Core}/migrations/Version20211002072605.php | 0 .../Core}/migrations/Version20220110113313.php | 0 .../Core}/migrations/Version20230103105343.php | 0 .../Core}/migrations/Version20230130090946.php | 0 .../Core}/migrations/Version20230211171904.php | 0 .../Core}/migrations/Version20230303164233.php | 0 phpcs.xml | 1 - 42 files changed, 11 insertions(+), 25 deletions(-) rename {data => module/Core}/migrations/Version20160819142757.php (100%) rename {data => module/Core}/migrations/Version20160820191203.php (100%) rename {data => module/Core}/migrations/Version20171021093246.php (100%) rename {data => module/Core}/migrations/Version20171022064541.php (100%) rename {data => module/Core}/migrations/Version20180801183328.php (100%) rename {data => module/Core}/migrations/Version20180913205455.php (100%) rename {data => module/Core}/migrations/Version20180915110857.php (100%) rename {data => module/Core}/migrations/Version20181020060559.php (100%) rename {data => module/Core}/migrations/Version20181020065148.php (100%) rename {data => module/Core}/migrations/Version20181110175521.php (100%) rename {data => module/Core}/migrations/Version20190824075137.php (100%) rename {data => module/Core}/migrations/Version20190930165521.php (100%) rename {data => module/Core}/migrations/Version20191001201532.php (100%) rename {data => module/Core}/migrations/Version20191020074522.php (100%) rename {data => module/Core}/migrations/Version20200105165647.php (100%) rename {data => module/Core}/migrations/Version20200106215144.php (100%) rename {data => module/Core}/migrations/Version20200110182849.php (100%) rename {data => module/Core}/migrations/Version20200323190014.php (100%) rename {data => module/Core}/migrations/Version20200503170404.php (100%) rename {data => module/Core}/migrations/Version20201023090929.php (100%) rename {data => module/Core}/migrations/Version20201102113208.php (100%) rename {data => module/Core}/migrations/Version20210102174433.php (100%) rename {data => module/Core}/migrations/Version20210118153932.php (100%) rename {data => module/Core}/migrations/Version20210202181026.php (100%) rename {data => module/Core}/migrations/Version20210207100807.php (100%) rename {data => module/Core}/migrations/Version20210306165711.php (100%) rename {data => module/Core}/migrations/Version20210522051601.php (100%) rename {data => module/Core}/migrations/Version20210522124633.php (100%) rename {data => module/Core}/migrations/Version20210720143824.php (100%) rename {data => module/Core}/migrations/Version20211002072605.php (100%) rename {data => module/Core}/migrations/Version20220110113313.php (100%) rename {data => module/Core}/migrations/Version20230103105343.php (100%) rename {data => module/Core}/migrations/Version20230130090946.php (100%) rename {data => module/Core}/migrations/Version20230211171904.php (100%) rename {data => module/Core}/migrations/Version20230303164233.php (100%) diff --git a/.dockerignore b/.dockerignore index beca6373a..a98cc4bbd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,14 +1,6 @@ bin/rr config/autoload/*local* -data/infra -data/cache/* -data/log/* -data/locks/* -data/proxies/* -data/migrations_template.txt -data/GeoLite2-City* -data/database.sqlite -data/shlink-tests.db +data/* CHANGELOG.md CONTRIBUTING.md UPGRADE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d21c577ad..400837212 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,11 +53,6 @@ shlink │ ├── config.php │ └── container.php ├── data -│ ├── cache -│ ├── locks -│ ├── log -│ ├── migrations -│ └── proxies ├── docs │ ├── adr │ ├── async-api diff --git a/composer.json b/composer.json index b9eef16c8..26bfa8388 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/config/cli-config.php b/config/cli-config.php index 573488245..da09be7b4 100644 --- a/config/cli-config.php +++ b/config/cli-config.php @@ -11,7 +11,7 @@ return (static function () { $migrationsConfig = [ 'migrations_paths' => [ - 'ShlinkMigrations' => 'data/migrations', + 'ShlinkMigrations' => 'module/Core/migrations', ], 'table_storage' => [ 'table_name' => 'migrations', diff --git a/config/test/bootstrap_api_tests.php b/config/test/bootstrap_api_tests.php index 2653b552b..b82e5bc65 100644 --- a/config/test/bootstrap_api_tests.php +++ b/config/test/bootstrap_api_tests.php @@ -29,10 +29,10 @@ }); $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'] ?? [])); diff --git a/config/test/bootstrap_db_tests.php b/config/test/bootstrap_db_tests.php index 5aa8ea511..2731804f7 100644 --- a/config/test/bootstrap_db_tests.php +++ b/config/test/bootstrap_db_tests.php @@ -9,9 +9,9 @@ /** @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')); diff --git a/data/migrations/Version20160819142757.php b/module/Core/migrations/Version20160819142757.php similarity index 100% rename from data/migrations/Version20160819142757.php rename to module/Core/migrations/Version20160819142757.php diff --git a/data/migrations/Version20160820191203.php b/module/Core/migrations/Version20160820191203.php similarity index 100% rename from data/migrations/Version20160820191203.php rename to module/Core/migrations/Version20160820191203.php diff --git a/data/migrations/Version20171021093246.php b/module/Core/migrations/Version20171021093246.php similarity index 100% rename from data/migrations/Version20171021093246.php rename to module/Core/migrations/Version20171021093246.php diff --git a/data/migrations/Version20171022064541.php b/module/Core/migrations/Version20171022064541.php similarity index 100% rename from data/migrations/Version20171022064541.php rename to module/Core/migrations/Version20171022064541.php diff --git a/data/migrations/Version20180801183328.php b/module/Core/migrations/Version20180801183328.php similarity index 100% rename from data/migrations/Version20180801183328.php rename to module/Core/migrations/Version20180801183328.php diff --git a/data/migrations/Version20180913205455.php b/module/Core/migrations/Version20180913205455.php similarity index 100% rename from data/migrations/Version20180913205455.php rename to module/Core/migrations/Version20180913205455.php diff --git a/data/migrations/Version20180915110857.php b/module/Core/migrations/Version20180915110857.php similarity index 100% rename from data/migrations/Version20180915110857.php rename to module/Core/migrations/Version20180915110857.php diff --git a/data/migrations/Version20181020060559.php b/module/Core/migrations/Version20181020060559.php similarity index 100% rename from data/migrations/Version20181020060559.php rename to module/Core/migrations/Version20181020060559.php diff --git a/data/migrations/Version20181020065148.php b/module/Core/migrations/Version20181020065148.php similarity index 100% rename from data/migrations/Version20181020065148.php rename to module/Core/migrations/Version20181020065148.php diff --git a/data/migrations/Version20181110175521.php b/module/Core/migrations/Version20181110175521.php similarity index 100% rename from data/migrations/Version20181110175521.php rename to module/Core/migrations/Version20181110175521.php diff --git a/data/migrations/Version20190824075137.php b/module/Core/migrations/Version20190824075137.php similarity index 100% rename from data/migrations/Version20190824075137.php rename to module/Core/migrations/Version20190824075137.php diff --git a/data/migrations/Version20190930165521.php b/module/Core/migrations/Version20190930165521.php similarity index 100% rename from data/migrations/Version20190930165521.php rename to module/Core/migrations/Version20190930165521.php diff --git a/data/migrations/Version20191001201532.php b/module/Core/migrations/Version20191001201532.php similarity index 100% rename from data/migrations/Version20191001201532.php rename to module/Core/migrations/Version20191001201532.php diff --git a/data/migrations/Version20191020074522.php b/module/Core/migrations/Version20191020074522.php similarity index 100% rename from data/migrations/Version20191020074522.php rename to module/Core/migrations/Version20191020074522.php diff --git a/data/migrations/Version20200105165647.php b/module/Core/migrations/Version20200105165647.php similarity index 100% rename from data/migrations/Version20200105165647.php rename to module/Core/migrations/Version20200105165647.php diff --git a/data/migrations/Version20200106215144.php b/module/Core/migrations/Version20200106215144.php similarity index 100% rename from data/migrations/Version20200106215144.php rename to module/Core/migrations/Version20200106215144.php diff --git a/data/migrations/Version20200110182849.php b/module/Core/migrations/Version20200110182849.php similarity index 100% rename from data/migrations/Version20200110182849.php rename to module/Core/migrations/Version20200110182849.php diff --git a/data/migrations/Version20200323190014.php b/module/Core/migrations/Version20200323190014.php similarity index 100% rename from data/migrations/Version20200323190014.php rename to module/Core/migrations/Version20200323190014.php diff --git a/data/migrations/Version20200503170404.php b/module/Core/migrations/Version20200503170404.php similarity index 100% rename from data/migrations/Version20200503170404.php rename to module/Core/migrations/Version20200503170404.php diff --git a/data/migrations/Version20201023090929.php b/module/Core/migrations/Version20201023090929.php similarity index 100% rename from data/migrations/Version20201023090929.php rename to module/Core/migrations/Version20201023090929.php diff --git a/data/migrations/Version20201102113208.php b/module/Core/migrations/Version20201102113208.php similarity index 100% rename from data/migrations/Version20201102113208.php rename to module/Core/migrations/Version20201102113208.php diff --git a/data/migrations/Version20210102174433.php b/module/Core/migrations/Version20210102174433.php similarity index 100% rename from data/migrations/Version20210102174433.php rename to module/Core/migrations/Version20210102174433.php diff --git a/data/migrations/Version20210118153932.php b/module/Core/migrations/Version20210118153932.php similarity index 100% rename from data/migrations/Version20210118153932.php rename to module/Core/migrations/Version20210118153932.php diff --git a/data/migrations/Version20210202181026.php b/module/Core/migrations/Version20210202181026.php similarity index 100% rename from data/migrations/Version20210202181026.php rename to module/Core/migrations/Version20210202181026.php diff --git a/data/migrations/Version20210207100807.php b/module/Core/migrations/Version20210207100807.php similarity index 100% rename from data/migrations/Version20210207100807.php rename to module/Core/migrations/Version20210207100807.php diff --git a/data/migrations/Version20210306165711.php b/module/Core/migrations/Version20210306165711.php similarity index 100% rename from data/migrations/Version20210306165711.php rename to module/Core/migrations/Version20210306165711.php diff --git a/data/migrations/Version20210522051601.php b/module/Core/migrations/Version20210522051601.php similarity index 100% rename from data/migrations/Version20210522051601.php rename to module/Core/migrations/Version20210522051601.php diff --git a/data/migrations/Version20210522124633.php b/module/Core/migrations/Version20210522124633.php similarity index 100% rename from data/migrations/Version20210522124633.php rename to module/Core/migrations/Version20210522124633.php diff --git a/data/migrations/Version20210720143824.php b/module/Core/migrations/Version20210720143824.php similarity index 100% rename from data/migrations/Version20210720143824.php rename to module/Core/migrations/Version20210720143824.php diff --git a/data/migrations/Version20211002072605.php b/module/Core/migrations/Version20211002072605.php similarity index 100% rename from data/migrations/Version20211002072605.php rename to module/Core/migrations/Version20211002072605.php diff --git a/data/migrations/Version20220110113313.php b/module/Core/migrations/Version20220110113313.php similarity index 100% rename from data/migrations/Version20220110113313.php rename to module/Core/migrations/Version20220110113313.php diff --git a/data/migrations/Version20230103105343.php b/module/Core/migrations/Version20230103105343.php similarity index 100% rename from data/migrations/Version20230103105343.php rename to module/Core/migrations/Version20230103105343.php diff --git a/data/migrations/Version20230130090946.php b/module/Core/migrations/Version20230130090946.php similarity index 100% rename from data/migrations/Version20230130090946.php rename to module/Core/migrations/Version20230130090946.php diff --git a/data/migrations/Version20230211171904.php b/module/Core/migrations/Version20230211171904.php similarity index 100% rename from data/migrations/Version20230211171904.php rename to module/Core/migrations/Version20230211171904.php diff --git a/data/migrations/Version20230303164233.php b/module/Core/migrations/Version20230303164233.php similarity index 100% rename from data/migrations/Version20230303164233.php rename to module/Core/migrations/Version20230303164233.php diff --git a/phpcs.xml b/phpcs.xml index b79d7b404..957d5dbca 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -12,7 +12,6 @@ bin module - data/migrations config docker/config public/index.php From 9bdbb594018b5abb0125c97bba2b54a666af6e44 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 3 Jan 2024 10:08:03 +0100 Subject: [PATCH 2/4] Update shlinkio/shlink-testing-utils --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 26bfa8388..7c336b05d 100644 --- a/composer.json +++ b/composer.json @@ -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" }, From 554b9487751dc94de7d97080d91783f84dc922da Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 3 Jan 2024 19:22:33 +0100 Subject: [PATCH 3/4] Create data directories in docker entry point if they don't exist --- .dockerignore | 10 +++++++++- CONTRIBUTING.md | 10 +++++++--- config/autoload/router.global.php | 4 +++- docker/docker-entrypoint.sh | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index a98cc4bbd..beca6373a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,14 @@ bin/rr config/autoload/*local* -data/* +data/infra +data/cache/* +data/log/* +data/locks/* +data/proxies/* +data/migrations_template.txt +data/GeoLite2-City* +data/database.sqlite +data/shlink-tests.db CHANGELOG.md CONTRIBUTING.md UPGRADE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 400837212..4167569eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,13 +46,16 @@ This is a simplified version of the project structure: ``` shlink ├── bin -│ └── cli +│ ├── cli +│ └── [...] ├── config │ ├── autoload │ ├── params │ ├── config.php -│ └── container.php +│ ├── container.php +│ └── [...] ├── data +│ └── [...] ├── docs │ ├── adr │ ├── async-api @@ -62,6 +65,7 @@ shlink │ ├── Core │ └── Rest ├── public +│ └── [...] ├── composer.json └── README.md ``` @@ -70,7 +74,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. diff --git a/config/autoload/router.global.php b/config/autoload/router.global.php index 8b5e856e9..831a7523d 100644 --- a/config/autoload/router.global.php +++ b/config/autoload/router.global.php @@ -11,7 +11,9 @@ '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', ], ], diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 799feb809..6c95bee24 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -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 From e7b876f4e6d04669d9fa9c44ae324cd81865d4b1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 3 Jan 2024 19:39:19 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 18 ++++++++++++++++++ CONTRIBUTING.md | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 736daf3be..51b0d55b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4167569eb..4b2f36d2b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,7 +55,10 @@ shlink │ ├── container.php │ └── [...] ├── data -│ └── [...] +│ ├── cache +│ ├── locks +│ ├── log +│ └── proxies ├── docs │ ├── adr │ ├── async-api