Load dev env as a PHP array instead of an env file

This commit is contained in:
Alejandro Celaya 2024-10-24 09:59:13 +02:00
parent f4da9c1fcc
commit 45e108d21e
9 changed files with 84 additions and 78 deletions

View File

@ -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*

1
.gitignore vendored
View File

@ -15,4 +15,3 @@ docs/mercure.html
docker-compose.override.yml
.phpunit.result.cache
docs/swagger/swagger-inlined.json
shlink-dev.env

View File

@ -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",

View File

@ -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());

View File

@ -1,2 +1,3 @@
*
!.gitignore
!*.dist

View File

@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
use Shlinkio\Shlink\Core\Config\EnvVars;
return [
EnvVars::APP_ENV->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',
];

View File

@ -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

View File

@ -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'

View File

@ -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