V8-archive: Error parsing environment variables

Created on 3 Oct 2019  路  9Comments  路  Source: directus/v8-archive

Bug Report

Steps to Reproduce

  1. Run the API providing these additional 2 environment variables:
    KUBERNETES_PORT_443_TCP="doesnt matter"
    KUBERNETES_PORT="doesnt matter"
  2. Run the API
  3. Make a request to API
  4. See error

Expected Behavior

API Call return : {"error":{"code":3,"message":"Unauthorized request"}}
Command run without errors

Actual Behavior

API call returns error:

<b>Fatal error</b>:  Uncaught Error: Only variables can be passed by reference in /var/www/src/core/Directus/Config/Context.php:39
Stack trace:
#0 /var/www/src/core/Directus/Config/Context.php(39): Directus\Config\Context::expand('tcp://raft-test...', Array, 'tcp://raft-test...')
#1 /var/www/src/core/Directus/Config/Context.php(39): Directus\Config\Context::expand(Array, Array, 'tcp://raft-test...')
#2 /var/www/src/core/Directus/Config/Context.php(71): Directus\Config\Context::expand(Array, Array, 'tcp://raft-test...')
#3 /var/www/src/core/Directus/Config/Context.php(85): Directus\Config\Context::from_map(Array)
#4 /var/www/src/web.php(30): Directus\Config\Context::from_env()
#5 /var/www/public/index.php(3): require('/var/www/src/we...')
#6 {main}
  thrown in <b>/var/www/src/core/Directus/Config/Context.php</b> on line <b>39</b><br />

Other Context & Screenshots

Looks like this happens due to nested nature of exploded environment variables.
Adding below lines to Context::expand method just before return statement fixes the issue.

    if (!is_array($target[$segment])) {
        $target[$segment] = [];
    }

Technical Details

bug docker

Most helpful comment

For anyone waiting on the next release, I've created an easy temporary fix by forking the master branch and applying this change. You can use the directus/docker builder script _(https://github.com/directus/docker)_ to build a dist image and pass the fork in with the --repository and --ref flags. Just watch out that the image tag will be named differently

Repo:
https://github.com/zfalen/api

Example: _(note I am passing in a custom version of the API base image which you do NOT have to do)_
/bin/build --type dist --project api --kind apache --base-image custom-directus-api-base:latest --repository zfalen/api --ref master && docker tag zfalen/api:v2.6.1-apache axseattle/custom-directus-api:latest && echo "done

All 9 comments

I encountered this same issue while deploying on kubernetes. Can confirm that it gets solved putting that line.

Hi, so what is what is container version that fix that issue ?

Regards.

Hey @Radionz - The next release will contain this fix.

Hey @bjgajjar
I also have this case while installing directus/api:v2.6.0-apache from Docker Hub on Kubernetes.
When do you expect the next release to be issued?

Hey again @bjgajjar,
This issue occurs also in directus/api:v2.5.0-apache.
Is there a known workaround until the next container is published?

For now I ssh into the pod, install vi and put the fix by hand. You can also create your own docker image with the fix.
But looking at the time between releases I also really hope for it to be released soon. (And release more often :P)

we are mounting the corrected file from a ConfigMap. so isnt broken when the pod is restarted and no need to create a new Docker image ;)

For anyone waiting on the next release, I've created an easy temporary fix by forking the master branch and applying this change. You can use the directus/docker builder script _(https://github.com/directus/docker)_ to build a dist image and pass the fork in with the --repository and --ref flags. Just watch out that the image tag will be named differently

Repo:
https://github.com/zfalen/api

Example: _(note I am passing in a custom version of the API base image which you do NOT have to do)_
/bin/build --type dist --project api --kind apache --base-image custom-directus-api-base:latest --repository zfalen/api --ref master && docker tag zfalen/api:v2.6.1-apache axseattle/custom-directus-api:latest && echo "done

Was this page helpful?
0 / 5 - 0 ratings