ddev / ddev-platformsh

Add integration with Platform.sh hosting service
Apache License 2.0
10 stars 11 forks source link

Improve actual support for PLATFORM_ROUTES #47

Closed gilzow closed 1 year ago

gilzow commented 2 years ago

List of php-based templates that in some way use/depend on PLATFORM_ROUTES

rfay commented 2 years ago

Thanks so much!

lolautruche commented 2 years ago

Here is the documentation page about routes: https://docs.platform.sh/define-routes.html However, it doesn't explain the properties in the JSON object (most notably the original_url property).

gilzow commented 1 year ago

just ran into an issue trying to use nextcloud which uses PLATFORM_ROUTES in its config.

Currently in ddev, $platform_sh_url is set to ${DDEV_PRIMARY_URL} which means the explode at line 6 produces only one key, so the attempt to grab key 1 results in passing null to rtrim, and then everything just falls apart after that.

rfay commented 1 year ago

@gilzow if from a template, can you link to the template please? (Oh, I see from link that it is from template)

lolautruche commented 1 year ago

It's this one: https://github.com/platformsh-templates/nextcloud

Use of $PLATFORM_ROUTES is here.

gilzow commented 1 year ago

BTW, we're in the process of updating this template, hence why I'm working with it in DDEV.

For now I'm rebuilding the PLATFORM_ROUTES info with the DDEV reported URL hardcoded in .ddev/config.platformsh.yaml but we can't really ask developers to do that.

DDEV has calculated and stored the generated URL in .ddev/.ddev-docker-compose-full.yaml. Is it possible to have the actual URL used when creating PLATFORM_ROUTES vs using the ${DDEV_PRIMARY_URL} variable?

rfay commented 1 year ago

Yes, it should use the actual URL. The question will be when there are many URLs of course.

lolautruche commented 1 year ago

@gilzow Can you please share what you're expecting to get (and that you set in .ddev/config.platformsh.yaml), vs what you're getting?

Thanks

gilzow commented 1 year ago

what i'm getting is

{
  "${DDEV_PRIMARY_URL}": {
    "primary": true,
    "id": null,
    "production_url": "${DDEV_PRIMARY_URL}",
    "attributes": {},
    "upstream": "drupal",
    "type": "upstream",
    "original_url": "https://{default}/"
  }
}

What I'm expecting is:

{
  "https://nexcloud-upgrade-test.ddev.site/": {
    "primary": true,
    "id": null,
    "production_url": "https://nexcloud-upgrade-test.ddev.site/",
    "attributes": {},
    "upstream": "drupal",
    "type": "upstream",
    "original_url": "https://{default}/"
  }
}

!!! IMPORTANT SIDE NOTE !!!

please notice the inclusion of the trailing end slash (/) in both the route key and the production_url property. According to our docs, all generated routes now have a trailing slash. I mention this because the current value of ${DDEV_PRIMARY_URL} does not contain the trailing slash.

What i set in .ddev/config.platformsh.yaml is the base64 encoded version of the above:

"- PLATFORM_ROUTES=eyJodHRwczovL25leGNsb3VkLXVwZ3JhZGUtdGVzdC5kZGV2LnNpdGUvIjp7InByaW1hcnkiOnRydWUsImlkIjpudWxsLCJwcm9kdWN0aW9uX3VybCI6Imh0dHBzOi8vbmV4Y2xvdWQtdXBncmFkZS10ZXN0LmRkZXYuc2l0ZS8iLCJhdHRyaWJ1dGVzIjp7fSwidXBzdHJlYW0iOiJkcnVwYWwiLCJ0eXBlIjoidXBzdHJlYW0iLCJvcmlnaW5hbF91cmwiOiJodHRwczovL3tkZWZhdWx0fS8ifX0K"
rfay commented 1 year ago

The trailing slash probably won't make a difference here, but we'll add it anyway!

lolautruche commented 1 year ago

@rfay Do you know why ${DDEV_PRIMARY_URL} is not resolved?

rfay commented 1 year ago

Interesting, not sure the context it's being evaluated in. Looks like it's not even being processed by bash, because if it were even being evaluated, it would then be empty.

lolautruche commented 1 year ago

Could it be because of the HEREDOC?

  platform_routes=$(cat <<-"ENDROUTES"
  {
  "${DDEV_PRIMARY_URL}": {
    "primary": true,
    "id": null,
    "production_url": "${DDEV_PRIMARY_URL}",
    "attributes": {},
    "upstream": "drupal",
    "type": "upstream",
    "original_url": "https://{default}/"  }
  }
  ENDROUTES
  )
rfay commented 1 year ago

Yes, it could. There's a right way and wrong way to do that. I think if you use "ENDROUTES" it doesn't evaluate and if you use ENDROUTES it does.

lolautruche commented 1 year ago

Yes, that's it: https://stackoverflow.com/questions/4937792/using-variables-inside-a-bash-heredoc

gilzow commented 1 year ago

Interesting, not sure the context it's being evaluated in.

as for where this is being evaluated, from inside PHP after accessing $_ENV['PLATFORM_ROUTES'] and base64 decoding & json decoding.

gilzow commented 1 year ago

The trailing slash probably won't make a difference here, but we'll add it anyway!

oh, yeah it won't make a difference in this scenario, but when I was manually changing the value I noticed it and wanted to make sure I mention it since it will make a difference in other situations.

rfay commented 1 year ago
gilzow commented 1 year ago

@lolautruche

However, it doesn't explain the properties in the JSON object (most notably the original_url property).

original_url property is the route key defined in routes.yaml. (e.g. https://{default}/).

rfay commented 1 year ago

@gilzow is that OK or not?

rfay commented 1 year ago

I imagine in the future we'll want much more significant versions of PLATFORM_ROUTES? (drupal9-multisite template)

$ echo $PLATFORM_ROUTES | base64 -d | jq
{
  "https://first.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "primary": false,
    "id": null,
    "production_url": "https://first.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "attributes": {},
    "type": "upstream",
    "upstream": "drupal",
    "original_url": "https://first.{default}/"
  },
  "https://second.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "primary": false,
    "id": null,
    "production_url": "https://second.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "attributes": {},
    "type": "upstream",
    "upstream": "drupal",
    "original_url": "https://second.{default}/"
  },
  "https://main.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "primary": true,
    "id": null,
    "production_url": "https://main.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "attributes": {},
    "type": "upstream",
    "upstream": "drupal",
    "original_url": "https://main.{default}/"
  },
  "https://main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "primary": false,
    "id": null,
    "production_url": "https://main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "attributes": {},
    "type": "redirect",
    "to": "https://main.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "original_url": "https://{default}/"
  },
  "http://first.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "original_url": "http://first.{default}/",
    "id": null,
    "primary": false,
    "type": "redirect",
    "to": "https://first.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "production_url": "http://first.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/"
  },
  "http://second.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "original_url": "http://second.{default}/",
    "id": null,
    "primary": false,
    "type": "redirect",
    "to": "https://second.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "production_url": "http://second.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/"
  },
  "http://main.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "original_url": "http://main.{default}/",
    "id": null,
    "primary": false,
    "type": "redirect",
    "to": "https://main.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "production_url": "http://main.main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/"
  },
  "http://main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/": {
    "original_url": "http://{default}/",
    "id": null,
    "primary": false,
    "type": "redirect",
    "to": "https://main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/",
    "production_url": "http://main-bvxea6i-ljeh5qxqywco6.ca-1.platformsh.site/"
  }
}

I'm certainly not understanding why there are 8 entries here for a 3-site multisite.

gilzow commented 1 year ago

I imagine in the future we'll want much more significant versions of PLATFORM_ROUTES?

Yes, please. :D

I'm certainly not understanding why there are 8 entries here for a 3-site multisite.

There are four entries in the routes.yaml from your example, 3 upstreams, and 1 redirect.


"https://first.{default}/":
    type: upstream
    upstream: "drupal:http"
 <snip>

"https://second.{default}/":
    type: upstream
    upstream: "drupal:http"
<snip>

"https://main.{default}/":
    type: upstream
    upstream: "drupal:http"
    primary: true
<snip>

"https://{default}/":
    type: redirect
    to: "https://main.{default}/"

Each of those are going to get both an http and https variant, hence the 8 entries in PLATFORM_ROUTES.