From 45e108d21e0d9302d7cf8128b19bec94c379e680 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 24 Oct 2024 09:59:13 +0200 Subject: [PATCH] Load dev env as a PHP array instead of an env file --- .dockerignore | 2 +- .gitignore | 1 - composer.json | 2 +- config/container.php | 4 +- config/params/.gitignore | 1 + config/params/shlink_dev_env.php.dist | 76 +++++++++++++++++++++++++++ data/infra/roadrunner.Dockerfile | 6 +-- docker-compose.yml | 3 -- shlink-dev.env.dist | 67 ----------------------- 9 files changed, 84 insertions(+), 78 deletions(-) create mode 100644 config/params/shlink_dev_env.php.dist delete mode 100644 shlink-dev.env.dist diff --git a/.dockerignore b/.dockerignore index db2d21f0..893aa659 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ bin/rr config/autoload/*local* +config/params/*.dist data/infra data/cache/* data/log/* @@ -23,4 +24,3 @@ php*xml* build* **/.* !config/roadrunner/.rr.yml -*.env* diff --git a/.gitignore b/.gitignore index 96ac6719..04c8ed56 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,3 @@ docs/mercure.html docker-compose.override.yml .phpunit.result.cache docs/swagger/swagger-inlined.json -shlink-dev.env diff --git a/composer.json b/composer.json index 4c66c67f..50633ca1 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "shlinkio/shlink-event-dispatcher": "^4.1", "shlinkio/shlink-importer": "^5.3.2", "shlinkio/shlink-installer": "^9.2", - "shlinkio/shlink-ip-geolocation": "dev-main#0619112 as 4.1", + "shlinkio/shlink-ip-geolocation": "dev-main#6f35bd4 as 4.1", "shlinkio/shlink-json": "^1.1", "spiral/roadrunner": "^2024.1", "spiral/roadrunner-cli": "^2.6", diff --git a/config/container.php b/config/container.php index 3a1e3355..e207fe16 100644 --- a/config/container.php +++ b/config/container.php @@ -15,8 +15,8 @@ chdir(dirname(__DIR__)); require 'vendor/autoload.php'; -// Promote env vars from installer config -loadEnvVarsFromConfig('config/params/generated_config.php', enumValues(EnvVars::class)); +// Promote env vars from installer or dev config +loadEnvVarsFromConfig('config/params/*.php', enumValues(EnvVars::class)); // This is one of the first files loaded. Configure the timezone and memory limit here ini_set('memory_limit', EnvVars::MEMORY_LIMIT->loadFromEnv()); diff --git a/config/params/.gitignore b/config/params/.gitignore index d6b7ef32..36565258 100644 --- a/config/params/.gitignore +++ b/config/params/.gitignore @@ -1,2 +1,3 @@ * !.gitignore +!*.dist diff --git a/config/params/shlink_dev_env.php.dist b/config/params/shlink_dev_env.php.dist new file mode 100644 index 00000000..2a3905dc --- /dev/null +++ b/config/params/shlink_dev_env.php.dist @@ -0,0 +1,76 @@ +value => 'dev', +// EnvVars::GEOLITE_LICENSE_KEY->value => '', + + // URL shortener + EnvVars::DEFAULT_DOMAIN->value => 'localhost:8800', + EnvVars::IS_HTTPS_ENABLED->value => false, + + // Database - MySQL + EnvVars::DB_DRIVER->value => 'mysql', + EnvVars::DB_USER->value => 'root', + EnvVars::DB_PASSWORD->value => 'root', + EnvVars::DB_NAME->value => 'shlink', +// EnvVars::DB_NAME->value => 'shlink_foo', + EnvVars::DB_HOST->value => 'shlink_db_mysql', + + // Database - Maria +// EnvVars::DB_DRIVER->value => 'maria', +// EnvVars::DB_USER->value => 'root', +// EnvVars::DB_PASSWORD->value => 'root', +// EnvVars::DB_NAME->value => 'shlink_foo', +// EnvVars::DB_HOST->value => 'shlink_db_maria', + + // Database - Postgres +// EnvVars::DB_DRIVER->value => 'postgres', +// EnvVars::DB_USER->value => 'postgres', +// EnvVars::DB_PASSWORD->value => 'root', +// EnvVars::DB_NAME->value => 'shlink_foo', +// EnvVars::DB_HOST->value => 'shlink_db_postgres', + + // Database - MSSQL +// EnvVars::DB_DRIVER->value => 'mssql', +// EnvVars::DB_USER->value => 'sa', +// EnvVars::DB_PASSWORD->value => 'Passw0rd!', +// EnvVars::DB_NAME->value => 'shlink_foo', +// EnvVars::DB_HOST->value => 'shlink_db_ms', + + // Matomo + // Dev matomo instance needs to be manually configured once before enabling the configuration below: + // 1. Go to http://localhost:8003 and follow the installation instructions. + // 2. Open data/infra/matomo/config/config.ini.php and replace `trusted_hosts[] = "localhost"` with + // `trusted_hosts[] = "localhost:8003"` (see https://github.com/matomo-org/matomo/issues/9549) + // 3. Go to http://localhost:8003/index.php?module=SitesManager&action=index and paste the ID for the site you just + // created into the `MATOMO_SITE_ID` var below. + // 4. Go to http://localhost:8003/index.php?module=UsersManager&action=userSecurity, scroll down, click + // "Create new token" and once generated, paste the token into the `MATOMO_API_TOKEN` var below. + // 5. Copy the config below and paste it in a new shlink-dev.local.env file. + EnvVars::MATOMO_ENABLED->value => false, + EnvVars::MATOMO_BASE_URL->value => 'http://shlink_matomo', +// EnvVars::MATOMO_SITE_ID->value => , +// EnvVars::MATOMO_API_TOKEN->value => , + + // Mercure + EnvVars::MERCURE_PUBLIC_HUB_URL->value => 'http://localhost:8002', + EnvVars::MERCURE_INTERNAL_HUB_URL->value => 'http://shlink_mercure_proxy', + EnvVars::MERCURE_JWT_SECRET->value => 'mercure_jwt_key_long_enough_to_avoid_error', + + // RabbitMQ + EnvVars::RABBITMQ_ENABLED->value => true, + EnvVars::RABBITMQ_HOST->value => 'shlink_rabbitmq', + EnvVars::RABBITMQ_PORT->value => 5672, + EnvVars::RABBITMQ_USER->value => 'rabbit', + EnvVars::RABBITMQ_PASSWORD->value => 'rabbit', + + // Redis + EnvVars::REDIS_PUB_SUB_ENABLED->value => true, + EnvVars::REDIS_SERVERS->value => 'tcp://shlink_redis:6379', + +]; diff --git a/data/infra/roadrunner.Dockerfile b/data/infra/roadrunner.Dockerfile index 28d2d343..0bf251f6 100644 --- a/data/infra/roadrunner.Dockerfile +++ b/data/infra/roadrunner.Dockerfile @@ -73,7 +73,7 @@ CMD \ if [[ ! -d "./vendor" ]]; then /usr/local/bin/composer install ; fi && \ # Download roadrunner binary if [[ ! -f "./bin/rr" ]]; then ./vendor/bin/rr get --no-interaction --no-config --location bin/ && chmod +x bin/rr ; fi && \ - # Create .env file if it does not exist yet - if [[ ! -f "./shlink-dev.env" ]]; then cp ./shlink-dev.env.dist ./shlink-dev.env ; fi && \ + # Create env file if it does not exist yet + if [[ ! -f "./config/params/shlink_dev_env.php" ]]; then cp ./config/params/shlink_dev_env.php.dist ./config/params/shlink_dev_env.php ; fi && \ # Run with `exec` so that signals are properly handled - exec ./bin/rr serve --dotenv /home/shlink/shlink-dev.env -c config/roadrunner/.rr.dev.yml + exec ./bin/rr serve -c config/roadrunner/.rr.dev.yml diff --git a/docker-compose.yml b/docker-compose.yml index 05132dfb..e5a34e80 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,9 +34,6 @@ services: - shlink_matomo environment: DEFAULT_DOMAIN: localhost:8000 - env_file: - - path: shlink-dev.env - required: false extra_hosts: - 'host.docker.internal:host-gateway' diff --git a/shlink-dev.env.dist b/shlink-dev.env.dist deleted file mode 100644 index ee6173f2..00000000 --- a/shlink-dev.env.dist +++ /dev/null @@ -1,67 +0,0 @@ -LC_ALL=C -APP_ENV=dev -#GEOLITE_LICENSE_KEY= - -# URL shortener -DEFAULT_DOMAIN=localhost:8800 -IS_HTTPS_ENABLED=false - -# Database - MySQL -DB_DRIVER=mysql -DB_USER=root -DB_PASSWORD=root -DB_NAME=shlink -#DB_NAME=shlink_foo -DB_HOST=shlink_db_mysql - -# Database - Maria -#DB_DRIVER=maria -#DB_USER=root -#DB_PASSWORD=root -#DB_NAME=shlink_foo -#DB_HOST=shlink_db_maria - -# Database - Postgres -#DB_DRIVER=postgres -#DB_USER=postgres -#DB_PASSWORD=root -#DB_NAME=shlink_foo -#DB_HOST=shlink_db_postgres - -# Database - MSSQL -#DB_DRIVER=mssql -#DB_USER=sa -#DB_PASSWORD=Passw0rd! -#DB_NAME=shlink_foo -#DB_HOST=shlink_db_ms - -# Matomo -# Dev matomo instance needs to be manually configured once before enabling the configuration below: -# 1. Go to http://localhost:8003 and follow the installation instructions. -# 2. Open data/infra/matomo/config/config.ini.php and replace `trusted_hosts[] = "localhost"` with -# `trusted_hosts[] = "localhost:8003"` (see https://github.com/matomo-org/matomo/issues/9549) -# 3. Go to http://localhost:8003/index.php?module=SitesManager&action=index and paste the ID for the site you just -# created into the `MATOMO_SITE_ID` var below. -# 4. Go to http://localhost:8003/index.php?module=UsersManager&action=userSecurity, scroll down, click -# "Create new token" and once generated, paste the token into the `MATOMO_API_TOKEN` var below. -# 5. Copy the config below and paste it in a new shlink-dev.local.env file. -MATOMO_ENABLED=false -MATOMO_BASE_URL=http://shlink_matomo -#MATOMO_SITE_ID= -#MATOMO_API_TOKEN= - -# Mercure -MERCURE_PUBLIC_HUB_URL=http://localhost:8002 -MERCURE_INTERNAL_HUB_URL=http://shlink_mercure_proxy -MERCURE_JWT_SECRET=mercure_jwt_key_long_enough_to_avoid_error - -# RabbitMQ -RABBITMQ_ENABLED=true -RABBITMQ_HOST=shlink_rabbitmq -RABBITMQ_PORT=5672 -RABBITMQ_USER=rabbit -RABBITMQ_PASSWORD=rabbit - -# Redis -REDIS_PUB_SUB_ENABLED=true -REDIS_SERVERS=tcp://shlink_redis:6379