From 554b9487751dc94de7d97080d91783f84dc922da Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 3 Jan 2024 19:22:33 +0100 Subject: [PATCH] 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 a98cc4bb..beca6373 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 40083721..4167569e 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 8b5e856e..831a7523 100644 --- a/config/autoload/router.global.php +++ b/config/autoload/router.global.php @@ -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', ], ], diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 799feb80..6c95bee2 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