-
Notifications
You must be signed in to change notification settings - Fork 0
IBX-10764: Extracted Upsun environmental variables #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
effd671 to
fa2b4cb
Compare
konradoboza
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have at least logging when configuration contains errors? I assume exceptions on build/deploy will be rather annoying.
I'm also missing some unhappy path testing a bit, but this is related to the remark above.
| foreach ($groupedRelationships['redis'] as $endpoints) { | ||
| foreach ($endpoints as $endpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why nested foreach if we return an array in the first iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow you here, nested foreach is here to return first endpoint under a given relationship's scheme, in this case redis. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks weird at first glance that you iterate in two loops just to return the first element. If we cannot do it differently ($array[0]) then fine.
| /** | ||
| * @param array<string, mixed> $route | ||
| */ | ||
| private function isVarnishRoute(array $route): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Fastly handled at all here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Http cache is handled by exactly the same way as in the current core solution: https://github.com/ibexa/core/pull/672/files#diff-0bc93691994620e932aa9941baa089094640bca3da1275b5073f74d5e9b71d16L952
@konradoboza I'm not quite sure I understand. What kind of logging or maybe at which point in time do you wish to see such logging to be done? If configuration contains errors then build hook will crash which is completely expected. The loader presented in this PR doesn't inject itself into build hook, it's active during runtime. |
|
Ok, just wanted to suggest some way to report misconfigurations. If the build hook fails with proper info, I am fine with that. |
I'm not aware of any way to report broken configuration, if the configuration is broken the build will simply fail on Upsun side and they provide us with build logs :) |
|
@barw4 please add permissions for |
Related PRs:
ibexa/core#672
ibexa/recipes-dev#222
Description:
Overview
UpsunEnvVarLoaderparses Upsun environment variables (PLATFORM_RELATIONSHIPS,PLATFORM_ROUTES) and exposes them as env vars for Ibexa application.Env Vars Generation
1. Database (MySQL/PostgreSQL)
Logic: Iterates over
mysql*andpgsql*schemes (usesstr_starts_withfor HA support likemysql-replica)Generated variables:
{RELATIONSHIP_NAME}_URL- full URL with charset and serverVersion{RELATIONSHIP_NAME}_USER{RELATIONSHIP_NAME}_USERNAME{RELATIONSHIP_NAME}_PASSWORD{RELATIONSHIP_NAME}_HOST{RELATIONSHIP_NAME}_PORT{RELATIONSHIP_NAME}_NAME{RELATIONSHIP_NAME}_DATABASE{RELATIONSHIP_NAME}_DRIVER{RELATIONSHIP_NAME}_SERVERExample: Relationship
database→DATABASE_URL,DATABASE_HOST, etc.2. DFS Database
Logic:
dfs_databaserelationship gets the SAME treatment as any other database viabuildDatabaseEnvVars(full URL with charset, serverVersion, etc.)PLATFORMSH_DFS_NFS_PATHis set,buildDfsEnvVarsadds DFS-specific variablesCondition for DFS-specific vars: Only when
$_SERVER['PLATFORMSH_DFS_NFS_PATH']is setStandard database variables (from
buildDatabaseEnvVars):DFS_DATABASE_URL- full URL with charset and serverVersionDFS_DATABASE_HOSTDFS_DATABASE_PORTDFS_DATABASE_USERDFS_DATABASE_USERNAMEDFS_DATABASE_PASSWORDDFS_DATABASE_NAMEDFS_DATABASE_DATABASEDFS_DATABASE_DRIVERDFS_DATABASE_SERVERDFS-specific variables (from
buildDfsEnvVars, only when NFS path is set):DFS_NFS_PATHDFS_DATABASE_CHARSETDFS_DATABASE_COLLATIONDFS_DATABASE_DRIVER(PDO driver format, e.g.,pdo_mysql)3. Cache (Redis/Memcached)
Priority: Redis ALWAYS before Memcached (regardless of array order)
Logic:
CACHE_POOL)Generated variables per endpoint:
{RELATIONSHIP_NAME}_URL(Redis only){RELATIONSHIP_NAME}_HOST{RELATIONSHIP_NAME}_PORT{RELATIONSHIP_NAME}_SCHEME(Redis only)Global variables (first found):
CACHE_POOL-cache.redisorcache.memcachedCACHE_DSN4. Session (Redis)
Priority:
redissession(dedicated Redis for sessions)rediscache,myredis, etc.)Generated variables:
SESSION_HANDLER_ID-NativeSessionHandlerclassSESSION_SAVE_PATH-host:port5. Search (Solr/Elasticsearch)
Solr logic: Checks
$endpoint['scheme'] === 'solr'Elasticsearch logic: Checks
$endpoint['rel'] === 'elasticsearch'(NOT scheme, because ES useshttp/https)Solr generated variables:
SEARCH_ENGINE=solrSOLR_DSNSOLR_CORE{RELATIONSHIP_NAME}_HOST{RELATIONSHIP_NAME}_PORT{RELATIONSHIP_NAME}_NAME{RELATIONSHIP_NAME}_DATABASEElasticsearch generated variables:
SEARCH_ENGINE=elasticsearchELASTICSEARCH_DSN{RELATIONSHIP_NAME}_URL{RELATIONSHIP_NAME}_HOST{RELATIONSHIP_NAME}_PORT{RELATIONSHIP_NAME}_SCHEME6. Varnish (HTTP Cache)
Logic: Looks for route with
type: upstreamandupstream: varnish, prefersprimary: trueGenerated variables:
HTTPCACHE_PURGE_TYPE=varnishHTTPCACHE_PURGE_SERVERHTTPCACHE_VARNISH_INVALIDATE_TOKENSummary: When we use relationship name vs scheme
mysql*,pgsql*)str_starts_withfor HAdfs_database)redis,memcached)redissession) + scheme fallbacksolr)relfield (elasticsearch)type: upstream,upstream: varnishRelationship naming conventions
Recommended names (but not required, except for special cases):
database- main databasedfs_database- DFS database (this name is required)rediscache- Redis for cacheredissession- Redis for sessions (this name is preferred for dedicated instance)elasticsearch- Elasticsearchsolr- SolrDevelopers can use any relationship names - env vars will be generated with a prefix matching the relationship name (uppercase,
-→_).For QA:
Documentation: