Closed rfay closed 2 years ago
@lolautruche I haven't figured out where to get environment variables from. I see the list you provided in https://docs.platform.sh/development/variables/use-variables.html#use-platformsh-provided-variables but the only way I've been able to access those is platform ssh
and env | grep PLATFORM_
- I thought they would be available via a platform command but I haven't found one.
About $PLATFORM_*
variables, they're purely informational and are useful in build/deploy hooks, may be used in .environment
or in apps. They're here to describe the current environment.
We don't want to mirror them from Platform, but populate them according to the DDEV environment. For now we can overlook the ones that are base64 encoded, except $PLATFORM_RELATIONSHIPS
that would need to be populated for services (ref #9 )
Thanks @lolautruche - The question is how to get the PLATFORM_ variables... do you have to platform ssh
? That seems hard, I'd expect one of the platform commands to provide them.
We don't have to get them, we need to create them consistently in the local containers, according to the DDEV environment. In other words, we emulate their presence, with local values.
So get them from a secondary sources... that seems awkward. And don't we need to use those values? What's the recommended secondary source? The .platform.app or whatever?
$PLATFORM_
env vars describe the current environment. In our case, the environment will be a DDEV container. Some variables are sourced from .platform.app.yaml
(e.g., $PLATFORM_APPLICATION_NAME
, or $PLATFORM_APPLICATION
which is a base64 JSON blob), but others depend on the environment (e.g. $PLATFORM_BRANCH
which is the actual git branch, or $PLATFORM_DOCUMENT_ROOT
which gives the absolute path for the document root.
Here are a few examples that I would expect to get from the DDEV container: | Var name | Value |
---|---|---|
$PLATFORM_BRANCH |
The current Git branch | |
$PLATFORM_DOCUMENT_ROOT |
/var/www/html/web or /app/web (depends on the configured web root) |
|
$PLATFORM_PROJECT |
Current Platform.sh project ID | |
$PLATFORM_SMTP_HOST |
Mailhog SMTP host |
Regarding $PLATFORM_RELATIONSHIPS
, it is a JSON blob base64 encoded which describes how to access to a related service (e.g., the database).
Example:
$ echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq
{
"database": [
{
"username": "user",
"scheme": "mysql",
"service": "db",
"fragment": null,
"ip": "169.254.255.8",
"hostname": "4rrtb6sgmu5heslnidt5lfpvmi.db.service._.eu-3.platformsh.site",
"public": false,
"cluster": "6j4ypl5iendqc-workshop-5ziq2gq",
"host": "database.internal",
"rel": "mysql",
"query": {
"is_master": true
},
"path": "main",
"password": "",
"type": "mariadb:10.4",
"port": 3306,
"host_mapped": false
}
]
}
hostname
, port
, path
(DB name), username
, password
, etc... should get the corresponding for the DDEV database, e.g.:
{
"database": [
{
"username": "db",
"scheme": "mysql",
"service": "db",
"fragment": null,
"ip": "172.20.0.4",
"hostname": "ddev-myapp-db",
"public": false,
"cluster": "",
"host": "ddev-myapp-db",
"rel": "mysql",
"query": {
"is_master": true
},
"path": "db",
"password": "db",
"type": "mariadb:10.4",
"port": 3306,
"host_mapped": false
}
]
}
I'm going to go ahead and pull this one, and people can start to give it a little bit of attention, then we can prioritize next steps.
Related issues:
To try this out, you can
ddev get https://github.com/rfay/ddev-platformsh/tarball/20220601_initial_experiments