Skip to content

Commit

Permalink
Load dev env as a PHP array instead of an env file
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 24, 2024
1 parent f4da9c1 commit 45e108d
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bin/rr
config/autoload/*local*
config/params/*.dist
data/infra
data/cache/*
data/log/*
Expand All @@ -23,4 +24,3 @@ php*xml*
build*
**/.*
!config/roadrunner/.rr.yml
*.env*
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ docs/mercure.html
docker-compose.override.yml
.phpunit.result.cache
docs/swagger/swagger-inlined.json
shlink-dev.env
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

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());
Expand Down
1 change: 1 addition & 0 deletions config/params/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*
!.gitignore
!*.dist
76 changes: 76 additions & 0 deletions config/params/shlink_dev_env.php.dist
Original file line number Diff line number Diff line change
@@ -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',

];
6 changes: 3 additions & 3 deletions data/infra/roadrunner.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
67 changes: 0 additions & 67 deletions shlink-dev.env.dist

This file was deleted.

0 comments on commit 45e108d

Please sign in to comment.